Supported syntax
The beautifier handles modern JavaScript including:- ES6+ features:
const,let, arrow functions, destructuring, spread/rest operators - Async/await and generator functions
- Template literals and tagged templates
- JSX-like syntax
- Dynamic
import()expressions - Optional chaining (
?.) and nullish coalescing (??)
Before and after
The beautifier takes minified or poorly formatted code and produces readable output.Key options
brace_style
Controls where opening and closing braces are placed. Accepts a comma-separated value: a style name, optionally combined with preserve-inline.
| Value | Description |
|---|---|
collapse | Opening brace on same line as statement (default) |
expand | Opening brace on its own line |
end-expand | Closing brace on its own line only |
none | Do not adjust brace position |
,preserve-inline to any value to keep single-line blocks on one line.
- collapse (default)
- expand
- end-expand
- collapse,preserve-inline
operator_position
When a line break occurs around a binary operator, this option controls which side of the break the operator appears on.
| Value | Description |
|---|---|
before-newline | Operator stays at the end of the previous line (default) |
after-newline | Operator moves to the start of the next line |
preserve-newline | Operator position is not changed |
- before-newline (default)
- after-newline
space_in_paren and space_in_empty_paren
space_in_paren adds padding spaces inside parentheses. space_in_empty_paren adds a single space inside empty parentheses.
jslint_happy
Enables stricter JSLint-compatible formatting. When true, it automatically sets space_after_anon_function to true, adding a space before anonymous function parentheses.
keep_array_indentation
When true, preserves the indentation of array elements as written in the source. When false (default), the beautifier re-indents array contents.
comma_first
When true, places commas at the beginning of each new line rather than at the end of the previous line.
wrap_line_length
Sets a soft maximum line length. Lines that exceed this character count will be wrapped at the next opportunity. Set to 0 (default) to disable wrapping.
JSON beautification
You can use the JavaScript beautifier to format JSON. Pass a JSON string tojs_beautify and it produces indented output.
For strict JSON output without trailing commas, use
JSON.parse followed by JSON.stringify with a space argument instead. The JS beautifier is more permissive and useful when the input may not be 100% valid JSON.All JS-specific options at a glance
brace_style
brace_style
Default:
Values:
"collapse"Values:
collapse, expand, end-expand, none, optionally append ,preserve-inlineControls placement of opening and closing braces.operator_position
operator_position
Default:
Values:
"before-newline"Values:
before-newline, after-newline, preserve-newlineWhere to place binary operators when a line break is inserted around them.space_in_paren
space_in_paren
Default:
falseAdd padding spaces inside parentheses: f( a, b ).space_in_empty_paren
space_in_empty_paren
Default:
falseAdd a single space inside empty parentheses: f( ).jslint_happy
jslint_happy
Default:
falseEnable JSLint-stricter mode. Forces space_after_anon_function to true.space_after_anon_function
space_after_anon_function
Default:
falseAdd a space before anonymous function parentheses: function ().space_after_named_function
space_after_named_function
Default:
falseAdd a space before named function parentheses: function example ().keep_array_indentation
keep_array_indentation
Default:
falsePreserve the original indentation of array elements.comma_first
comma_first
Default:
falsePlace commas at the beginning of new lines instead of the end.wrap_line_length
wrap_line_length
Default:
0 (disabled)Wrap lines that exceed N characters. 0 disables wrapping.break_chained_methods
break_chained_methods
Default:
falseBreak chained method calls across subsequent lines.unindent_chained_methods
unindent_chained_methods
Default:
falseDo not indent chained method calls.unescape_strings
unescape_strings
Default:
falseDecode printable characters encoded in xNN notation inside strings.e4x
e4x
Default:
falsePass E4X XML literals through untouched.