HTMLㆍCSSㆍJS Formatter
Beautify or minify HTML, CSS, and JavaScript code in your browser.
About HTMLㆍCSSㆍJS Formatter
Pretty-print compressed one-line code, or strip whitespace and comments to shrink files for production.
Beautify
Uses js-beautify to indent and line-break HTML/CSS/JS code per standard conventions.
Minify
JavaScript is safely compressed with Terser; HTML/CSS removes whitespace and comments. The savings ratio is shown.
Privacy
All processing is in the browser. Your code never leaves your device.
For JSON data in your code, try the JSON Formatter & Converter. To format SQL queries, use the SQL Formatter. For encoding strings or files, see the Base64 Encoder/Decoder.
Common HTML, CSS, and JS Formatting Pitfalls
Knowing what a formatter handles automatically versus what you need to manage yourself goes a long way toward cleaner code reviews and fewer merge conflicts.
Indentation issues developers run into
- Mixing tabs and spaces - When both appear in the same file, indentation width varies by editor settings. Enforce a project-wide choice with
.editorconfig. - Mixing 2-space and 4-space indentation - JavaScript communities tend to prefer 2 spaces; Python uses 4. Consistency within a project matters most.
- Deeply nested code - Four or more indentation levels is usually a signal to refactor. Extract functions or use early returns to flatten the structure.
JavaScript details that trip developers up
- Relying on ASI (Automatic Semicolon Insertion) - A value on the line after
returncauses ASI to insert a semicolon, returningundefined. Explicit semicolons are safer. - Mixing single and double quotes - Both work, but mixing them in one file hurts readability. Pick one and stick with it.
- Trailing commas - A trailing comma after the last item in an object, array, or function parameter list means diffs show only the added line. Allowed in ES2017+ function arguments.
- Debugging minified code - Without source maps, stack traces from production bundles are meaningless. Always ship source maps alongside minified output.
HTML mistakes worth catching early
- Self-closing void elements - In HTML5,
<br>is the standard.<br />is valid but mixing XHTML syntax is unnecessary. - Inline styles -
style="..."attributes are not cacheable and cannot be reused. Move styles to CSS classes. - Unquoted attribute values - Values containing spaces or special characters will cause parse errors without quotes. Quote all attribute values for consistency.
- Duplicate IDs -
idmust be unique per document.document.getElementByIdreturns only the first match, which leads to confusing bugs.
CSS habits that cause problems later
- Inconsistent property order - The conventional order is: positioning, box model, typography, visual effects. Random ordering hurts readability at a glance.
- Overusing !important - Once used, it tends to spread as developers fight it with more
!important. Redesigning selector specificity is the real fix. - Stale vendor prefixes -
-webkit-and-moz-prefixes are mostly unnecessary today. Use autoprefixer to handle them automatically. - Magic numbers - Values like
margin: 17pxwith no clear rationale make maintenance harder. Align to a spacing scale (4, 8, 16 px, etc.).
FAQ
Does minified code still work the same?
Terser preserves JavaScript semantics while shortening variable names. For large projects, prefer your build pipeline.
Does it support JSX or TypeScript?
Only standard ES2020 JavaScript, HTML, and CSS. JSX/TSX/TypeScript require a transpiler.
How is this different from Prettier?
Prettier re-parses and reprints code with its own AST, while this tool uses js-beautify for lightweight in-browser formatting. Use Prettier for projects; use this tool for quick ad-hoc formatting.