Update 2021-07-21

It's been more than half a decade since I first wrote this answer. The extensions to which I originally linked are abandoned, and Visual Studio Code's intrinsic PHP support hasn't improved, which is disappointing. The only decent extension still standing of which I'm aware is PHP Intelephense, which uses a freemium model: basic features are free, and a lifetime license is $12 USD as of writing.

The free version of Intelephense supports code formatting with the usual shortcuts (Alt + Shift + F on Windows and Linux, ⌥⇧F on macOS). Visual Studio Code continues to lack built-in support for PHP code formatting and will direct you to the extension marketplace if you attempt to format PHP without an appropriate extension installed.

Original answer

Visual Studio Code has pretty awesome PHP support. What it lacks is covered by extensions. A quick search reveals at least three (1, 2, and 3) that claim to support PHP formatting.

They mostly seem to use the standard shortcut of Alt + Shift + F on Windows/Linux, with varying shortcuts on Mac. If you're on Mac, give ⌥⇧F a try.

Answer from Zenexer on Stack Overflow
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Format HTML in PHP - Visual Studio Marketplace
Extension for Visual Studio Code - Provides formatting for the HTML code in PHP files using JSbeautify - Works well paired with a PHP formatting extension
Top answer
1 of 14
106

Update 2021-07-21

It's been more than half a decade since I first wrote this answer. The extensions to which I originally linked are abandoned, and Visual Studio Code's intrinsic PHP support hasn't improved, which is disappointing. The only decent extension still standing of which I'm aware is PHP Intelephense, which uses a freemium model: basic features are free, and a lifetime license is $12 USD as of writing.

The free version of Intelephense supports code formatting with the usual shortcuts (Alt + Shift + F on Windows and Linux, ⌥⇧F on macOS). Visual Studio Code continues to lack built-in support for PHP code formatting and will direct you to the extension marketplace if you attempt to format PHP without an appropriate extension installed.

Original answer

Visual Studio Code has pretty awesome PHP support. What it lacks is covered by extensions. A quick search reveals at least three (1, 2, and 3) that claim to support PHP formatting.

They mostly seem to use the standard shortcut of Alt + Shift + F on Windows/Linux, with varying shortcuts on Mac. If you're on Mac, give ⌥⇧F a try.

2 of 14
53

I installed

  • Prettier for HTML, CSS, and JavaScript files

  • PHP Intelephense for PHP files

I followed the instructions for each plugin but found I had to additionally edit settings.json manually in order to get them to work together.

"editor.defaultFormatter": "esbenp.prettier-vscode",
"[php]": {
  "editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
}

The settings use Intelephense as the formatter for PHP files and use Prettier as the formatter for all other files.

Now I use Shift + Alt + F to format the files like everybody else.

Discussions

laravel - How can I format PHP files with HTML markup in Visual Studio Code? - Stack Overflow
This will format .blade.php files as HTML, but it will not remove Blade snippets. ... Using a newish feature in php, vscode seems to format and highlight embedded HTML beautifully. (php 7.3, released after the question was posted) adds what are called "heredoc" and "neardoc" strings. More on stackoverflow.com
🌐 stackoverflow.com
VS Code extension for formatting a PHP file with HTML?
I haven't done PHP in over a decade (when Atom was still relevant), but searching for `category:formatters php` in the extensions tab will show you only extensions with a PHP formatting function. Some of them report supporting formatting HTML with PHP. More on reddit.com
🌐 r/vscode
9
5
September 6, 2025
Formatting html inside php
Curious if I can format HTML inside a PHP file somehow? Right now It only formats purely PHP. More on github.com
🌐 github.com
6
October 9, 2017
visual studio code - Automatically formatting HTML within PHP with VSCode? - Stack Overflow
Luckily I felt the same way as ... with a VScode extension that doesn't register itself as a "formatting" extension I format the HTML onBeforeSave so you can still register a PHP formatting extension so between the two it gets the whole file. I use js-beautify so you can just use all the native HTML formatting settings in VSCode ... More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 10
64

The extension Beautify (from HookyQR) just does it very well. Either add PHP, and any other file extension type, to the configuration. As said by Nico, here is an example:

  1. Go to user settings (Ctrl + Shift + PUser settings (UI) or Ctrl + , (comma)

  2. Search for Beautify in the field above. And click on "Edit in settings.json" for "Beautify: Config".

  3. For the "html" section, add "php" and "blade".

###Usage

You can invoke it directly. Press F1, and then write Beautify. The auto completion gives you two choices, "Beautify file" and "Beautify selection". Choose the one you need, and it will do the job. That's a straightforward direct way.

You can also add a keybinding to have a keyboard shortcut. Here is how to do it:

  1. Open keybindings.json (go to menu FilePreferencesKeyboard Shortcuts)

  2. Click in the above. Open and edit file keybindings.json

  3. Add the following into the closed brackets, []

    {
           "key": "alt+b",
           "command": "HookyQR.beautify",
           "when": "editorFocus"
    }
    

    Choose any key you want, and make sure you don't override an existing one. Search first in the left side if it exists or not.

Note that all of those things are well documented in the description of the extension.

Extra: Note about blade

(suite to @Peter Mortensen clarification pinpoint)

blade or blade.php

If you are confused if it's blade or blade.php for the setting! I'll clear it up for you! It's blade! That's vscode keyword for the language!

How do you know ?

First if you open the list of languages as by the image bellow:

Write blade

You can see Laravel Blade (blade)! The language keyword is in the paratheses! blade!

Well but how to check!

Try with blade.php in the settings!

Try to beautify

You'll get an asking context menu for what language (html, css, js)!

So it doesn't works!

To really know ! Put back blade! And it will work and beautify directly!

How well it works with blade

The awesome answer to that! Is try it, and see for yourself!

But if you ask me! I'll say it does work as with html! It can be too handy! And you may need to fix some lines! Depending on your expectations and your style!

Here an illustration! I screwed the indentation in purpose

And here the beautification result:

2 of 10
10

Beautify (from HookyQR) does solve this problem!

Many people add "blade.php" and "php" to the HTML configuration. Beautify does not recognize and manually choose an HTML template. Instead, just adding "blade" to the HTML configuration fixes all issues.

🌐
GitHub
gist.github.com › superjojo140 › b498f9efdbce77dd3d3fbc7ece8f3536
PHP and HTML Formatting in VS Code · GitHub
PHP and HTML Formatting in VS Code · Raw · php_formatting_vscode.md · Install theese two extensions: https://marketplace.visualstudio.com/items?itemName=kokororin.vscode-phpfmt · https://marketplace.visualstudio.com/items?itemName=rifi2k.format-html-in-php ·
🌐
W3Docs
w3docs.com › php
Format code command for PHP/HTML in Visual Studio Code
Press Shift+Alt+F to open the "Format Document" window. Select "PHP" or "HTML" from the dropdown menu, depending on the type of code you are formatting.
🌐
GitHub
github.com › squizlabs › PHP_CodeSniffer › discussions › 3941
vs code formatting mixed php and html · squizlabs PHP_CodeSniffer · Discussion #3941
March 5, 2024 - Search for "format" in the search bar to filter formatting-related settings. Adjust the settings for PHP and HTML formatting to your preference. For example: "php.format.enable": true, "php.suggest.basic": false, "editor.formatOnSave": true, // Enable format on save "editor.defaultFormatter": "esbenp.prettier-vscode", // Use Prettier as the default formatter ·
Author   squizlabs
Find elsewhere
🌐
Reddit
reddit.com › r/vscode › vs code extension for formatting a php file with html?
r/vscode on Reddit: VS Code extension for formatting a PHP file with HTML?
September 6, 2025 -

I usually use PHP Intelephense to format code. but when I try to format code with html, the php code lines up with the beginning of the code block like the first image. this can result in a huge amount of indentation. It's hard to read and manage.

I tried another extension, Format HTML in PHP, it simply skips tabbing in PHP. see image 2.

I would like the code to look similar to image 3, adding a single indentation when going into or out of php code.

I realize that I can put the php start and end on it's on line, like image 4, but this NOT what I want to do. it affects the HTML and can affect the display of page by adding spacing.

are there any extensions that can accomplish this?

🌐
YouTube
youtube.com › tech on tech
Visual Studio Code - Format Html in PHP - YouTube
In this Video I will show Visual Studio Code - Format html in php.★★★ Thanks For Watching ★★★★★★ Please like share and subscribe ★★★Background Music - Music:...
Published   October 25, 2020
Views   27K
🌐
GitHub
github.com › RiFi2k › format-html-in-php
GitHub - RiFi2k/format-html-in-php: Basically this vscode extension uses all your standard configurations for html formatting, and your standard configurations for format on save, etc. It more or less works exactly how vscode should already work as it pertains to HTML in PHP files.
Add keybind Ctrl + Alt + F to format HTML in a PHP file. Update code for checking on PHP scoped formatOnSave setting to use native vscode method.
Starred by 35 users
Forked by 8 users
Languages   TypeScript 100.0% | TypeScript 100.0%
🌐
GitHub
github.com › vysker › vscode-php-formatter › issues › 23
Formatting html inside php · Issue #23 · vysker/vscode-php-formatter
October 9, 2017 - Curious if I can format HTML inside a PHP file somehow? Right now It only formats purely PHP.
Author   rgfx
🌐
Visual Studio Code
code.visualstudio.com › docs › languages › html
HTML in Visual Studio Code
November 3, 2021 - html.format.templating Open in VS Code Open in VS Code Insiders : Honor django, erb, handlebars and php templating language tags.
🌐
Devsense
docs.devsense.com › vscode › formatting
Code Formatting - PHP Tools for Visual Studio - Documentation
Use php.format.rules.* settings to configure the formatter to behave as you wish. For a detailed list of formatting options, either open the Settings Editor (Ctrl+,) and type php format in the Search bar or see our documentation page HERE. PHP Tools support HTML, JavaScript and CSS formatting in PHP files.
🌐
DEV Community
dev.to › ngobrolinit › prettier-for-php-file-formats-in-vscode-104o
Prettier for PHP File Formats in VSCode - DEV Community
March 18, 2024 - The solution is to use the settings.json configuration file in VSCode to set the PHP language using PHP Intelephense. Now go to settings and change Default Formatter to Prettier. Why Prettier? Prettier itself supports quite a lot of languages such as JavaScript, TypeScript, JSX, Angular, Vue, CSS, HTML, JSON, GraphQL, and others.
🌐
Devsense
community.devsense.com › d › 537-formatting-multiple-languages-php-javascript-html
Formatting Multiple Languages (PHP, Javascript, HTML) - PHP Tools Community Forum | DEVSENSE
May 14, 2018 - Welcome to our community forum. This is an open discussion forum where we try to help and guide you through using Devsense's PHP Tools software. We're here to help!
🌐
Visual Studio Code
code.visualstudio.com › docs › languages › php
PHP in Visual Studio Code
November 3, 2021 - Learn about Visual Studio Code editor features (syntax highlighting, snippets, linting) and extensions for PHP.