Code Beautifier
About the Code Beautifier
This code beautifier re-indents minified or messy JavaScript, CSS, HTML, XML and JSON so you can actually read it. Only whitespace changes: every token, string and regular expression comes out exactly as it went in.
Beautifier vs formatter vs linter
A beautifier (or pretty printer) fixes layout: line breaks, indentation and spacing. It does not change names, reorder code or decide on quote style the way an opinionated formatter like Prettier does, and it does not look for bugs the way a linter like ESLint does.
That makes it the right tool for inspecting code you do not own, such as a minified bundle, a vendor stylesheet or an API response, where you want to read it without rewriting it.
How each language is beautified
JavaScript is tokenized first, so braces inside strings, template literals and regexes never affect indentation. Blocks, object literals and switch cases are indented one level per depth. CSS gets one declaration per line, with nested @media rules indented.
HTML and XML put each block element on its own line and indent children. Short elements that contain only text or inline tags, like <h1>Hello <em>world</em></h1>, stay on one line, and <pre> and <textarea> keep their original whitespace. Inline <script> and <style> blocks in HTML are beautified as JavaScript and CSS.
Invalid XML and JSON
JSON is parsed before it is printed, so a trailing comma or a single-quoted key is reported as an error rather than guessed at. XML is checked with the browser's own XML parser, and the parser's message, for example a mismatched closing tag, is shown instead of output.
How to Use the Code Beautifier
- Choose the language: JavaScript, CSS, HTML, XML or JSON.
- Select the indentation: 2 spaces, 4 spaces or Tabs.
- Paste code into the Input box, or click Load sample to try a minified example.
- Read the result in Beautified output, which updates as you type.
- Click Copy, or Download to save it as beautified.js (or .css, .html, .xml, .json).
Frequently Asked Questions
- Is my code sent to a server?
- No. Beautifying runs entirely in your browser, including the XML validation, so your code stays on your device.
- Can it restore the original variable names of minified code?
- No. Beautifying restores layout only. If a bundler renamed variables to a, b and c, they stay that way; you need the source map to recover original names.
- Does it support TypeScript or JSX?
- TypeScript and JSX are not separate options. Simple TypeScript often beautifies fine in JavaScript mode because only whitespace changes, but JSX tags are not specially handled.
- Why does my XML show an error?
- XML must be well formed: every tag closed, attributes quoted and exactly one root element. The message from the browser's parser points to the first problem.
- Will comments be kept?
- Yes. Comments are preserved in all languages that support them. JSON has no comments, so comment-like text in JSON causes a parse error.
- Is this the same as the Code Minifier in reverse?
- Roughly. Minifying removes whitespace and comments, beautifying adds whitespace back. Comments removed by minification cannot be recovered.