Code Formatter

Beautify JavaScript, TypeScript, HTML, XML, CSS, and JSON in one place.

Loading tool…

Code Formatter tidies JavaScript, TypeScript, HTML, XML, CSS, and JSON using the same beautifier library that previously backed four separate pages. XML is handled with entity decoding switched off, because in an Android manifest an ampersand entity and a CDATA block are data, not markup that should be rewritten. JSON is parsed and re-indented rather than pushed through the JavaScript formatter.

How to use

  1. Choose the language from the dropdown.
  2. Paste the unformatted code.
  3. Run it and copy the result.

Features and limitations

  • Six languages from one library, so a single dynamic import serves all of them.
  • JSON is parsed and re-indented instead of being forced through the JavaScript formatter.
  • A parse failure names the problem instead of printing an empty result.
  • Switching language swaps in a matching sample, so you can see the expected shape without typing one.
  • The text never leaves the browser.

Limitation: Formats text; it does not validate it. XML is processed as HTML, and TypeScript is formatted with the JavaScript formatter, which will not reorder types or strip syntax it does not recognise.

Frequently asked questions

Usage, result, and limitation information for this tool.

Why was XML handled by the HTML formatter?
Because the two share a tag structure and the alternative is shipping a second parser for one format. Entity decoding is switched off, so ampersands and CDATA in an Android manifest survive untouched.
Does it minify as well as it beautifies?
No. This formats. If you want the opposite, remove the line breaks and the indentation yourself, or use a dedicated minifier.
Why is TypeScript formatted with the JavaScript formatter?
Most TypeScript syntax is valid JavaScript syntax. Type-only constructs that are not will pass through unrecognised rather than breaking the output.
Is my code sent anywhere?
No. The formatter library is fetched on demand and the text stays in the page.

Found something broken?

Every tool is open about how it works, and a bug report is the fastest way to get a fix.

Report a bug