1. All tools
  2. HTML, CSS & JS formatter

How do I format or minify HTML, CSS and JavaScript?

Choose HTML, CSS or JavaScript, paste your code and press Format to get clean, indented code, or press Minify to shrink HTML or CSS and see how many bytes you save. Formatting changes only whitespace and line breaks, and inline style and script blocks inside HTML are formatted too. JavaScript minifying is deliberately not offered, because doing it safely needs a real parser.

Runs entirely in your browser · nothing is sent · no account

  1. Pick the language and paste your code into the box.
  2. Press Format, or Minify for HTML and CSS, after setting the options you want.
  3. Check the size change, then copy the result or download it as a file.
Before
0 B
After
0 B
Size change
0%

What this page can do

  • Format HTML, CSS and JavaScript with 2 spaces, 4 spaces or tabs
  • Format inline style and script blocks inside an HTML page
  • Minify HTML and CSS conservatively, leaving pre, textarea, script and style content alone
  • Wrap long lines at 80 or 120 characters, and choose how many blank lines to keep
  • Show the size before and after, as bytes and as a percentage
  • Copy the result or download it as an .html, .css or .js file

When to use this page

  • Making a minified or generated snippet readable so you can debug it.
  • Tidying markup or styles before you paste them into a ticket, a pull request or a document.
  • Shrinking a small HTML email, widget or stylesheet by hand without setting up a build tool.

When to use something else

  • You need to minify JavaScript: use a build tool such as esbuild or Terser, which parse the code properly.
  • You want formatting on every save with your team style: use Prettier or your editor in the project.
  • You need advanced HTML minifying, such as removing optional tags or renaming classes: use a dedicated build step.

How it compares with other options

Editors and tools such as Prettier, VS Code and the browser developer tools format code too, and they are the better choice for daily work because they follow project rules. This page is quicker for a one-off paste. Formatting uses the open-source js-beautify library. The HTML and CSS minifiers are simple on purpose: they remove comments and whitespace that cannot change how the page looks, but they do not rewrite your code, so the savings are smaller than a full build tool can achieve.

Where your text goes

Nowhere. Formatting and minifying are done by your own browser when you press the button. Nothing is sent to a server, saved to an account or written to storage, and closing the tab clears it. You can check it yourself: open your browser’s network panel. The page still loads its own code and any ads, but no request carries your code.

Questions about this tool

Why can’t I minify JavaScript here?

Safe JavaScript minification needs a real parser. Simply removing whitespace and comments can break code that relies on automatic semicolon insertion, or that contains regular expressions and template strings, and a broken script is worse than a long one. Use the Format button to make JavaScript readable, and use a build tool such as esbuild or Terser to minify it.

Is the minified HTML guaranteed to render the same?

The minifier is deliberately conservative: it never changes the content of pre, textarea, script and style elements, keeps one space between inline elements, and keeps conditional comments. Even so, pages that depend on whitespace in unusual ways, for example with CSS white-space rules, can look different, so compare the result in a browser before you ship it.

Does formatting change what my code does?

Formatting only changes whitespace and line breaks, so JavaScript, CSS and HTML behave the same afterwards. The one exception in HTML is whitespace-sensitive content such as text next to inline tags, where an added line break can show as a space. If the code has a syntax error the formatter does not report it; it formats what it can.

What does the wrap line length option do?

It tells the formatter to break long lines of HTML or JavaScript after roughly 80 or 120 characters. Off keeps your lines as they are. Wrapping is a best effort: a single long word, URL or string is never split, and CSS is not wrapped.

Other tools you may need