Skip to content
| Marketplace
Sign in
Visual Studio Code>Formatters>Format JS in PHPNew to Visual Studio Code? Get it now.
Format JS in PHP

Format JS in PHP

ErPrabin

|
470 installs
| (0) | Free
Format JavaScript code in PHP files using Prettier - supports selection-based formatting.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Format JS in PHP

Format JavaScript code in PHP files using Prettier - Fast and lightweight!

This VS Code extension allows you to format JavaScript code embedded in PHP files. Works cross-platform (Windows, macOS, Linux) and supports Format on Save. ` Demo

Features

  • Format JavaScript files (.js) using Prettier
  • Format JavaScript code within PHP files (.php)
  • Selection-based formatting - Format only selected code
  • Smart Indentation Preservation - Perfectly preserves existing code indentation, mixing tabs and spaces correctly.
  • Configurable Indentation - Choose tabs or spaces via VS Code settings (formatJsInPhp.useTabs, formatJsInPhp.tabWidth)
  • Lightning fast - Direct Prettier integration (no external processes)
  • Cross-platform support
  • Respects .prettierrc configuration
  • Lightweight and easy to use

Requirements

  • Node.js (for Prettier)
  • Prettier is bundled via npm in the extension

Usage

Format Entire JavaScript File

  1. Open a JavaScript file in VS Code
  2. Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS)
  3. Run Format JS using PHP

Format JavaScript in PHP Files (Selection)

  1. Open a PHP file containing JavaScript code
  2. Select the JavaScript code you want to format
  3. Right-click and choose Format JS in PHP (Selection)
  4. Or use Ctrl+Shift+P and run Format JS in PHP (Selection)

Configuration

Settings Demo

You can customize the indentation style to match your preferences (tabs vs. spaces) by opening your VS Code Settings (Ctrl+, or Cmd+,) and searching for Format JS in PHP:

  • formatJsInPhp.useTabs: Enable this to use Tabs for indentation. Disable it to use Spaces (default).
  • formatJsInPhp.tabWidth: The number of spaces per indentation level. Only applies when useTabs is false (default is 2).

(Note: If your workspace has a .prettierrc file, the extension will also automatically respect those formatting rules!)

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft