Everyday Toolkit

VS Code Beautify Code: Shortcuts & Extensions for Clean Code

Published 2026-07-26

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.

Key takeaways
  • Reformat code instantly using built-in shortcuts like Shift + Alt + F
  • Prettier offers strict, opinionated auto-formatting across multiple languages
  • Enabling format-on-save automates code cleanup every time you work
  • Project-level .prettierrc files keep team formatting completely uniform
VS Code Beautify Code: Shortcuts & Extensions for Clean Code
Photo: Archives New Zealand (BY) via Openverse

Automatically beautifying code in Visual Studio Code requires pressing `Shift + Alt + F` (or `Shift + Option + F` on macOS) or installing dedicated formatting extensions like Prettier. Setting up these tools cleans up messy indentation, enforces syntax consistency, and keeps repositories readable across development teams.

Why Auto-Beautify Your Code in VS Code?

Auto-beautifying code eliminates manual tab-spacing, fixes broken indentation, and maintains consistent syntax rules across your entire repository. Automating this process saves developers significant time during code reviews, reduces unnecessary git diff noise, and prevents petty style arguments between team members working on the same codebase.

Working in a codebase with inconsistent formatting is exhausting. Mixed tabs and spaces, trailing commas, and random line breaks make reading logic far harder than it needs to be. When multiple developers work on the same file, minor spacing changes often clutter pull requests, making genuine logic changes difficult to review. Automating code cleanup fixes these issues at the source. Instead of spending cognitive effort manually aligning brackets or lining up array properties, you let the editor handle structure. This shift keeps pull requests clean, speeds up onboarding for new team members, and ensures your repository maintains a professional standard regardless of who wrote the code.

The Built-in VS Code Formatting Shortcut

VS Code Beautify Code: Shortcuts & Extensions for Clean Code
Photo: occupyreno_media (BY-SA) via Openverse

VS Code includes built-in formatting accessible via `Shift + Alt + F` on Windows/Linux or `Shift + Option + F` on macOS. Alternatively, press `Ctrl + Shift + P` (or `Cmd + Shift + P`), type "Format Document," and press Enter to instantly clean up the active editor window.

Out of the box, Visual Studio Code includes native formatting engines for HTML, CSS, JavaScript, JSON, and TypeScript. You don't need to install external packages just to fix basic indentation or tidy up a quick script. If you only want to tidy a specific snippet rather than an entire file, highlight the block of code and press `Ctrl + K, Ctrl + F` (or `Cmd + K, Cmd + F` on macOS). This triggers the "Format Selection" command, leaving the rest of the document untouched—a helpful trick when working inside legacy codebases where reformatting the entire file might trigger unwanted git changes.

Popular Code Beautifying Extensions

Popular code formatting extensions include Prettier for opinionated multi-language styling, Beautify for legacy setups, and ESLint for JavaScript code quality. Prettier remains the most widely adopted choice because it enforces consistent formatting across JavaScript, TypeScript, HTML, CSS, and Markdown with minimal setup.

While VS Code's default tools work fine for quick edits, dedicated extensions provide much stronger ecosystem support. * **Prettier:** The industry standard for frontend and full-stack projects. It takes an "opinionated" stance, meaning it parses your code and re-prints it from scratch according to strict rules. You trade granular aesthetic control for instant, zero-friction consistency. * **Beautify:** A classic extension based on `js-beautify`. While historically popular for HTML and JS styling, it is now largely unmaintained, and most communities recommend migrating to Prettier or native language servers. * **ESLint:** Primarily a static analysis tool (linter) designed to catch bug-prone logic, ESLint can also fix formatting issues when paired with formatting plugins.

Setting Up Prettier for Automatic Formatting

Install Prettier from the VS Code Extensions Marketplace, then open your settings and enable `Editor: Format On Save`. Setting Prettier as your default document formatter ensures every file auto-cleans instantly whenever you save, completely removing manual formatting keypresses from your everyday coding routine.

To configure Prettier from scratch, follow these straightforward steps: 1. Open the Extensions tab in VS Code (`Ctrl + Shift + X` or `Cmd + Shift + X`). 2. Search for **Prettier - Code formatter** (extension ID: `esbenp.prettier-vscode`) and click **Install**. 3. Open your VS Code Settings (`Ctrl + ,` or `Cmd + ,`). 4. Search for "Default Formatter" and select **Prettier - Code formatter** from the dropdown list. 5. Search for "Format On Save" and check the box next to **Editor: Format On Save**. If you prefer editing raw JSON settings, press `Ctrl + Shift + P`, search for `Preferences: Open User Settings (JSON)`, and add these keys directly: ```json { "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": true } ```

Customizing Prettier Settings with Configuration Files

Customize Prettier settings by creating a `.prettierrc` or `.prettierrc.json` file in your project’s root folder. Defining project-level rules—like single quotes, custom tab widths, and semicolon enforcement—guarantees every contributor formats code identically regardless of their local VS Code settings.

Global editor settings work well for individual projects, but team environments demand shared rules. Placing a `.prettierrc` configuration file in your project root overrides personal VS Code preferences for anyone working in that repository. Here is a common `.prettierrc` configuration used in modern web development: ```json { "semi": true, "singleQuote": true, "tabWidth": 2, "trailingComma": "es5", "printWidth": 80 } ``` Committing this file to git ensures everyone on your team produces identical formatting when saving files, avoiding conflicting style edits across pull requests.

Comparing Code Beautifying Extensions

Choosing a formatter depends on whether your project requires strict automated consistency or custom formatting rules. Prettier excels at effortless zero-config consistency, ESLint handles code logic alongside formatting checks, while built-in VS Code rules handle smaller scripts without adding extra extension overhead.

Tool Best For Pricing Tier Standout Feature
Prettier Multi-language, zero-config formatting Free / Open Source Opinionated, instant multi-language support
Beautify (Legacy) Granular, custom formatting rules Free / Open Source Deep control over JS/HTML spacing (unmaintained)
ESLint Catching syntax bugs and code quality errors Free / Open Source Combines static code analysis with auto-fixing
VS Code Built-in Quick edits without extra extensions Free / Built-in No setup required; handles HTML, CSS, JS out of the box

🛍 Ready to buy? Check current prices on Amazon for the picks in this guide.

Here is how these options rank for general workflow efficiency: 1. **Prettier:** The top recommendation for almost all modern web and application development. 2. **ESLint (with Prettier integration):** Ideal when you need deep code quality checks alongside formatting enforcement. 3. **VS Code Built-in Formatter:** Perfect for lightweight scripts, quick bug fixes, or environments where installing extensions isn't possible.

Troubleshooting Formatting Issues in VS Code

When formatting stops working, open Settings to confirm `Editor: Default Formatter` isn't set to "None." Check for conflicting extensions, inspect the VS Code Output panel under "Prettier" or "Log," and ensure your file type has a valid language mode selected in the bottom-right status bar.

If pressing your shortcut or saving a file fails to reformat code, walk through these common diagnostic checks: * **Syntax Errors:** Most formatters build an Abstract Syntax Tree (AST) before formatting. If your code has missing brackets or invalid syntax, the formatter safely skips the file to prevent breaking logic. * **Multiple Formatter Conflicts:** Having multiple extensions installed (e.g., Prettier, Beautify, and HTML Hint) can cause silent failures. Open Settings, search for `[javascript]` or your specific language, and explicitly set `editor.defaultFormatter`. * **Check the Output Log:** Click **View > Output** from the top menu, then select **Prettier** (or your formatter) from the dropdown list on the right. Any parsing error or configuration failure will print directly in that console.

FAQ

How do I format a single line or selected block in VS Code?

Highlight the specific code block you want to format and press `Ctrl + K, Ctrl + F` on Windows/Linux or `Cmd + K, Cmd + F` on macOS. VS Code will apply your active default formatter exclusively to the highlighted selection without modifying the rest of the file.

Can I use Prettier and ESLint together without conflicts?

Yes, but you should install `eslint-config-prettier` in your project. This configuration turns off all ESLint formatting rules that clash with Prettier, letting ESLint focus on catching code quality issues while Prettier safely manages overall visual layout and style.

Does auto-formatting slow down VS Code?

For standard daily coding, formatting on save executes in milliseconds and causes no noticeable slowdown. Extremely large generated files containing thousands of lines may experience a brief pause during save operations, which you can avoid by adding those files to a `.prettierignore` document.

How do I disable code formatting on save for specific languages?

Open `settings.json` and add language-specific configuration blocks. For instance, adding `"[markdown]": { "editor.formatOnSave": false }` disables automatic formatting specifically for Markdown documents while leaving format-on-save active across all your other source code files.

What is the main difference between a code formatter and a linter?

A code formatter solely restructures visual presentation like spacing, indentation, and quotation marks without touching code logic. A linter analyzes code execution patterns to detect bugs, unassigned variables, syntax errors, and potential security issues alongside optional code style checks.

🛍 See today's best prices on Amazon and grab the option that fits you.

Editorial Team Author & reviewer

Hands-on reviewers testing tools, apps and services so you do not have to. Every article here is hands-on tested and human-reviewed before publishing.