Small Tools
Frontend utility

JavaScript Beautifier

Add indentation and line breaks to JavaScript source text.

● This tool runs entirely in your browser. Your input is never uploaded to our servers.
Output
Your result will appear here…

How to use JavaScript Beautifier

  1. Paste JavaScript source or compact code.
  2. Select Format.
  3. Read the indented result.

Example

Input / settings:

const greet=(name)=>{return `Hello, ${name}!`;};

Output:

const greet = (name) => {
  return `Hello, ${name}!`;
};

Formatting the output again returns the same text.

When to use

Overview

JavaScript Beautifier re-indents JavaScript with a lightweight tokenizer: two-space indentation, one statement per line, spaces around operators, } else { on one line, indented switch cases and one property per line in object literals. It does not add or remove semicolons, wrap long lines, reorder code or check that the program is valid. Strings, template literals, regular expressions and comments are kept as written.

Supported input

JavaScript text of at most 200,000 characters. JSX is not supported and TypeScript annotations are formatted as plain text.

Output details

Indented JavaScript with two-space indentation. Semicolons are not added or removed and long lines are not wrapped.

Common mistakes

Practical tips

Privacy and security

This tool runs entirely in your browser. Your input is never uploaded to our servers. Formatting runs locally in your browser and nothing is uploaded. Your source is only read as text; nothing in it is executed. An unclosed string, template literal, comment or regular expression is rejected rather than changed, but the tool is not a parser and does not check that the code is valid JavaScript.

References

Frequently asked questions

Does JavaScript Beautifier change what my code does?

It is meant to change only whitespace and line breaks. Because it is a lightweight tokenizer and not a parser, check results for rare constructs such as a regular expression right after a closing brace.

Which indentation does the beautifier use?

Two spaces per level. The page has no indentation setting.

Can it format TypeScript or JSX?

No. TypeScript annotations pass through as plain text, and JSX text that contains an apostrophe is rejected as an unclosed string.

Related tools