Proper indentation is the most basic form of code hygiene, and yet HTML files in the wild routinely fail to have it.
Loading HTML Formatter…
Applies consistent depth-based indentation
Choose 2 or 4 space indent width
Deterministic output for reproducible results
Browser-only with no upload required
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.
Proper indentation means that the depth of each element in the source code matches the depth of that element in the document tree. A direct child of the body sits at one level of indentation, a child of that element sits at two levels, and so on through the deepest nested elements. This depth-based correspondence is what makes formatted HTML scannable: a reader can follow the visual indentation line to understand the structural hierarchy without having to manually count opening and closing tags. The visual hierarchy is also what makes mistakes obvious; a closing tag at the wrong indentation level immediately suggests a structural error worth investigating.
FixTools indents HTML properly by parsing the input into a document tree using a standards-compliant HTML5 parser and re-emitting each element with indentation matching its depth in the tree. The indentation width is configurable between two and four spaces, with two spaces as the default because it matches the modern convention used by Prettier and most open-source projects. The output is deterministic, which means anyone who pastes the same input gets the same output. Reproducibility is a feature of conservative defaults, and it pays back in shared workflows where multiple developers need to produce consistent results from the same source.
A common source of improperly indented HTML is automated tooling that produces output without applying indentation. Build pipelines that combine partial templates, server-side rendering frameworks that emit HTML strings, and content management systems that store post content as HTML all frequently produce output with inconsistent or absent indentation. Running this output through a proper indenter as a post-processing step is a quick way to make the generated HTML readable for debugging or auditing without changing the generation logic itself. This is particularly useful when the generation tool is a third-party system whose internals you cannot modify.
Indentation is the entry point to readable code, but it is not the entire story. A properly indented file with poor semantic structure is still hard to maintain, and a properly indented file with accessibility issues is still inaccessible. Treat indentation as the foundation that makes other improvements visible; once the indentation is consistent, the structural and semantic issues that need attention become much easier to spot. The combination of consistent indentation, valid structure, and thoughtful semantics is what produces HTML that genuinely supports long-term maintenance.
Paste your HTML and click Format. The output panel shows the same HTML with proper indentation applied at every nesting level, ready to commit.
Step-by-step guide to indent html properly:
Paste your HTML
Paste any HTML into the input panel, regardless of its current indentation state. Mixed indentation, missing indentation, and tab-and-space combinations all work as input.
Choose your indent width
Select two-space or four-space indentation depending on your project standard. The default is two spaces, which matches the modern convention used by Prettier.
Click Format
Click Format to apply consistent depth-based indentation. The output appears with each element indented to match its depth in the document tree.
Commit or share the result
Commit the properly indented output to version control as a standalone formatting change, or share it with collaborators who need a readable copy.
Common situations where this approach makes a real difference:
Standardising indentation across a legacy codebase
A team running a one-time formatting pass on a legacy codebase uses FixTools to indent every HTML file properly. The standardised output makes subsequent code reviews dramatically more productive because reviewers spend their attention on substance rather than whitespace. The team estimates the indentation pass paid back its setup time within the first two weeks.
Cleaning up automated build output for debugging
A developer indents the output of a build pipeline that produces compressed HTML to debug a layout regression. The properly indented version reveals a missing wrapper element that was the actual cause of the regression. The fix is in the upstream template, but identifying the issue required the formatted output to be readable first.
Preparing HTML for an external code review
A consultant indents the HTML of an internal application before sharing it with an external developer for review. The properly indented version produces a much more substantive review because the external developer can engage with the structure immediately rather than spending the first hour formatting in their head.
Onboarding a new developer to inherited code
A team indents all HTML files in a recently inherited project before adding a new developer to the project. The new developer ramps up significantly faster than they would have against the original inconsistent source, because the consistent indentation makes the structural patterns obvious from the first day.
Use this when you have HTML with missing or inconsistent indentation and you want a deterministic, properly indented output you can commit and trust.
Get better results with these expert suggestions:
Standardise indentation across the team
Document the chosen indentation width in a project README or contributing guide so every contributor knows the expected style. Configure editor settings, pre-commit hooks, and CI checks to enforce the chosen width automatically. Documented and automated indentation removes the recurring discussion about formatting from code review, which lets reviewers focus on substance. The one-time effort of setting up the documentation and automation pays back every time a code review happens without the team relitigating the indentation choice.
Use indentation as a quick smoke test for generated output
When evaluating a new HTML generation tool, paste its output into a proper indenter and look at the result. Tools that produce structurally clean output indent into a sensible tree, while tools that emit malformed HTML produce indented output with obvious structural errors that suggest implementation bugs. This is a quick way to evaluate generation tools without writing extensive test cases, and it surfaces real issues that the tool documentation may not mention.
Indent before running other formatters
Some other HTML-aware tools, such as accessibility checkers and SEO auditors, produce more useful output when run against properly indented HTML. The tools work on the underlying DOM regardless of formatting, but their reports often include line numbers that are much more useful when the file is properly indented. Indenting first produces reports where each issue points to a clearly identifiable line in a readable file, rather than to a line in a wall of unformatted text.
Use indentation to detect tag mismatches
A subtle but powerful use of proper indentation is detecting opening and closing tag mismatches that the parser tolerates but a human would consider errors. After indenting, scan the output for closing tags that appear at unexpected depths. These often indicate that an opening tag is missing somewhere upstream, or that a closing tag was placed at the wrong nesting level. The visual depth makes the mismatch obvious in a way that examining the raw source rarely does.
Pick a width and stick to it
Choose two or four spaces for your project and apply it consistently across all HTML files. Consistency matters more than which width you choose.
Indent before committing
Make proper indentation part of your pre-commit workflow so no improperly indented HTML enters the repository. A pre-commit hook automates this.
Use deterministic tools for reproducibility
Pick formatters that produce the same output for the same input, regardless of who runs them. This eliminates whitespace conflicts in collaborative work.
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