Two-space indentation is the de-facto standard for modern HTML codebases, used by Prettier, the Google HTML and CSS Style Guide, the Airbnb style guide, and the majority of open-source front-end projects you will encounter.
Loading HTML Formatter…
Strict 2-space indentation
Compatible with Prettier defaults
Consistent across all element types
Free and instant
Drop the HTML Formatter into any page — blog post, product docs, intranet, school portal — with a single line of HTML. Your visitors get the full tool, processed entirely in their browser. No backend, no uploads, no signup.
Embed code
<iframe
src="https://www.fixtools.io/html/html-formatter?embed=1"
width="100%"
height="780"
frameborder="0"
style="border:0;border-radius:16px;max-width:900px;"
title="HTML Formatter by FixTools"
loading="lazy"
allow="clipboard-write"
></iframe>Attribution-friendly: a small "Powered by FixTools" link appears in the embed footer.
Two-space indentation emerged as the dominant convention in front-end development largely because of two influential style guides published by major engineering organisations: Google's HTML and CSS Style Guide, and the Airbnb JavaScript Style Guide. Both of these documents codified two-space indentation as the default, and their adoption across the open-source ecosystem meant that any new developer learning modern web development encountered two-space code far more often than four-space. When Prettier launched as an opinionated code formatter and was rapidly adopted across the JavaScript ecosystem, it reinforced the convention by defaulting to two-space indentation for every file type it supports, including HTML. Today, the majority of open-source front-end projects, component libraries, and framework starter templates use two-space indentation, making it the safe default for any new project.
The technical reason two-space indentation works well for HTML specifically is line length management. HTML structures can nest deeply: a responsive layout might wrap a grid container around a card component, which wraps a content section, which wraps a paragraph, which contains a link with several attributes. With four-space indentation, the paragraph text starts sixteen spaces from the left margin even before any attributes are added, which is far enough to cause horizontal scrolling in editors with narrow panels or in side-by-side diff views. Two-space indentation keeps deeply nested content within the common eighty to one hundred twenty character line length limit, reducing the need to scroll or wrap lines and making the code comfortable to read in a standard editor configuration. FixTools applies exactly two spaces per nesting level with no variation, which means the output is predictable and matches what other two-space tools produce.
The main trade-off of two-space indentation is that the visual distinction between levels is subtle for readers who are unfamiliar with the code. A developer new to a two-space codebase, or a non-developer reviewing HTML for content changes, may find it harder to quickly identify parent-child relationships than in a four-space file where the visual jump between levels is larger. For documentation aimed at non-developers, for teaching contexts where the audience is learning HTML for the first time, or for printed code samples where the visual jump matters more than line length, four-space is sometimes preferred even when the underlying project uses two-space. This is a reasonable pattern and many teams adopt it deliberately as a translation step between developer source and end-user documentation.
A practical advantage of two-space indentation is round-trip compatibility with the broader ecosystem. If you open-source a project, contribute to an open-source library, or accept pull requests from external contributors, two-space output works without friction because it matches what the contributor's formatter is likely configured to produce. Choosing a non-default indent width can subtly increase the friction of every external contribution because every contributor needs to either match your width or accept that their formatter will fight your convention. Picking the ecosystem default reduces this friction to zero.
Paste your HTML and click Format. The output uses exactly 2 spaces per indentation level, matching the default used by Prettier and most modern frameworks.
Step-by-step guide to html formatter with 2-space indentation:
Paste your HTML
Paste any HTML into the input panel of the HTML Formatter. The tool accepts fragments, partial templates, and complete documents with the same logic, and there is no length restriction beyond the practical memory limit of your browser tab.
Select 2-space indentation
Choose the two-space option in the indent selector. This setting produces output that matches Prettier defaults, the Google Style Guide, and the convention used by the majority of modern front-end projects.
Click Format
Click Format to run the parse and re-serialise step. The output is formatted with exactly two spaces per nesting level, applied consistently to every block element from the outermost wrapper down to the deepest leaf.
Copy the result
Copy the two-space-indented HTML with the clipboard button and use it in your project, pull request, documentation, or anywhere else you need clean two-space output. The original input remains in place in case you want to re-run with a different setting.
Common situations where this approach makes a real difference:
Reformatting files before adding to a Prettier-controlled repo
Pre-formatting HTML with two-space indent before committing means that Prettier's pre-commit hook will not flag the files with formatting diffs, which keeps the commit history clean and avoids the awkward pattern where every contribution starts with an automatic Prettier reformat commit before any substantive change.
Aligning a freelancer's deliverable with project standards
A contractor delivers HTML with four-space tab indentation, which does not match the in-house project standard of two-space spaces. Pasting the deliverable into the formatter with two-space selected standardises every file in minutes, making the deliverable ready for review without manual conversion work.
Standardising design system component examples
A design system documentation site presents HTML examples for every component. Running every example through the formatter with two-space indent before publishing ensures the documentation feels consistent, which improves the perceived quality and reduces follow-up questions from consumers of the library who notice and ask about inconsistencies.
Converting legacy four-space code to modern conventions
An older PHP project with four-space HTML indentation is being modernised to match the conventions of newer projects in the same organisation. Running every file through the formatter with two-space selected produces a single batch conversion commit that brings the legacy code into alignment without weeks of manual editing.
Use this when your project enforces 2-space HTML indentation (Google Style Guide, most front-end frameworks) and you need to normalize existing files.
Get better results with these expert suggestions:
Set tabWidth: 2 in your Prettier config to match FixTools output
If your project uses Prettier for JavaScript, TypeScript, or CSS, adding tabWidth two to your .prettierrc ensures that when Prettier runs on HTML files, the output matches what FixTools produces. Consistency across all formatters in a project eliminates the formatting conflicts that arise when different tools produce different output for the same input, and it means a developer can use either tool depending on the situation without the project drifting between two slightly different styles.
Use 2-space output to spot over-nesting early
When code formatted at two spaces still reaches the right margin of your editor, the nesting is almost certainly too deep and the structure should be examined. Two-space indentation is a lighter warning signal than four-space because the jumps are smaller, but it still flags structures that should be refactored or broken into smaller components. A line that exceeds the column limit at two-space depth indicates either over-nested wrappers or an attribute list that has grown beyond what one element can reasonably carry.
Add indent_size = 2 to .editorconfig before onboarding contributors
New contributors set up their editors with whatever defaults their installation provides, which may or may not match your project. An .editorconfig file with indent_size two and indent_style space ensures auto-indent works correctly from their very first commit, without requiring any manual editor configuration or out-of-band setup documentation. Most modern editors read .editorconfig automatically, so the single file removes a friction point for every new team member.
Make indent conversion a dedicated commit
When converting from four-space to two-space across an entire codebase, commit the change in isolation with a clear message such as "chore: convert HTML indentation from 4-space to 2-space". This keeps formatting changes out of git blame results for functional lines, makes the history searchable, and gives future readers a clear answer when they wonder why every file changed on the same day. Many version control workflows let you mark cosmetic commits as ignorable for blame purposes, which further reduces long-tail noise.
Match your Prettier config
If your project uses Prettier, the 2-space HTML output from FixTools matches Prettier's default, making it easy to maintain consistency without running the full build pipeline.
2 spaces keeps line length manageable
On deeply nested structures, 2-space indentation prevents lines from exceeding the standard 80-120 character limit, reducing the need for horizontal scrolling.
Commit a .editorconfig
Once you've decided on 2-space indentation, add an .editorconfig to your project so all team editors enforce it automatically.
More use-case guides for the same tool:
Open the full HTML Formatter — free, no account needed, works on any device.
Open HTML Formatter →Free · No account needed · Works on any device