Code

HTML formatter: set readable spacing and review the changes

·

An HTML formatter turns compact markup into source that is easier to inspect. ToolMellow uses Prettier’s HTML parser with controls for indentation, preferred line width and one attribute per line. Paste a fragment or import a local text file, then run Format HTML to create a separate Result.

Review the result before putting it into a page or template. Formatting can change quotes, tag layout and closing markup; it does not sanitize HTML, prove that a document is valid or show how a browser will render it. The workflow below explains what each setting changes and how to keep the full output.

HTML formatter

Format the whole input, then inspect the result

Start with the built-in sample if you want to compare settings on a small piece of markup. For your own source, paste into Input or choose a local file. Format HTML always processes the whole Input: highlighting a selection does not restrict the operation.

Successful formatting leaves Input unchanged and puts the formatted text in the read-only Result. Editing Input or changing a formatting option invalidates the old Result; run Format HTML again to produce a new one. This helps you avoid copying output that belongs to an earlier version.

  • Keep a copy of the original source before editing or replacing it.
  • Choose two or four spaces for indentation.
  • Set the preferred line width between 40 and 200.
  • Enable one attribute per line when you want multi-attribute tags spread out.
  • Run Format HTML and inspect the changed markup and any reported errors.
  • Copy or download the complete Result, or reuse it as Input if it fits the input limit.

Which settings are adjustable?

The visible controls cover a small set of Prettier options. Whitespace sensitivity and embedded-language formatting are fixed choices here, so there is no extra switch to enable either a different whitespace mode or formatting inside script and style bodies.

A layout preference can produce different results depending on the surrounding markup. A long value may exceed the chosen width, and a tag with only one attribute may remain on one line even when the attribute option is enabled.

Which settings are adjustable?
SettingValue hereWhat it means
ParserhtmlFormats the whole input as HTML source.
Indentation2 or 4 spacesSets the indentation width.
Preferred line width40–200; default 80Guides line breaking without imposing a hard maximum.
One attribute per lineOptionalRequests separate attribute lines on applicable multi-attribute tags.
Whitespace sensitivitystrictTreats whitespace around tags as significant when printing.
Embedded-language formattingoffSkips a separate JavaScript or CSS formatting pass inside HTML.
Wrap linesDisplay optionChanges textarea wrapping without rewriting the source.
ResultRead-onlyReceives output only after a successful new formatting run.

Prettier formatting optionsWHATWG HTML: syntax and elements

Choose two or four spaces for nesting

Two spaces keep deeply nested markup relatively compact. Four spaces make each nesting level more prominent. Choose the convention used by the surrounding project so that pasting a formatted fragment does not introduce an unnecessary style change.

Indentation is a formatting preference, not a repair for a missing element or a broken attribute. Under strict whitespace handling, some inline content stays together and some closing angle brackets move onto another line. Those layouts are not evidence that the indentation control has stopped working.

Treat line width as a preference

The line-width control accepts values from 40 to 200 and starts at 80. Smaller values encourage shorter lines; larger values allow more markup to stay together. Prettier’s print width is a target for readable layout, not a rule that every output line must obey.

A 250-character attribute value, for example, can still produce a line longer than a width of 40. The formatter does not split that value simply to meet a column count. Inspect long URLs, template expressions and other indivisible text in the result.

Treat line width as a preference
SituationUseful choiceExpected tradeoff
Narrow review windowTry 40More line breaks where the printer can safely introduce them.
General editingStart at 80A moderate preferred width.
Wide editorTry 120More tags and attributes may remain together.
Very wide source viewUp to 200Fewer width-driven breaks, depending on the markup.
Long attribute valueAny supported widthThe value may exceed the preference.
One attribute per line enabledCombine with your preferred widthAttribute layout also affects the result.

Prettier formatting options

Put attributes on separate lines when useful

Enable one attribute per line to make applicable tags with several attributes easier to scan. This is useful when reviewing names, accessibility attributes or long data attributes. It is an attribute-layout preference, not a rule that every opening tag must become a block.

A single-attribute input such as <img src="x"> can still format to <img src="x" /> on one line. Special constructs can also follow their own printer rules. Check the actual result before adopting the layout throughout a template.

Prettier formatting options

Why some tags and brackets break in unusual places

This formatter fixes HTML whitespace sensitivity to strict. Whitespace next to inline tags can affect text, so the printer may keep content such as <p>Hello <strong>world</strong>!</p> together. In other layouts, a closing angle bracket may sit on a different line from the tag name.

Strict handling does not promise byte-for-byte preservation of whitespace or identical rendered behavior for every input. In particular, formatting can alter the layout around pre and textarea content. Review whitespace-sensitive text and test the page or template in its intended environment.

Prettier formatting options

JavaScript and CSS inside HTML stay out of a separate format pass

Embedded-language formatting is fixed to off. A script body such as const x={a:1,b:2}; or a style body such as .x{color:red;padding:0} does not receive a separate JavaScript or CSS beautification pass. There is no visible control to turn that pass on.

The HTML printer can still move surrounding tags, indentation and line breaks, including layout around those bodies. Skipping the embedded formatter therefore does not mean the whole script or style region remains byte-identical. Review embedded code and template delimiters before replacing the original.

Prettier: embedded language formatting

Review more than added indentation

An HTML beautifier parses and prints markup; it can make changes beyond spaces at the beginning of lines. The examples below describe observed output for specific inputs, not a promise that every malformed document will be accepted or repaired in the same way.

Compare source changes deliberately when working with generated markup, HTML email or a template language. Formatting is not a substitute for the project’s tests or for checking the result in the browser and template engine that will use it.

Review more than added indentation
Input featureObserved changeWhat to check
Unquoted or single-quoted attributesAttribute quotes can become double quotes.Review quoting and template expressions.
Void element such as <input disabled>Output can include a closing slash.Check the syntax expected by your consuming system.
Missing closing tag in <div>helloOutput can include </div>.An accepted parse is not a full validity check.
CRLF line endingsFormatted output uses LF.Review line-ending changes in your diff.
Inline text and tagsContent can stay on the same line.Avoid adding spaces that would change the text.

WHATWG HTML: syntax and elements

Read parser errors without treating success as validation

When the parser rejects source, the workspace shows a localized error summary and the engine’s original detail, which can include a line and column. Use that position to inspect the nearby source; the cause may begin before the reported location. Correct Input and run Format HTML again.

The parser may also accept markup with omitted or missing closing tags and print inferred closing markup. Success therefore does not certify HTML conformance, accessibility, safe content or correct template behavior. There is no dedicated validation report or rendered preview in this tool.

WHATWG HTML: syntax and elements

Understand input, file and history limits

The text limit is measured in UTF-16 code units, which differ from file bytes and from visible characters. A basic Latin letter uses one unit; a supplementary character such as 🌿 uses two, and a displayed emoji sequence can contain several code points. A local file must pass both the byte check and the decoded-text check.

Formatting may expand output beyond the input limit. The complete result remains available for copying and downloading, but Use result as input refuses an oversized result and preserves the existing Input and Result. The table separates those limits from search and history bounds.

Understand input, file and history limits
ItemLimitBoundary behavior
Pasted or processed Input1,000,000 UTF-16 code unitsExactly the limit is allowed; larger text is refused.
Local fileStrictly less than 4,000,000 bytesA file exactly at that byte count is refused before reading.
Decoded file text1,000,000 UTF-16 code unitsMust also fit after UTF-8 decoding.
Use result as input1,000,000 UTF-16 code unitsOversized output is not inserted; the full Result remains exportable.
Find text1,000 UTF-16 code unitsLiteral input search is bounded.
Replacement text10,000 UTF-16 code unitsAn edit that would exceed the input limit is refused.
Undo and redo historyUp to 20 older snapshotsTracks accepted Input changes, not separate formatted results.
Combined history text4,000,000 UTF-16 code unitsExcludes current Input; older stored states are bounded.

Import local HTML as UTF-8 text

Choose a local HTML or text file to load source into Input. The workspace checks file size before reading, uses the file’s text-reading method to decode UTF-8, then checks decoded length. There is no encoding selector; changing a filename or MIME type does not select a different decoding scheme.

This is a text-file import workflow. It does not fetch a page from a URL, extract HTML from a PDF or Word document, or open linked scripts, styles and images. If the imported text is garbled because it uses another encoding, convert it to UTF-8 in a suitable editor before importing.

W3C File API: Blob text decoding

Copy or download the complete HTML result

Copy and Download use the entire Result rather than the current selection or only the portion visible in the editor. Download creates a UTF-8 text file named toolmellow-result.html. The file contains formatted source, not a screenshot or an archive of page dependencies.

Keep the exported source with the assets and build steps it needs. The downloaded file does not include external stylesheets, images or scripts. Review and test the markup before publishing it, especially if the original came from an untrusted source.

Reuse output only when it fits

Use result as input replaces Input with a successful result that fits the text limit, allowing another editing pass. Producing Result alone does not rewrite Input. If you need the original, save it before reuse or use available Input history after the accepted replacement.

For an exact-limit input of one million plain letters, adding a final line break can produce 1,000,001 output units. That output can still be copied or downloaded in full, while reuse is refused. A refusal to reuse does not mean the result has been truncated.

Find, wrapping, history and Clear affect different things

Find and replace operates on literal text in Input, with an optional case-sensitive mode. It does not use regular expressions or understand HTML nodes and attributes. Replacement text such as $& is inserted literally; review matches before changing repeated markup. Accepted edits invalidate the previous Result.

Wrap lines changes only how the Input and Result textareas display long lines. It does not insert line breaks into copied or downloaded source. HTML code stays left-to-right even when the surrounding interface is in a right-to-left language.

Undo and redo track accepted Input edits, imports, replacements and result reuse within the bounded history. They do not undo the act of producing a separate Result. Clear empties Input, Result, history and search state while retaining formatter settings and the wrapping preference; Clear cannot be undone.

Local formatting still depends on loading the engine

Formatting runs in a browser worker. Input and output are text, not HTML mounted as a live page, so the workflow does not run pasted scripts or load pasted image URLs. That isolation does not sanitize the source for later use. The worker and formatter assets may require network access when loading; local processing alone does not guarantee offline availability.

If the engine cannot load, keep Input and try the action again after connectivity is restored. Cancel can stop a pending job while preserving Input. There is a configured 60-second startup-and-processing limit, but actual completion time depends on the browser and source. Cancelled or outdated work must not be treated as a fresh Result.

Prettier: running in the browser

Common questions

Does formatting HTML sanitize it?

No. The formatter prints source as text and does not execute it in the workspace, but it does not remove dangerous content or make the result safe to publish. Use appropriate sanitization and security controls where that source will be consumed.

Is the preferred line width a hard limit?

No. The supported preference is 40–200, with a default of 80. Long attribute values and other unbreakable content can exceed the chosen width.

Can this formatter fix invalid HTML?

It can print inferred closing markup for some accepted input, while other input produces a parser error. It is not a general repair tool or an HTML conformance validator; review the result and test it in the intended environment.

Why do inline HTML tags stay together?

Whitespace sensitivity is fixed to strict. The printer takes whitespace around tags seriously and can keep inline text together or move a closing angle bracket to another line. Review whitespace-sensitive content rather than assuming every tag should occupy its own line.

Will JavaScript and CSS inside HTML be reformatted?

A separate embedded JavaScript or CSS formatting pass is disabled and there is no toggle to enable it. HTML printing can still change surrounding indentation and line layout, so embedded regions are not guaranteed to remain byte-identical.

How much HTML can I paste or import?

Input may contain at most 1,000,000 UTF-16 code units. A local file must be strictly smaller than 4,000,000 bytes and its UTF-8-decoded text must also fit the input limit. File bytes, code units and visible characters are different measurements.

Can I format only the selected HTML?

No. Format HTML processes the entire Input. A selection does not narrow the formatting scope; copy the desired fragment into a separate input if you want to format that fragment on its own.

Can I undo formatting or Clear?

Formatting creates a separate Result and leaves Input unchanged. Undo and redo apply to accepted Input changes within the available history. Clear erases Input, Result, search and history, so it cannot be undone.

Does this HTML formatter show a live preview?

No. Input and Result are source editors. The tool does not render the pasted markup as a page, fetch its linked assets or show a live browser preview.

Why can a tag stay on one line with the attribute option enabled?

One attribute per line applies to applicable multi-attribute layouts. A tag with a single attribute can stay on one line, and special constructs can follow their own printer rules.

Does Wrap lines change the downloaded HTML?

No. Wrapping is a textarea display preference. The download contains the complete formatted Result with its actual source line breaks, regardless of the visible wrapping.

Can I import a URL, PDF or Word document?

The formatter accepts local text-file content. It does not retrieve HTML from a URL or extract document content from PDF or Word files.

Why is a result downloadable but too large to reuse?

Formatting can expand text beyond the input limit. Full-result Copy and Download remain available, but inserting that output back into Input would exceed its 1,000,000-unit limit and is refused without discarding the result.

Can this tool minify HTML?

There is no HTML Minify action here. Format HTML prints readable source using its formatting settings; it does not offer a compression mode or a guarantee of smaller output.

Primary references

Put it into practice.

Related guides