HTML, CSS & JS Beautifier and Minifier · CodePress

Beautify and minify HTML, CSS and JavaScript with configurable rules.

Updated:

100% client-side

Input code

0 characters

Result


        
—

What the HTML, CSS & JS beautifier and minifier does

CodePress cleans up HTML, CSS and JavaScript code in two opposite directions: "Beautify" takes messy or compressed code and re-indents it with consistent spacing and line breaks so it's readable, while "Minify" strips out whitespace, comments and line breaks to make the file as small as possible for production. It's meant for whenever code you're given (or wrote in a hurry) doesn't match the formatting you need.

How to use the HTML, CSS & JS beautifier and minifier

  1. Paste your code into the Input code panel (or click Example), and pick its language — HTML, CSS or JavaScript.
  2. Choose Beautify or Minify, and an indentation width if beautifying.
  3. Read the formatted code in the Result panel.
  4. Click Copy or Download to save it.

How CodePress works

CodePress tokenizes the code respecting strings, comments and (in JS) template literals and regex, then applies indentation rules based on brace/parenthesis depth for "Beautify," or strips whitespace, comments and unnecessary line breaks for "Minify":

/* Before */
.card{color:red;padding:8px}

/* After Beautify */
.card {
  color: red;
  padding: 8px;
}

JavaScript's compact mode is deliberately conservative (it never merges lines) to avoid ASI bugs; HTML and CSS are compacted aggressively. Everything runs in your browser — no external libraries, no server calls.

Examples

1. Beautify one-line CSS. Each rule and declaration gets its own line, and rules inside @media are indented one more level:

/* Input */
.btn{padding:8px 16px;border-radius:6px}.btn:hover,.btn:focus{background:#1d5dea;color:#fff}@media (max-width:600px){.btn{width:100%}}

/* Output (2 sp.) */
.btn {
  padding: 8px 16px;
  border-radius: 6px;
}
.btn:hover,.btn:focus {
  background: #1d5dea;
  color: #fff;
}
@media (max-width:600px) {
  .btn {
    width: 100%;
  }
}

2. Minify CSS. Comments, indentation and line breaks go; the result is 69% of the original size:

/* Input */
/* Buttons */
.btn {
  padding: 8px 16px;
  border-radius: 6px;
}

.btn:hover {
  background: #1d5dea;
}

/* Output (Minify, 72 characters) */
.btn{padding:8px 16px;border-radius:6px;}.btn:hover{background:#1d5dea;}

3. Minify JavaScript, conservatively. Comments and indentation are removed but line breaks are kept, so code that relies on automatic semicolon insertion keeps working. Here the output is 65% of the original:

// Input
// Sum the prices of items in stock
function total(items) {
  let sum = 0;
  for (const item of items) {
    if (item.stock > 0) {
      sum += item.price; // add it
    }
  }
  return sum;
}

// Output (Minify)
function total(items) {
let sum = 0;
for (const item of items) {
if (item.stock > 0) {
sum += item.price;
}
}
return sum;
}

Common problems when beautifying or minifying

  • Expecting production-grade JavaScript minification. The Minify mode doesn't rename variables, drop dead code or join lines, so it saves far less than a real minifier. For a production bundle use esbuild or Terser (see below); use this mode to strip comments before pasting a snippet somewhere.
  • Extra spaces in beautified HTML. Beautify puts every element on its own line, inline ones too: <p>Some <strong>bold</strong> text.</p> becomes seven lines. Browsers render line breaks between inline elements as spaces, which can add a gap next to a link or before punctuation. Beautify to read and debug the markup; don't ship the beautified version where spacing matters.
  • Wrong language selected. CSS run through the JavaScript mode, or HTML with embedded <script> run as CSS, produces odd indentation. Pick the language that matches the code you pasted.
  • Selectors that stay on one line. In CSS, a selector list like .btn:hover,.btn:focus is kept on one line as written (example 1). If your team requires one selector per line, enforce it with a linter such as Stylelint.
  • Broken code in, broken code out. The tool formats; it doesn't validate. An unclosed brace shifts the indentation of everything after it, which is a useful hint about where to look.

Beautifier vs. Prettier, esbuild and Terser

In a project, formatting belongs in your editor and CI: npx prettier --write "src/**/*.{html,css,js}" formats HTML, CSS and JavaScript with one consistent style. For production, npx esbuild app.js --minify --outfile=app.min.js or npx terser app.js -c -m -o app.min.js minify JavaScript properly, renaming variables and removing whitespace safely. This page is for code outside a project: a minified file from a CDN you want to read, a snippet from a ticket, CSS copied from DevTools. For SQL, use the SQL Formatter; for JSON, the JSON Formatter, which also validates.

Frequently asked questions

Does it use a full parser for each language?

No. It uses a tokenizer and indentation rules based on brace/parenthesis depth, similar to most lightweight online formatters — not a full compiler. Code with very unusual syntax may need manual tweaks.

Is the JavaScript compact mode as aggressive as a production minifier?

Deliberately not: it only strips comments, blank lines and indentation, but keeps the original line breaks between statements to avoid bugs from automatic semicolon insertion (ASI) that an aggressive minifier without a full parser could introduce.

Is HTML and CSS compacting just as conservative?

No, those are minified more aggressively (collapsing whitespace and stripping comments) because HTML and CSS don't have JavaScript's ASI problem — it's safe to compact them fully.

Is it safe to paste proprietary code here?

Yes. All processing happens in your browser; no code is ever sent to a server.