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
104

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
51

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.

🌐
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
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
PHP Formatter - Visual Studio Marketplace
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.
🌐
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 ...
🌐
GitHub
github.com › squizlabs › PHP_CodeSniffer › discussions › 3941
vs code formatting mixed php and html · squizlabs/PHP_CodeSniffer · Discussion #3941
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
🌐
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.

Find elsewhere
🌐
YouTube
youtube.com › watch
Installing and setting up PHP code formatter extension or php cs fixer on Visual Studio Code - YouTube
Installing and setting up PHP code formatter extension or php cs fixer on Visual Studio Code:Follow this article:https://medium.com/@armorasha/php-cs-fixer-h...
Published   September 15, 2021
🌐
Codethepixel
codethepixel.com › articles › Formatting-PHP-in-VSCode-Using-Prettier-and-PHP-Intelephense
CTP: Formatting PHP in VSCode Using Prettier and PHP Intelephense
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.
🌐
Bordermedia
bordermedia.org › blog › using-prettier-format-php-in-vscode
Using Prettier to format PHP code in VS Code
Using Prettier to format PHP code in VS Code provides several benefits: Consistency across multiple languages in your project ... The @prettier/plugin-php plugin makes it easy to extend your existing Prettier setup to include PHP files, maintaining ...
🌐
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
🌐
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!
🌐
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
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.
🌐
Aslam Doctor
aslamdoctor.com › home › articles › php code sniffing & formatting in vscode
PHP Code Sniffing & Formatting in VSCode - Aslam Doctor
June 16, 2025 - The linting tool provided is called phpcs and the formatting tool provided is called phpcbf. You will need composer to install PHP_CodeSniffer on your system.
🌐
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).
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). - vysker/vscode-php-formatter
Starred by 90 users
Forked by 12 users
Languages   TypeScript 89.5% | JavaScript 10.5%
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
PHP Sniffer & Beautifier for VS Code
Extension for Visual Studio Code - PHP Sniffer & Beautifier for Visual Studio Code