VSCode Prettier not formatting PHP

VSCode Prettier not formatting PHP

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

VSCode Prettier Not Formatting PHP Files? Fix Your Language IDs and Plugin Conflicts

It is a common frustration when setting up a modern editor stack: HTML files format perfectly, but PHP files remain stubbornly unformatted. You might look at your .eslintrc.json or settings.json expecting to find a missing configuration flag, only to realize the issue lies in how VSCode identifies the file and which formatter it delegates the work to.

When you observe that HTML code inside a .php file formats differently than standalone .html files—specifically when using a plugin like "Beautify" as a last resort—it indicates a conflict between multiple formatters or incorrect language identification. Prettier is a fantastic tool, but it requires the correct environment to execute, and VSCode relies on explicit configuration to know which engine handles which file type.

Configuring the PHP Language ID

The most immediate hurdle is ensuring VSCode treats your .php files as code that should be formatted by Prettier. By default, the editor might not associate Prettier with PHP unless explicitly told to do so.

In your settings.json, you need to ensure the prettier.config.path (if using a specific config) or simply enable the plugin for PHP. However, a more robust approach involves checking the editor.formatOnSave and editor.defaultFormatter settings specifically for the php language ID.

Add the following entries to your workspace settings to enforce Prettier as the default formatter for PHP files:

{
  "editor.defaultFormatter": {
    "source.php": "esbenp.prettier-vscode"
  },
  "editor.formatOnSave": true,
  "[php]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}

This configuration explicitly tells VSCode to use the Prettier extension for PHP files. The bracket notation [php] ensures this applies specifically to that language identifier, overriding any global defaults.

Resolving Beautify vs. Prettier Conflicts

Your source material mentions using "Beautify" as a last option for HTML inside PHP files. This is the root cause of the inconsistent formatting you are seeing. Having multiple active formatters for the same file type leads to race conditions where one formatter runs, then another overwrites its work, or they run in an unpredictable order.

To fix this, you must disable the Beautify plugin for languages that Prettier handles. Look for settings related to beautify in your configuration and ensure it does not target PHP or HTML within Blade templates (blade).

In your settings.json, check for any entries like:

"beautify.language": { "html": ["php", "blade"] }

If you are relying on Prettier to handle the formatting, this configuration is unnecessary and potentially destructive. It forces Beautify to run after Prettier, negating Prettier's output. Remove or comment out these lines if you want a consistent, single-source-of-truth formatting experience.

Handling ESLint and Prettier Integration

Your .eslintrc.json currently extends prettier/react. This is a valid setup for React applications, but it can cause confusion in non-React PHP projects if not scoped correctly. The prettier rule inside ESLint acts as a linting layer; however, the actual formatting engine must still be Prettier running via the VSCode extension.

Ensure that your ESLint configuration does not try to format code itself (e.g., using eslint --fix), as this can conflict with Prettier's output if both are enabled on save. Your current config sets editor.codeActionsOnSave.mode to all, which triggers both ESLint fixes and formatter saves. This is generally fine, provided that only one formatter (Prettier) is active for PHP.

If you are using Laravel or Blade templates, note that the syntax highlighting and formatting logic can differ between standard PHP and Blade directives. If you find that Blade files inside .php are still being handled by Beautify, ensure that your prettier.config.js includes rules specifically for Blade syntax if necessary, or rely solely on Prettier's built-in support for PHP/Blade without external beautifiers.

Conclusion: A Single Formatter Strategy

The key to solving this issue is exclusivity. Your editor should only have one formatter active per file type. By configuring VSCode to use esbenp.prettier-vscode explicitly for PHP and removing the "Beautify" fallback from your beautify.language settings, you ensure that HTML within PHP files formats identically to standalone HTML files.

This approach eliminates the inconsistency where different parts of your codebase get formatted by different engines. Stick with Prettier for all frontend-related languages (HTML, CSS, JS, and PHP/Blade) to maintain a unified style across your entire project.

Our network