HTML Formatter
Paste HTML that is minified, copied from a page source or edited into a mess, and get it back with every element on its own line and indentation that follows the nesting. The tool reads the markup the way a browser does: text that flows between inline tags such as links and bold stays together, the contents of pre, textarea, script and style are not reflowed, and nothing is added or removed, so the page looks the same afterwards.
What you enter
- HTML
- Indent
- Wrap long text at
What you get
- Lines
- Characters
How it works
- Paste your HTML into the box. A full page or just a fragment both work, and nothing is uploaded.
- Choose the indent size: 2 spaces, 4 spaces or a tab. Choose where long text lines should wrap, or turn wrapping off.
- Read the formatted markup in the result. Block elements such as div, section, ul and table start on their own lines, and inline elements stay with their text.
- Copy the result or download it as an .html file.
How whitespace works in HTML
Browsers treat any run of spaces, tabs and line breaks between words as a single space, so for most elements you can reformat the whitespace freely. The exceptions are the pre element and textarea, where whitespace is part of the content, and the gaps between inline elements, where a collapsed space is still a space.
That is why an HTML formatter has to know which elements are block level and which are inline. Between two blocks, whitespace is ignored and the formatter can put a line break anywhere. Between two inline pieces, the formatter may only break where the original already had whitespace, because a break where there was none adds a space.
Reading messy markup
When a page is minified, a missing closing tag is hard to spot because everything runs together. After formatting, a missing end tag shows up as indentation that never comes back out: the lines after it are all one level deeper than they should be. Scroll to where the indentation stops matching the structure you expect and look at the tag just above.
Pages built by tools often contain deep wrappers, empty containers and inline styles. A formatted view makes those visible, which is the first step in tidying them. When you take over a template or a page exported from a site builder, formatting it first makes the rest of the clean-up quicker.
Tips
- Inline elements such as a, span, strong and img are kept on the same line as the text around them. Putting them on separate lines would add a visible space between words, which would change how the page looks.
- Pre blocks and textareas are copied exactly as written, because spaces and line breaks are part of their content.
- If a tag is never closed in your source, the tool leaves it unclosed. It does not guess where the end should be, so fix those by hand.
- Attribute values are never altered. Extra spaces and line breaks between attributes are tidied, but anything inside quotes stays exactly as it is.
- Formatting does not validate the page. Use it to read the structure and spot a missing closing tag, then check the result in a validator if you need to be sure.
Frequently asked questions
What does an HTML formatter do?
It rewrites the whitespace in your markup so the structure is visible: each block element on its own line, children indented one step deeper than their parent and long lines of text wrapped. The elements, attributes and text stay the same.
Why are some tags kept on one line with the text?
In HTML, a space or line break between two inline pieces is rendered as a visible space. In the markup Hello <b>world</b>!, there is no space between the closing b tag and the exclamation mark, so the formatter keeps them together instead of moving the exclamation mark to a new line.
Is the content of script and style tags changed?
The code inside is not reflowed or rewritten. Short ones stay on one line. Longer style blocks, and script blocks without backtick template strings, are re-indented to fit the new nesting depth. Scripts containing backticks are copied exactly, because indenting could change the text of a multi-line template.
What happens with unclosed or mismatched tags?
The tool follows the common browser rules for optional end tags, such as a new li closing the previous li. A closing tag with no matching opening tag is kept on its own line, and a tag that is never closed is printed without a closing tag.
Does it change my attributes or add quotes?
No. It collapses extra whitespace between attributes to a single space, but it keeps attribute order, the quote style and the exact value of every attribute.
Related: HTML table generator, Text to HTML converter, Meta tag generator.
Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.
More in Free Tools
- HTML Link Generator
- HTML Minifier
- HTML Page Generator
- Accessible HTML Table Generator
- HTML to JSX Converter
- HTML to Markdown Converter
- HTML to Text Converter
- HTML Checker
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App