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
PHP Formatter - pretty-php - Visual Studio Marketplace
Extension for Visual Studio Code - The opinionated PHP code formatter, now with full PHP 8.4 support
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

Best php extension for vs code?
Intelephense, phpcbf, and phpcs are the three big ones for me. More on reddit.com
🌐 r/PHPhelp
16
11
August 7, 2022
VScode and PHP - Any beautify plugins?
I am using this. Not perfect but better than the rest. https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client More on reddit.com
🌐 r/webdev
6
1
April 30, 2019
Formatting PHP in Visual Studio on Windows
I am looking for an extension to help format my php while using VS Code editor. phpfmt seems to be very popular, however, the git repo is archived… More on reddit.com
🌐 r/Wordpress
2
1
November 14, 2020
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
🌐
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
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).
🌐
Devsense
docs.devsense.com › vscode › formatting
Code Formatting - PHP Tools for Visual Studio - Documentation
Formatter will help you keep your PHP code in VS Code clean and maintain the preferred code style like PSR-12, PSR-2, Allman and K&R.
🌐
GitHub
github.com › squizlabs › PHP_CodeSniffer › discussions › 3941
vs code formatting mixed php and html · squizlabs PHP_CodeSniffer · Discussion #3941
March 5, 2024 - 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
🌐
GitHub
github.com › vysker › vscode-php-formatter
GitHub - vysker/vscode-php-formatter: Visual Studio Code extension. 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).
After installing as an extension with Visual Studio Code, this extension automatically formats your PHP code, in accordance with PSR-0, PSR-1, PSR-2 or Symfony style conventions. Format current selection only, or the whole file. Trigger formatting with custom keybindings or actions.
Starred by 90 users
Forked by 12 users
Languages   TypeScript 89.5% | JavaScript 10.5% | TypeScript 89.5% | JavaScript 10.5%
🌐
Aslam Doctor
aslamdoctor.com › home › articles › php code sniffing & formatting in vscode
PHP Code Sniffing & Formatting in VSCode - Aslam Doctor
June 16, 2025 - While coding in PHP using VSCode, there are plenty of extensions that provide code formatting. Some of those are PHP Intelephense, phpfmt, and PHP Formatter. These are good extensions but don’t provide a better solution for code sniffing and formating code using PHP Standards.
🌐
Reddit
reddit.com › r/phphelp › best php extension for vs code?
r/PHPhelp on Reddit: Best php extension for vs code?
August 7, 2022 -

I switched from vscode + intelephense to phpstorm and i find it reeeeaaaally hard to go back because of all of the functionality that storm offers

However, i love vscodes snappiness and ease of use that phpstorm will never match

Is there any way out? How do I combine both? Im willing to pay for an extension just to get best of both worlds

🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
PHP Sniffer & Beautifier - Visual Studio Marketplace
December 28, 2025 - Extension for Visual Studio Code - PHP Sniffer & Beautifier for Visual Studio Code
🌐
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 - 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. Then you create settings.json using Ctrl + Shift + P then search for "open user settings". Select the (JSON) one. Then the settings.json file will open. So here add the following configuration: "[php]": { "editor.defaultFormatter": "bmewburn.vscode-intelephense-client" }
🌐
Laravel Daily
laraveldaily.com › post › vs-code-extensions-laravel-php
Four VS Code Extensions For Laravel/PHP Projects
Laravel Pint is a code formatter specifically for Laravel. It makes sense to use it in VSCode as well. With this extension, we get a few nice features: ... While it doesn't seem like it does much, it's just nice to run Pint from the editor. You can get the extension from the VSCode Marketplace · The last extension we used is PHP...
🌐
Jamesauble
jamesauble.com › blog › vs-code-php-formatter-that-actually-works-maclinux
VS Code PHP Formatter That Actually Works (Mac/Linux) - James Auble
February 24, 2022 - Open any .php file in VS Code right click in the editor and click on Format Document. If that formatted your code then great!
🌐
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
🌐
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.
🌐
Medium
aidilfitra.medium.com › the-ultimate-guide-to-code-formatters-plugin-in-vs-code-every-language-one-editor-3457d248b5d1
The Ultimate Guide to Code Formatters Plugin in VS Code: Every Language, One Editor | by Aidil Fitra | Medium
June 9, 2025 - The Ultimate Guide to Code Formatters Plugin in VS Code: Every Language, One Editor Make your VS Code smarter — from Python to PHP, JavaScript to Rust — and format every file …
🌐
Bordermedia
bordermedia.org › blog › using-prettier-format-php-in-vscode
Using Prettier to format PHP code in VS Code
June 19, 2025 - Learn how to use Prettier to format PHP code in VS Code using the @prettier/plugin-php community plugin. Complete setup guide with configuration examples and troubleshooting tips.
🌐
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