Skip to main content
JS Beautify options follow a consistent naming convention: CLI flags use dashes (e.g., --indent-size), while the library API and config files use underscores (e.g., indent_size). The two forms are interchangeable — the option parser normalizes dashes to underscores internally.
# CLI: dashes
js-beautify --indent-size 2 --end-with-newline foo.js
// Library: underscores
beautify.js(code, { indent_size: 2, end_with_newline: true });

Common options

These options apply to all three beautifiers (JavaScript, CSS, and HTML).
indent_size
number
default:"4"
Number of spaces per indentation level. Overridden by indent_with_tabs.
indent_char
string
default:"\" \""
Character used for indentation. Defaults to a single space. Set to "\t" or use indent_with_tabs instead.
indent_with_tabs
boolean
default:"false"
Indent with tab characters instead of spaces. When true, overrides indent_size and sets indent_char to "\t". If indent_size is 1 when this is enabled, it resets to 4.
eol
string
default:"\"auto\""
Line terminator sequence. Defaults to "auto", which uses the first newline found in the file, or "\n" if none is found. Accepts "\n", "\r\n", or "\r".
end_with_newline
boolean
default:"false"
Append a newline at the end of the output.
editorconfig
boolean
default:"false"
Read indentation and line-ending settings from the nearest .editorconfig file. Explicit options passed alongside this flag take precedence. See EditorConfig Integration.
indent_empty_lines
boolean
default:"false"
Preserve indentation whitespace on otherwise empty lines. By default, empty lines are left with no leading whitespace.

JavaScript options

These options are recognized only by the JavaScript beautifier.

Defaults

{
    "indent_size": 4,
    "indent_char": " ",
    "indent_with_tabs": false,
    "editorconfig": false,
    "eol": "auto",
    "end_with_newline": false,
    "indent_level": 0,
    "preserve_newlines": true,
    "max_preserve_newlines": 10,
    "space_in_paren": false,
    "space_in_empty_paren": false,
    "jslint_happy": false,
    "space_after_anon_function": false,
    "space_after_named_function": false,
    "brace_style": "collapse",
    "unindent_chained_methods": false,
    "break_chained_methods": false,
    "keep_array_indentation": false,
    "unescape_strings": false,
    "wrap_line_length": 0,
    "e4x": false,
    "comma_first": false,
    "operator_position": "before-newline",
    "indent_empty_lines": false,
    "templating": ["auto"],
    "eval_code": false,
    "space_before_conditional": true
}
eval_code and space_before_conditional are not exposed as CLI flags. They can only be set via the library API or a config file.

Option reference

indent_level
number
default:"0"
Initial indentation level applied before beautification begins. Useful when embedding beautified output inside another structure.
preserve_newlines
boolean
default:"true"
Keep existing blank lines in the source. Pass --no-preserve-newlines on the CLI to disable.
max_preserve_newlines
number
default:"10"
Maximum number of consecutive blank lines to preserve in one place. Has no effect when preserve_newlines is false.
space_in_paren
boolean
default:"false"
Add padding spaces inside parentheses: f( a, b ) instead of f(a, b).
space_in_empty_paren
boolean
default:"false"
Add a single space inside empty parentheses: f( ) instead of f().
jslint_happy
boolean
default:"false"
Enable jslint-compatible output. When true, forces space_after_anon_function to true as well.
space_after_anon_function
boolean
default:"false"
Add a space between the function keyword and the opening parenthesis of anonymous functions: function () instead of function().
space_after_named_function
boolean
default:"false"
Add a space between the function keyword and the opening parenthesis of named functions: function example () instead of function example().
brace_style
string
default:"\"collapse\""
Controls placement of curly braces. Accepted values:
  • collapse — Opening brace on same line as control statement (K&R style).
  • expand — Opening brace on its own line (Allman style).
  • end-expand — Opening brace on same line, closing brace on its own line.
  • none — Leave brace placement as-is.
Append ,preserve-inline to any value to keep single-line blocks on one line: "collapse,preserve-inline".
unindent_chained_methods
boolean
default:"false"
Do not add extra indentation for chained method calls.
break_chained_methods
boolean
default:"false"
Place each chained method call on its own line.
keep_array_indentation
boolean
default:"false"
Preserve the original indentation of array elements.
unescape_strings
boolean
default:"false"
Decode printable ASCII characters encoded in \xNN notation back to their literal form.
wrap_line_length
number
default:"0"
Wrap lines that exceed this number of characters. 0 disables wrapping.
e4x
boolean
default:"false"
Pass E4X XML literals through the beautifier unchanged.
comma_first
boolean
default:"false"
Place commas at the beginning of each new line rather than at the end.
operator_position
string
default:"\"before-newline\""
Where to place binary operators when a line breaks. Accepted values:
  • before-newline — Operator stays at the end of the upper line.
  • after-newline — Operator moves to the beginning of the lower line.
  • preserve-newline — Keep the operator wherever it appears in the source.
templating
string[]
default:"[\"auto\"]"
List of templating languages whose syntax should be preserved. Accepted values: auto, none, angular, django, erb, handlebars, php, smarty. auto means no templating in JavaScript mode.
eval_code
boolean
default:"false"
Attempt to beautify code passed to eval(). Not exposed as a CLI flag.
space_before_conditional
boolean
default:"true"
Add a space before conditional statements (if, for, etc.). Not exposed as a CLI flag.

CSS options

brace_style
string
default:"\"collapse\""
Controls placement of curly braces. Only collapse and expand are implemented for CSS.
  • collapse — Opening brace on same line as selector.
  • expand — Opening brace on its own line.
selector_separator_newline
boolean
default:"true"
Place each selector in a comma-separated list on its own line.
newline_between_rules
boolean
default:"true"
Add a blank line between CSS rule blocks.
space_around_combinator
boolean
default:"false"
Add spaces around combinator characters (>, +, ~). Also settable via the legacy space_around_selector_separator.

HTML options

indent_inner_html
boolean
default:"false"
Indent the contents of <head> and <body> tags.
indent_body_inner_html
boolean
default:"true"
Indent the contents of the <body> tag.
indent_head_inner_html
boolean
default:"true"
Indent the contents of the <head> tag.
indent_scripts
string
default:"\"normal\""
How to handle indentation of content inside <script> tags. Accepted values: normal, keep, separate.
wrap_line_length
number
default:"0"
Maximum characters per line for HTML output. 0 disables wrapping.
wrap_attributes
string
default:"\"auto\""
How to wrap HTML tag attributes when a tag is long. Accepted values:
  • auto — Only wrap when the line exceeds wrap_line_length.
  • force — Wrap each attribute onto its own line.
  • force-aligned — Wrap and align attributes to the first attribute.
  • force-expand-multiline — Wrap each attribute, including the first.
  • aligned-multiple — Align multiple attributes per line.
  • preserve — Preserve existing line breaks in attributes.
  • preserve-aligned — Preserve and align to the first attribute.
wrap_attributes_min_attrs
number
default:"2"
Minimum number of attributes required before forced wrapping applies (used with force wrap modes).
wrap_attributes_indent_size
number
default:"indent_size"
Number of characters to indent wrapped attributes. Defaults to indent_size. Ignored when wrap_attributes is "aligned".
inline
string[]
List of tag names treated as inline elements. These are not forced onto new lines. Defaults to the full set of HTML inline elements (a, abbr, b, br, code, em, img, input, span, etc.).
inline_custom_elements
boolean
default:"true"
Treat custom elements (e.g. <my-component>) as inline elements.
unformatted
string[]
default:"[]"
List of tag names whose opening tags, content, and closing tags are left completely unchanged.
content_unformatted
string[]
default:"[\"pre\", \"textarea\"]"
List of tag names whose inner content is preserved as-is, but whose tags themselves are still formatted.
unformatted_content_delimiter
string
default:"\"\""
Keep all text content between occurrences of this string on one line.
extra_liners
string[]
default:"[\"head\", \"body\", \"/html\"]"
List of tags that should be preceded by an extra blank line.
templating
string[]
default:"[\"auto\"]"
Templating languages to preserve. In HTML mode, auto enables django, erb, handlebars, and php by default.