Free · Fast · Privacy-first

Indent HTML Properly

Proper indentation is the most basic form of code hygiene, and yet HTML files in the wild routinely fail to have it.

Applies consistent depth-based indentation

🔒

Choose 2 or 4 space indent width

Deterministic output for reproducible results

Browser-only with no upload required

Cost
Free forever
Sign-up
Not required
Processing
In your browser
Privacy
Files stay local
FreeNo signupWhite-label

Add this HTML Formatter to your website

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.

  • Files stay 100% in the visitor's browser
  • Responsive — adapts to any container width
  • Free forever, no API key needed

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.

What Proper Indentation Actually Means and Why It Matters

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.

How to use this tool

💡

Paste your HTML and click Format. The output panel shows the same HTML with proper indentation applied at every nesting level, ready to commit.

How It Works

Step-by-step guide to indent html properly:

  1. 1

    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.

  2. 2

    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.

  3. 3

    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.

  4. 4

    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.

Real-world examples

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.

When to use this guide

Use this when you have HTML with missing or inconsistent indentation and you want a deterministic, properly indented output you can commit and trust.

Pro tips

Get better results with these expert suggestions:

1

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.

2

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.

3

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.

4

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.

5

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.

6

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.

7

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.

FAQ

Frequently asked questions

Indentation makes the document structure visible to a human reader. Browsers ignore whitespace between block-level elements, so the rendered output is identical regardless of indentation, but humans rely on indentation to understand where elements begin and end and how they nest within each other. A properly indented HTML file can be read and edited efficiently, while an unindented file requires manual counting of opening and closing tags to understand the structure. The cost of indentation is essentially zero in file size and zero in rendering performance, while the benefit in maintainability is large and continuous.
Two-space indentation is the modern default used by Prettier, the Google HTML and CSS Style Guide, and most open-source web projects. Four-space indentation is more common in older enterprise codebases, in documentation contexts where extra visual separation helps readers, and in projects that historically used four-space conventions for backend languages such as Python or PHP. The right choice for any specific project is whatever the team has agreed on, because consistency within a project matters more than the technical superiority of either width. If you are starting a new project with no inherited convention, pick two spaces and move on.
Yes, but the effect is small enough to be irrelevant for development and code-review purposes. Properly indented HTML is typically twenty to forty percent larger than its minified equivalent, depending on the depth of nesting. For development workflows the size difference does not matter because file size has no effect on local editing performance. For production deployment, run the indented source through a minifier as the last step of the build pipeline so visitors download the compact version. Keep the indented source in version control and deploy the minified output.
Yes, and it is one of the most common sources of inconsistent indentation in inherited codebases. Different editors render tabs as different visual widths, so a file that looks correct in one editor may look misaligned in another. The standard solution is to use spaces consistently for indentation, configure your editor to insert spaces when the tab key is pressed, and run an indenter like FixTools to normalise any existing tab characters in the file to spaces. After this conversion, the file renders consistently regardless of which editor or viewer is used to display it.
Automate it. Configure your editor to format HTML on save, add a pre-commit hook that runs a formatter on changed HTML files, and add a CI check that fails the build if any committed HTML file is not properly indented. With all three layers in place, no improperly indented HTML can enter the codebase, and the consistent indentation maintains itself without ongoing effort. The setup is a one-time investment that pays back continuously by removing the recurring work of fixing indentation manually and the recurring noise of indentation discussions in code review.

Ready to get started?

Open the full HTML Formatter — free, no account needed, works on any device.

Open HTML Formatter →

Free · No account needed · Works on any device