JavaScript Formatter
Re-indent JavaScript with consistent braces and line breaks, using a tokenizer that keeps strings, template literals, comments, and regex intact.
How to use
- Paste JavaScript into the input.
- Set the indent width.
- Copy the formatted code.
A JavaScript formatter re-indents code by brace, bracket, and parenthesis depth. A tokenizer reads strings, template literals, comments, and regex literals first, so their contents survive unchanged.
Paste or type something above.
Questions about javascript formatter
- Will it rename anything?
- No. Only whitespace and line breaks change. Identifiers, strings, and numbers are never touched.
- How does it tell division from a regex?
- It looks at the previous significant token. After an operator, an opening bracket, or a keyword, a slash starts a regex, otherwise it is division.
- Does it fix broken code?
- No. An unbalanced quote or comment is reported as an error rather than reformatted into something that does not compile.
Related tools
- JavaScript Minifier Strip comments and unneeded whitespace from JavaScript to cut file size, while keeping str...
- CSS Formatter Re-indent CSS so each declaration sits on its own line and nested at-rules are indented, w...
- Regex Tester Test a regular expression against sample text and see every match with its position, captu...