Skip to content

Code Formatter

Paste any code and get clean indentation, with the language detected automatically.

Indent
Options

Formatter for a specific language

Runs in your browser — your data is not uploaded.

How to use

  1. Paste your code into the Code box.
  2. Set Language to Auto-detect or select your code’s language.
  3. Choose 2 spaces, 4 spaces or Tab under Indent.
  4. Click Format code.
  5. Click Copy to copy the result from Formatted code.

Examples

Expand minified JavaScript

Input
function greet(n){const t=new Date().getHours();if(t<12){return "Good morning, "+n}return "Hello, "+n}console.log(greet("Ann"));
Output
function greet(n) {
  const t = new Date().getHours();
  if (t < 12) {
    return "Good morning, " + n
  }
  return "Hello, " + n
}
console.log(greet("Ann"));

Format responsive CSS without blank lines

Input
.card{padding:16px;border-radius:12px}.card h2{margin:0 0 8px;font-size:20px}@media (max-width:600px){.card{padding:12px}}
Output
.card {
    padding: 16px;
    border-radius: 12px
}
.card h2 {
    margin: 0 0 8px;
    font-size: 20px
}
@media (max-width:600px) {
    .card {
        padding: 12px
    }
}

Pretty-print a JSON response with tabs

Input
{"user":{"id":12345678901234567890,"name":"Ann","roles":["admin","editor"]},"active":true}
Output
{
	"user": {
		"id": 12345678901234567890,
		"name": "Ann",
		"roles": ["admin", "editor"]
	},
	"active": true
}

FAQ

Which languages can I format?

You can format HTML, CSS, SCSS, LESS, JavaScript, JSX, JSON, XML and SQL. Python, Java and PHP are not supported. TypeScript has no separate mode. It passes through the JavaScript formatter, and results for complex TypeScript are not guaranteed.

Does the formatter fix invalid code?

No. The formatter only re-indents your code and does not repair it. Invalid JSON, invalid XML and SQL parse errors stop formatting and show the line and column, and any previous result stays in Formatted code. HTML, CSS and JavaScript can produce a result even with syntax errors, so formatted output does not confirm that your code is valid.

Is my code uploaded or saved?

Formatting runs in your browser without sending your code to a server. The tool does not save your code. It saves only Language, Indent and Blank lines settings in localStorage.

Can I minify code here?

This page only beautifies code. For minifying, use the HTML Formatter, JSON Formatter or SQL Formatter.

Why did automatic formatting stop?

After the first run, edits reformat automatically only when the input is 200 KB or smaller. For larger input, click Format code or press Ctrl+Enter (Cmd+Enter on Mac) to format again.