Four-space indentation makes every nesting level unmistakably clear, which is why it remains the preference in documentation, enterprise codebases, and teams transitioning from older style guides that established four-space as the project norm.
Loading HTML Formatter…
Strict 4-space indentation applied to every level
Makes nesting depth immediately obvious
Preferred for documentation and printable code examples
Free with no sign-up 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.
Four-space indentation has a longer history in software development than two-space, partly because it was the default in many early editors and integrated development environments, and partly because it makes the hierarchy of nested structures easier to see at a glance with no prior context. Each indentation level is visually distinct even on wide monitors, on projected screens, or in printed documents. For HTML specifically, the visual jump matters in documentation contexts where readers may not be familiar with the tag names and rely on visual cues to understand structure. A reader scanning a code sample in a tutorial, a reference guide, or a printed handbook can follow the nesting at four-space widths without needing to count spaces carefully or trace tag pairs by hand.
FixTools applies four-space indentation by traversing the parsed HTML tree and emitting each node with a prefix of four spaces multiplied by its depth in the tree. The rules for block versus inline elements are identical to the two-space mode: block elements get their own lines so the structure is visible vertically, inline elements stay with their text content to preserve reading flow and avoid the inline-block whitespace gap, and void elements such as img, br, hr, and input are correctly handled without closing tags being added. The only difference between two-space and four-space modes is the width of each indent step. If your file currently uses two-space, tab, or mixed indentation, the formatter converts it to clean four-space output in a single pass.
The trade-off with four-space indentation is line length, which becomes the dominant consideration in deeply nested structures. A structure nested six levels deep starts its content twenty-four characters from the left margin before any tag name or attribute appears. In typical HTML layouts with nested tables, forms, complex components, or attribute-heavy framework templates, this often pushes attribute-heavy tags past the eighty-column mark that most style guides use as a soft line limit. If your team enforces a strict line length, consider whether two-space serves the project better, or use four-space only for documentation outputs that are converted from a two-space source as a build step.
A nuanced point that experienced teams discover: four-space indentation tends to flag over-nested HTML earlier and more visibly than two-space. When code at four-space depth starts running off the right edge of the editor, the developer notices the problem immediately and is prompted to refactor. With two-space, the same structural complexity may go unnoticed for longer because the lines fit comfortably. Some teams deliberately use four-space during refactoring sprints to make complexity visible, then switch back to two-space for ongoing work. This is an unusual pattern but a useful technique when the goal is reducing structural complexity rather than just maintaining it.
Paste your HTML and select 4-space indentation before clicking Format. Every child element will be offset by exactly 4 spaces from its parent.
Step-by-step guide to html formatter with 4-space indentation:
Paste your HTML
Paste any HTML code into the input panel on the HTML Formatter. The tool handles fragments, partial templates, and complete multi-section documents with the same logic and there is no length restriction beyond your browser tab's memory.
Select 4-space indentation
Choose the four-space option from the indent selector. This setting matches enterprise style guides, traditional documentation conventions, and projects that historically used four-space conventions inherited from backend languages.
Click Format
Click Format to run the parse and re-serialise step. Every element is indented with exactly four spaces per nesting level, applied consistently from the outermost wrapper down to the deepest leaf in the tree.
Copy the output
Copy the four-space formatted HTML with the clipboard button and use it in your documentation, editor, training materials, or wherever the wider indent is required. The original input remains in place if you want to re-run with the two-space setting to compare.
Common situations where this approach makes a real difference:
Documentation site code samples
A component library generates HTML examples for its documentation site. Using four-space indentation makes the output more scannable for designers reviewing the documentation, reducing clarification questions about element nesting and improving the perceived quality of the documentation overall.
Converting tab-indented legacy HTML
An enterprise codebase with tab-indented HTML files spanning eighty kilobytes per file is converted to four-space space indentation, producing consistent output across all editors and continuous integration environments without changing any visual line widths that developers were accustomed to seeing.
Printed code handout for a training workshop
An instructor formats twelve HTML examples at four-space indentation before printing handouts. Attendees follow the nesting relationships without a code editor, reducing structural questions during the workshop and freeing the instructor to focus on substantive concepts rather than spending time explaining the indentation of each example.
Accessibility audit submission
Before submitting HTML to an external accessibility auditor, the development team formats all files at four-space indentation to maximise visual clarity. The auditor identifies three heading-order issues within the first hour of review, citing the clear nesting visibility as the reason the issues were easy to locate without code-navigation tools.
Use this when your project, team style guide, or documentation standard requires 4-space indentation and you need to normalise existing HTML files quickly.
Get better results with these expert suggestions:
Use 4-space for design system documentation
When writing a component library's HTML documentation, four-space indentation makes the structural hierarchy obvious to designers and stakeholders who read the code examples but may not write HTML regularly themselves. The wider indent reduces the need for comments explaining nesting, because the visual structure communicates the hierarchy directly. This is particularly useful for design system documentation that is consumed by mixed audiences including engineers, designers, and product managers.
Keep a 4-space formatted copy alongside your 2-space source
For projects that maintain both a developer source in two-space and a documentation site that presents HTML examples, set up a separate build step that converts the two-space source to four-space output for the documentation. Automate this in your build pipeline so the two versions stay in sync automatically and you never have to manually maintain two copies of the same HTML at different indent widths.
Use 4-space for code review annotations
When submitting HTML for review by non-developers such as accessibility auditors or content editors, format the HTML at four-space first. The wider indentation communicates the document structure more clearly to reviewers who read code infrequently and cannot rely on intuition built from years of scanning two-space markup. A small formatting step before sharing reduces clarification questions during the review and produces more substantive feedback.
Convert tabs to 4-space to match legacy codebases
Many older enterprise codebases used tab indentation configured to display as four spaces in each developer's editor. Converting those files to explicit four-space spaces preserves the visual appearance while removing the ambiguity of tab width settings across different editors and platforms. After conversion, every developer sees the same indentation regardless of their editor configuration, which eliminates a category of subtle confusion that crops up in tab-based projects.
Use 4-space for printed code samples
Four-space indentation reads better on paper and in slides. For any HTML going into documentation, a printed handout, or a presentation, 4-space is the clearer choice.
Convert 4-space to 2-space before merging to shared repos
If your team project uses 2-space, write documentation examples in 4-space for clarity but convert them before committing code to the shared repository.
Check line lengths after formatting
Run a line-length check on 4-space formatted HTML to catch any lines exceeding your project's character limit. Long lines are more likely with 4-space than 2-space.
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