Format and Minify HTML, CSS, and JavaScript
Format HTML, CSS, or JavaScript, or make a compact version; strings, regexes, comments, and script or pre content stay unchanged.
Use this tool in your browser without installing software.
About this tool
This page reads each of the three languages on its own terms. In HTML every block tag starts a line, inline tags such as b, span and a stay with their text, and the content of pre, textarea, script, style and title is placed back exactly as it was, so the spacing a browser shows does not change. In CSS each declaration gets its own line, nested at-rules such as media and supports are indented, and strings, url() and comments stay as written. In JavaScript a tokenizer reads the code in order, braces open blocks, and any line break whose removal could change meaning — a return whose value sits on the next line, a ++ that would attach to it — is kept. With Minify checked only spacing that carries no meaning is removed: comments stay, because deleting them would change the text, and a // comment keeps a line break after it so the rest of the code does not fall inside it. Nothing is executed and nothing is sent anywhere. One limit is worth knowing: this tool lays text out, it does not compile it. TypeScript and JSX usually read fine, but a structure outside standard JavaScript can produce an error.
How to use it
- 1
Paste the text into the input box, or pick a file with Open. If the file ends in html, css or js, the language switches on its own. The result appears as you type.
- 2
Choose the language in the top bar and set the indentation to 2 or 4 spaces. Minify removes unnecessary whitespace while keeping breaks that preserve the code’s meaning.
- 3
Copy the result or download it under a fitting file name. If there is a structural problem, the line, the column and that source line with a ^ marker appear under the boxes.
If the file will not open
- It says the content of script or pre is not closed.
The end tag for that section is missing. Usually </script> or </pre> was left out, or the same section opened a second time inside the text. The tool never touches raw content, so it gives no output until that is fixed.
- A string or template is not closed.
A quote or backtick was left open. If a JavaScript string spans lines, use a backtick or join the lines with \. The line and column point exactly at where the string began.
- A parenthesis or brace has no pair.
One of the parentheses, brackets or braces was never closed. The line number points at the opener. The same check runs for JSX and TypeScript, so it may be a sign of an unfinished structure rather than a typo.
- The minified output still has several lines.
That is expected. After a // comment, and on lines whose break is needed for meaning, the break stays. Minifying here means “the fewest safe spaces”, not a guaranteed single line.
Frequently asked questions
Does the tool change my code?
No, only spacing and line breaks move. Tag text, attribute values, strings, templates, regexes and comments stay byte for byte the same. If any text changed, that is a bug, not a feature.
Why are some HTML tags stuck together?
Because text or an inline tag sat between them and a line break would add a new space to the text. A browser shows that space, so the tool deliberately keeps that part on one line. A block tag always gets its own line.
Why are comments kept when I minify?
Because this tool is meant to change spacing only. Deleting a comment changes the text and can remove a note the next reader needs. If you do not want comments, remove them before minifying.
Why did a JavaScript line not get joined?
Because joining it could change meaning. In a return whose value sits on the next line, or when ++ starts the following line, removing the break would break the code; the tool leaves those lines alone.
Does it format TypeScript and JSX too?
Most of the time, yes, because it recognises their tokens. But this is a text formatter, not a compiler. A structure outside standard JavaScript can stop it with an error. For sensitive code, give the output a quick read.
Will Persian text or emoji be damaged?
No. Text is moved without normalisation and without changing any character; only spacing outside strings and comments changes. If the file was not saved as UTF-8, a warning says so.