Your HTML
Formatted
Formats as you type. Press Ctrl + Enter (or ⌘ + Enter) to format on demand. Need to find errors instead? Try the HTML Validator →

How to format HTML

  1. Add your code. Paste HTML into the left panel, upload an .html file, or press Sample.
  2. Pick your style. Choose 2 spaces, 4 spaces or tabs, and decide whether long lines should wrap.
  3. Format it. The right panel updates as you type. You can also press Format HTML or Ctrl + Enter.
  4. Use the result. Copy it, download it as a file, or open it in the full editor with live preview to keep working on it.

What the formatter changes (and what it leaves alone)

The goal is code that’s easier to read but works exactly the same. So the formatter only touches whitespace and line breaks, and it stays away from anything where whitespace matters.

RewrittenKept exactly as written
Indentation, so every nested element sits one level deeper than its parentTag names, attribute names, values and quote marks
Line breaks, so block elements like <div>, <p> and <li> each start on their own lineEverything inside <pre> and <textarea>, character for character
Runs of spaces and line breaks inside text, collapsed to a single space (browsers already show them as one)Text-level tags like <a>, <strong> and <span>, which stay on the same line as the words around them
CSS inside <style> tags: one rule and one declaration per line (optional)JavaScript inside <script> tags. It’s re-indented to line up with your HTML but never rewritten
<br/> written as <br />Missing end tags. If your source leaves out </li> or </p>, the output does too

Formatting options

OptionWhat it does
IndentHow far each nesting level is pushed in. Two spaces is the most common choice for HTML. Tabs let everyone on a team set their own width in their code editor.
Wrap linesOff keeps each run of text on one line. At 80 or At 120 breaks long text and inline tags at word boundaries, so you don’t have to scroll sideways.
Indent head & bodyWhen on, <head> and <body> are indented one level inside <html>. Turn it off for flatter output, a style many large projects prefer.
Format CSSPuts each CSS rule and declaration inside <style> tags on its own line, adds a space after colons and fills in a missing final semicolon.
Keep blank linesKeeps one empty line wherever your source had blank lines between blocks, so the groupings you made on purpose survive.

Why format your HTML?

Readable markup is faster to fix. When every nested element sits one level deeper than its parent, a missing closing tag or a <div> in the wrong place stands out at a glance instead of hiding in a 400-character line.

It also keeps code reviews and version control clean. If everyone on a project formats the same way, diffs show real changes instead of whitespace noise. And when you copy code from a minified page, a CMS export or an email template, formatting it is usually the first step to figuring out what it does.

Formatting doesn’t check whether your HTML is correct. It will happily indent a page full of unclosed tags. To find actual mistakes, paste the same code into the HTML Validator, which flags unclosed tags, nesting problems, duplicate IDs, missing alt text and more.

Related tools and references

Frequently asked questions

Is this HTML formatter free?
Yes. There's no sign-up, no daily limit and no watermark on the output. The only size limit is what your browser can handle, which is several megabytes of HTML on any modern computer.
Is my code uploaded anywhere?
No. Formatting happens in your browser with JavaScript. Nothing you paste is sent to a server or stored, so it's safe to use with private or client code.
What's the difference between formatting, beautifying and prettifying HTML?
There isn't one. All three mean re-indenting code so it's easy to read. The opposite is minifying, which strips out whitespace to make files smaller and faster to download.
Can formatting break my page?
Almost never. Browsers already treat several spaces and line breaks in text as one space, so the formatter's whitespace changes don't show on screen. The two exceptions are elements styled with CSS white-space: pre (other than <pre>, which is left alone) and the gaps between inline-block elements, which can shift by a few pixels when line breaks are added or removed.
Does it format JavaScript too?
It re-indents the code inside <script> tags so it lines up with the surrounding HTML, but it doesn't rewrite the JavaScript itself. CSS inside <style> tags gets fully formatted when the Format CSS option is on.