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
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

What is the most common PHP code formatter?
php-cs-fixer https://github.com/PHP-CS-Fixer/PHP-CS-Fixer I do disagree on code standards being enforced in the IDE. My view is they absolutely need to be enforced at the project level to ensure consistency of code standard throughout that project. The IDE should be capable of configuring itself based on project owned configurations (this is the case when using php-cs-fixer). Edit: To your point of having an opinionated standard set out of the box. PSR12 https://www.php-fig.org/psr/psr-12/ . A rulset for this standard already exists in php-cs-fixer. Edit 2: For absolute transparency, there is also another popular capable of doing everything I mentioned above - https://github.com/squizlabs/PHP_CodeSniffer More on reddit.com
🌐 r/PHPhelp
19
7
August 1, 2024
formatting - Php format on save in Visual Studio Code - Stack Overflow
Can you format on save PHP as well with the Beautify extension of Visual Code ? If yes how do you set it up ? If not which extension does that? More on stackoverflow.com
🌐 stackoverflow.com
vscode not formatting php code

I typed some code similar to yours, and found there was no such option, but changing it to HTML, you can [wrongly] format it. No idea if that is by design, bug, or what, but I'd try https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-intellisense and see if that helps

More on reddit.com
🌐 r/vscode
5
5
May 26, 2022
Can't get PHP formatter to work
Welcome to using VS Code for PHP. For an editor that does so many things well, PHP support sucks. It seems really weird that they would release an editor without built-in ability to indent PHP. Most of the extensions to format PHP are broken or have tons of dependencies. The best one I have found is PHP Intellephense, but it still isn't great. Like who thinks a multi-line statement should have all lines at the same tab-stop?!? More on reddit.com
🌐 r/vscode
2
5
October 31, 2020
🌐
W3Docs
w3docs.com › php
Format code command for PHP/HTML in Visual Studio Code
Click the "Format" button to apply the formatting to the selected text. Alternatively, you can also use the keyboard shortcut Ctrl+Shift+I to automatically format the code in the current document.
🌐
Devsense
docs.devsense.com › vscode › formatting
Code Formatting - PHP Tools for Visual Studio - Documentation
This style focuses on leaving the code visual structure as untouched as possible while normalizing the whitespaces where possible. ... To turn off the formatting select the setting Off. Remaining features like PHPDoc auto-generation will work but Document Format, Selection Format, Format On Paste and Format On Type will do nothing. 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.
🌐
Reddit
reddit.com › r/phphelp › what is the most common php code formatter?
r/PHPhelp on Reddit: What is the most common PHP code formatter?
August 1, 2024 -

I found three code formatters for PHP.

  • Prettier (With PHP Plugin)

  • PrettyPHP (https://github.com/lkrms/vscode-pretty-php)

  • phpfmt (https://github.com/kokororin/vscode-phpfmt)

I was able to setup Prettier with the PHP plugin but the setup is not ideal since I have to install prettier and the prettier PHP plugin from NPM into the project every single time which is not the case when using Prettier VSCode extension with HTML, JS and CSS. I do like how Prettier has its own configuration .prettierrc files and it allows you to set a standard format for a project you are collaborating with others, however I believe formatting should be done in the IDE such as using a VSCode extension and this is the case with the Prettier extension for HTML, JS and CSS but not for PHP since it requires NPM packages.

The other two do not look popular. Am I missing something? I would like to have a standard format or be able to have an opinionated format setup like Prettier for JS but for PHP.

🌐
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
Find elsewhere
🌐
Aslam Doctor
aslamdoctor.com › home › articles › php code sniffing & formatting in vscode
PHP Code Sniffing & Formatting in VSCode - Aslam Doctor
June 16, 2025 - PHP_CodeSniffer is a set of tools that allows linting and formatting of code in one package and it’s an independent tool. You can simply use it as a set of simple commands on the terminal.
🌐
Visual Studio Code
code.visualstudio.com › docs › editing › codebasics
Basic editing
November 3, 2021 - Visual Studio Code is an editor first and foremost, and includes the features you need for highly productive source code editing. This topic takes you through the basics of the editor and helps you get moving with your code. Being able to keep your hands on the keyboard when writing code is crucial for high productivity. VS Code has a rich set of default keyboard shortcuts as well as allowing you to customize them.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
PHP Formatter - Visual Studio Marketplace
December 9, 2016 - Extension for Visual Studio Code - A wrapper for the Sensiolabs PHP CS Fixer. Analyzes some PHP source code and tries to fix coding standards issues (PSR-1 and PSR-2 compatible).
🌐
Codethepixel
codethepixel.com › articles › Formatting-PHP-in-VSCode-Using-Prettier-and-PHP-Intelephense
CTP: Formatting PHP in VSCode Using Prettier and PHP Intelephense
June 15, 2025 - Learn how to set up Visual Studio Code (VSCode) for automatic PHP file formatting using the Prettier and PHP Intelephense extensions. This step-by-step tutorial will help you maintain a clean and organised codebase, enhancing your PHP development experience.
🌐
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.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Unibeautify - Universal Formatter - Visual Studio Marketplace
Extension for Visual Studio Code - Unibeautify (Universal Code Formatter) for Visual Studio Code
🌐
GitHub
github.com › squizlabs › PHP_CodeSniffer › discussions › 3941
vs code formatting mixed php and html · squizlabs PHP_CodeSniffer · Discussion #3941
March 5, 2024 - Open your VS Code settings (press Ctrl + , or go to File > Preferences > Settings). Search for "format" in the search bar to filter formatting-related settings. Adjust the settings for PHP and HTML formatting to your preference.
Author   squizlabs
🌐
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 - To format the PHP language, I suggest you use the VSCode extension called PHP Intelephense which was created by Ben Mewburn. Install the extension first. After the extension is installed, you can go to File -> Preferences -> Settings, then look for "default formatter"
🌐
Devsense
community.devsense.com › d › 145-formatting-issues-in-vs-code
Formatting issues in VS code - PHP Tools Community Forum | DEVSENSE
November 13, 2019 - 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!
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-format-code-with-prettier-in-visual-studio-code
Format Code with Prettier in Visual Studio Code: Setup Guide | DigitalOcean
August 1, 2025 - Instead of manually enforcing style rules or debating formatting choices in code reviews, you can automate the process using a tool like Prettier - a popular, opinionated code formatter. In this article, you’ll learn how to set up and use Prettier in Visual Studio Code (VS Code) to automatically format your code.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
PHP Formatter - pretty-php - Visual Studio Marketplace
Extension for Visual Studio Code - The opinionated PHP code formatter, now with full PHP 8.4 support