YourTools.
简体中文
Back to the catalog
Tools

Code formatter

Format or minify HTML, CSS, SCSS, Less, JavaScript, TypeScript, JSON, Markdown, YAML, XML, SQL, C, C++, C#, Java, PHP, Python and nginx configuration.

Process locally

Files stay in this browser session. Closing or clearing releases them.

Add text

Type or paste the text to process

Adjust settings

Optional: Language, Action, Indent and more

Code formatter

Run

Processes in this browser; cancel at any time

Add text first

About this tool

Format or minify source code. Paste a minified script to make it readable again, tidy up a messy SQL query before a code review, or shrink HTML, CSS or JavaScript before putting it on a page. Supported languages are HTML, CSS, SCSS, Less, JavaScript, TypeScript, JSON, Markdown, YAML, XML, SQL, C, C++, C#, Java, PHP, Python and nginx configuration.

Formatting uses Prettier for the web languages and PHP, sql-formatter with 13 SQL dialects, clang-format for C, C++, C# and Java, and Ruff for Python. Minifying is available for HTML, CSS, JavaScript, JSON and XML. Up to 2 MB of code is processed right in your browser, and nothing is uploaded.

How to use it

  1. Type or paste your code, or select “Use example” to load a one-line JavaScript snippet.
  2. Choose the “Language” and the “Action”: “Format” or “Minify (HTML, CSS, JavaScript, JSON, XML)”.
  3. Set the “Indent” and “Line width” if you need to. For SQL, pick the “SQL dialect” and the case of “SQL keywords”; for C, C++, C# and Java, pick a “C, C++, C# and Java style”.
  4. Select “Run”. If the code cannot be parsed, the parser’s error message is shown instead.
  5. Preview the result and download it. The file keeps the language’s extension, such as formatted.js or minified.css.

Formats and limits

Input
Text
Output
Text
Size limit
2 MB
Settings
Language; Action (Format, Minify); Indent (Language convention, 2 spaces, 4 spaces, Tab); Line width; C, C++, C# and Java style (Google, LLVM, Chromium, Mozilla, WebKit, Microsoft, GNU); SQL dialect; SQL keywords (As written, UPPER CASE, lower case)
Privacy
Files stay in the current browser session. No file bytes are uploaded.
Price
Free, no sign-up

Common questions

Which languages can be minified?

Only HTML, CSS, JavaScript, JSON and XML; choosing minify for any other language stops with an error. JavaScript is compressed with terser, which also shortens variable names, and CSS with csso. HTML loses its comments and the whitespace between blocks and has its inline CSS and scripts minified, while XML loses comments and whitespace between tags.

What does the “Language convention” indent use?

Python, Java, C# and PHP get 4 spaces, and every other language gets 2. Choose “2 spaces”, “4 spaces” or “Tab” to override it.

What line width is used when it is set to 0?

80 characters for the languages Prettier formats, 88 for Python, and the chosen style’s own limit for C, C++, C# and Java. For SQL, a width above 0 limits how long an expression may stay on one line, up to 120. XML and nginx configuration ignore the line width.

Why did my JavaScript get double quotes and semicolons?

JavaScript and TypeScript are printed in Prettier’s default style, which prefers double quotes and ends statements with semicolons. Only the indent and line width can be changed here.

Are comments kept in XML and nginx configuration?

Yes, when formatting. XML comments, CDATA sections and processing instructions stay as written, and an element holding only text stays on one line; nginx configuration keeps its comments and quoting, with one directive per line. Minifying XML removes the comments.