HTML Indent Code

code
Loading feedback…

HTML Indent Code: paste minified or messy HTML and get correctly indented code. Each nested tag moves in one level. Choose 2 spaces, 4 spaces or tabs, then copy the result.

Last updated: October 5, 2026•Author: Mateo Díaz•Reviewed by: Riley Williams
Updates as you typePrivate: stays in your browser
Try an example:
Indent with
More options
Line width

Longer lines move to the next line at this length.

Copy the indented HTML

Your indented HTML appears here

Use this tool to indent HTML code correctly. Paste minified HTML, HTML on one line or HTML with incorrect spaces. The tool puts each tag on its own line and moves each child tag one level in from its parent. The colored guides show each nesting level, so you can see the structure of the page immediately.

How to Indent HTML Code

  1. Paste your HTML in the box above, or click Upload file.
  2. Select 2 spaces, 4 spaces or Tabs.
  3. Examine the result. The line numbers and the guides show each level.
  4. Click Copy indented HTML or Download .html.

A full page and a small part of a page both work. You do not have to add <html> or <body> tags.

Input:

<nav>
  <ul>
    <li><a href="/">Home</a></li>
    <li><a href="/blog">Blog</a></li>
  </ul>
</nav>

Output (2 spaces):

<nav>
  <ul>
    <li><a href="/">Home</a></li>
    <li><a href="/blog">Blog</a></li>
  </ul>
</nav>

HTML Indentation Rules

  • Indent each child element one level. A <li> is one level in from its <ul>. The <ul> is one level in from its <nav>.
  • Put the closing tag at the same level as the opening tag. Then you can find the end of each block quickly.
  • Use one indent size in the file. Do not mix 2 spaces, 4 spaces and tabs.
  • Keep short inline elements on one line. Tags such as <a>, <b> and <span> can stay inside the line of text.
  • Indent <head> and <body> inside <html>. Some teams do not indent these two tags. Both styles are correct if you use one style in all files.

2 Spaces, 4 Spaces or Tabs?

IndentUse it when
2 spacesYou want the default. The Google HTML/CSS Style Guide uses 2 spaces. Deep nesting stays readable.
4 spacesYour project uses 4 spaces for its other code, for example Python or PHP templates.
TabsYour team wants each person to set the indent width in their own editor.

Indentation does not change how the browser shows your page. Browsers ignore the spaces between tags. The tool keeps the spaces inside your text, inside <pre> blocks and next to inline tags, so the page looks the same.

Find Unclosed and Incorrect Tags

If the HTML has a structure problem, the tool shows the line and the column of the problem. For example:

Line 1, column 17: Unexpected closing tag "span".

This error tells you that a </span> has no <span> before it. Correct the tag at that position. The tool then indents the code again. Correct indentation also shows missing closing tags: when a block does not move back out to its level, a closing tag is missing.

Auto-Indent HTML in Your Code Editor

EditorIndent the full fileIndent selected lines
VS Code (Windows)Shift+Alt+FCtrl+] (in) and Ctrl+[ (out)
VS Code (Mac)Shift+Option+FCmd+] (in) and Cmd+[ (out)
VS Code (Linux)Ctrl+Shift+ICtrl+] (in) and Ctrl+[ (out)
WebStorm and PhpStormCtrl+Alt+L (Cmd+Option+L on a Mac)Tab (in) and Shift+Tab (out)
Sublime TextEdit > Line > ReindentCtrl+] (in) and Ctrl+[ (out)
Notepad++Use a plugin such as XML Tools > Pretty print. It works only on well-formed markup.Tab (in) and Shift+Tab (out)
Chrome DevToolsSources panel > click the {} (pretty print) buttonNot available

Indent Text on a Web Page (CSS)

Do you want to indent the text that people see on the page, not the code? Use CSS. Do not use many &nbsp; characters, because they break on small screens.

/* Indent the first line of each paragraph */
p {
  text-indent: 2em;
}

/* Move a full block to the right */
.note {
  margin-left: 2rem;
}

Common Mistakes

  • You indent with spaces and tabs in one file. The code then looks different in each editor. Select one option in this tool and indent the full file again.
  • You add &nbsp; to indent text. Use text-indent or margin-left in CSS.
  • You edit minified HTML manually. Indent it first, edit it, and then minify it again if necessary.
  • You ignore an error. The tool does not guess where a missing tag goes. Correct the tag at the line that the error shows.

Explore More Free Developer Tools

Your HTML stays in your browser. The tool does not send your code to a server.

Paste your HTML above and get correctly indented code now.

Frequently Asked Questions
Paste the HTML in the box above. The tool puts each tag on its own line and moves each child tag one level in from its parent. Choose 2 spaces, 4 spaces or tabs. Then click Copy indented HTML.
All three are correct. Most style guides, including the Google HTML/CSS Style Guide, use 2 spaces because HTML nests deeply. Use the setting that your team or project already uses.
No. Browsers ignore indentation between tags. The tool keeps the spaces inside text, <pre> blocks and inline tags such as <span> and <a>, so the page shows the same.
The HTML has a structure problem, for example a closing tag without an opening tag. The error shows the line and column. Correct the tag at that position and the tool indents the code again.
Press Shift+Alt+F on Windows, Shift+Option+F on a Mac or Ctrl+Shift+I on Linux. To move selected lines in or out by one level, press Ctrl+] or Ctrl+[ (Cmd+] or Cmd+[ on a Mac).
Use CSS. For example, p { text-indent: 2em; } indents the first line of each paragraph, and margin-left moves the full block. Do not use many &nbsp; characters for layout.
No. The tool formats your code in your browser. Your HTML does not go to a server.