Code Beautifier & Minifier
Beautify or minify HTML, CSS and JavaScript and see how many bytes you save
Runs entirely in your browser. Nothing you type or upload is sent to us or stored.
Results are for general guidance. Please check anything important before relying on it. Terms of use
How to Use
- Choose the language: HTML, CSS or JavaScript. If the code you paste looks like a different language, the tool offers to switch.
- Paste your code into the left box, tap Open file to load a .html, .css or .js file (the language is picked from the file name), or tap Sample to try it.
- Pick Beautify to indent messy or one-line code (choose 2 spaces, 4 spaces or tabs), or Minify to make it as small as possible for your website.
- Check the Before, After and Saved sizes. If the code has a syntax error, the message shows the line and column; tap Show in input to jump there.
- Tap Copy or Download to save the result as a .html, .css or .js file.
Beautify vs minify
Beautifying (also called pretty-printing or formatting) adds line breaks and consistent indentation so that people can read the code. It is useful when you copy code from a website's "view source", receive a one-line file, or inherit a project with mixed tabs and spaces. Minifying does the opposite: it removes everything the browser doesn't need, such as comments, indentation and long local variable names, so the file downloads faster. Neither changes what the code does.
Smaller files matter in India, where many visitors browse on mobile data and mid-range phones. Every kilobyte saved in CSS and JavaScript helps the page appear sooner, which also feeds into Google's Core Web Vitals.
Worked example
This 134-byte JavaScript function:
function priceWithGst(amount, ratePercent) {
const gst = amount * ratePercent / 100;
return amount + gst;
}
minifies to 44 bytes, about a third of its size: the comment goes, spaces disappear, and the parameter names become single letters because nothing outside the function can see them. The function name stays, because other code may call it.
Terser even simplified the body by putting the calculation straight into the return.
How each language is minified
| Language | What is removed | What is always kept |
|---|---|---|
| JavaScript (Terser) | Comments, whitespace, dead code; local names shortened | Global names, exports, /*! โฆ */ and @license comments |
| CSS | Comments, whitespace, the last ; in each block | Strings, url(โฆ), /*! โฆ */ comments, spaces that matter (div :hover, and (, calc(a + b)) |
| HTML | Comments, repeated spaces and line breaks, spaces next to block tags | Contents of <pre>, <textarea>, <script> and <style>, attribute values, IE conditional comments, one space between inline elements |
The CSS and HTML minifiers are deliberately cautious. They don't rewrite colours, merge rules or remove attribute quotes, which saves a few more bytes in other tools but can break edge cases. In HTML, whitespace between block-level tags such as <div>, <p> and <li> is removed, as most minifiers do; if your CSS makes those elements inline-block, the small gaps between them will close up, so check the layout.
Tips
- Keep your readable source files in your project and minify only the copy you deploy. Build tools such as Vite, webpack and Next.js minify automatically; this tool is handy for one-off files, WordPress snippets, email templates and quick checks.
- Servers usually also compress files with gzip or Brotli. Minifying first still helps, because compression can't remove comments or shorten names.
- If minifying JavaScript reports an error, the original code has a syntax mistake; the line and column point to it.
- Your code never leaves your browser, so it is safe to paste private or client code.