How to Format HTML Code in VS Code: Shortcuts & Settings
Updated Jul 2026
Some links on this page are affiliate links. If you buy through them we may earn a small commission at no extra cost to you. We only recommend what we'd use.
- Use Shift + Alt + F (Shift + Option + F on Mac) to instantly clean up messy HTML
- Customize native html.formatter settings for custom indentation and wrapping
- Install Prettier or Beautify for strict, team-wide style enforcement
- Enable editor.formatOnSave to automate clean markup every time you save.

How to Format HTML Code in VS Code: Shortcuts & Settings
You can instantly format HTML code in VS Code by pressing `Shift + Alt + F` on Windows/Linux or `Shift + Option + F` on macOS, which triggers the editor's built-in formatting engine or your chosen default extension. Maintaining readable code keeps projects organized, simplifies debugging, and helps team members review pull requests without getting distracted by inconsistent spacing or unaligned tags.
🛍 Ready to buy? Check current prices on Amazon for the picks in this guide.
The Core Shortcut: `Shift + Alt + F`
The primary keyboard shortcut to format HTML in VS Code is `Shift + Alt + F` on Windows and Linux, or `Shift + Option + F` on macOS. Pressing this combination immediately cleans up your markup by fixing bad indentation, aligning closing tags, and standardizing spacing according to your active formatting engine.
If you prefer using the mouse, right-click anywhere inside the editor window and select Format Document from the context menu. Alternatively, open the Command Palette with `Ctrl + Shift + P` (or `Cmd + Shift + P` on macOS), type "Format Document," and hit Enter. If you have multiple formatters installed, VS Code will prompt you to choose a default tool the first time you run this command.
Understanding the Default Formatting Rules
VS Code comes out of the box with a built-in HTML formatter powered by JS Beautify. By default, it applies two-space indentation, wraps attributes across multiple lines when they exceed standard lengths, and preserves line breaks between block-level elements so your raw markup remains structured and legible.
Out of the box, the editor treats inline elements like ``, ``, and `` differently than block elements like ` You customize HTML formatting in VS Code by opening the Settings editor (`Ctrl + ,` or `Cmd + ,`) and adjusting parameters under the `html.formatter` namespace. These configurations allow you to tweak indentation sizing, toggle attribute line-wrapping rules, enforce tag closing behavior, and set max line-length thresholds. To modify these rules via the graphic interface, search for "HTML format" in the search bar. If you prefer editing raw JSON, open your `settings.json` file directly and add custom keys under the main configuration block. Workspace-specific settings saved in `.vscode/settings.json` will override your global user settings, which works well when different projects demand distinct styling guidelines. The most influential native HTML settings include `html.formatter.enable` to toggle the formatting engine, `html.formatter.indentSize` to set space counts, `html.formatter.wrapAttributes` to control attribute placement across lines, and `html.formatter.wrapLineLength` to define maximum characters per line before soft line breaks occur across your document. Installing third-party extensions expands VS Code beyond basic HTML indentation into full-stack code style enforcement across mixed files like JSX, Vue, or PHP templates. Extensions replace or augment the native formatter, granting access to stricter style guides, custom config files, and multi-language formatting capabilities. While the native tool is fine for simple static pages, modern web projects frequently blend HTML with JavaScript frameworks or templating languages. Dedicated extensions parse complex syntax trees accurately, ensuring that nested tags inside component templates do not break during routine formatting passes. Prettier is an opinionated code formatter that handles HTML alongside CSS and JavaScript with minimal setup required. Once set as your default HTML formatter in VS Code settings, Prettier automatically enforces strict, unified formatting rules across your entire codebase every time you format your document. Because Prettier takes an opinionated approach, it removes endless debates about code styling across teams. You install the "Prettier - Code Formatter" extension from the VS Code Marketplace, set `"editor.defaultFormatter": "esbenp.prettier-vscode"` in your settings, and let it manage indentation, attribute quoting, and bracket spacing automatically. It relies on a local `.prettierrc` file in your repository root to keep rules consistent across every developer's machine. Beautify is a flexible VS Code extension that gives developers granular control over whitespace, attribute alignment, and nested tag structure. It reads custom `.jsbeautifyrc` configuration files in your workspace, making it ideal if you want deeper customization options than Prettier's rigid, opinionated default rules. If you need precise control over where closing brackets land or how embedded JavaScript blocks within `Customizing Your HTML Formatting with Settings

Key Settings to Consider
Leveraging Extensions for Advanced Formatting
Prettier: A Popular Choice for Consistent Formatting
Beautify: Another Robust Formatting Option