Skip to main content

Installation

Install via npm, pip, or use the CDN — get up and running in seconds.

Quickstart

Beautify your first file in under a minute.

Configuration

Explore all 40+ options to tailor output to your style guide.

API Reference

Full API reference for JavaScript, CSS, HTML, and Python.

What is JS Beautify?

JS Beautify reformats and re-indents JavaScript, CSS, and HTML source code. It handles minified code, unpacks scripts packed by Dean Edward’s packer, and partly deobfuscates scripts processed by javascript-obfuscator. You can use it in multiple environments:

Node.js Library

require('js-beautify') — beautify strings programmatically in Node.js or the browser.

CLI Tool

js-beautify, css-beautify, and html-beautify executables for shell workflows.

Python Package

jsbeautifier and cssbeautifier packages on PyPI.

Web Browser

Embed via CDN — exposes js_beautify, css_beautify, and html_beautify globally.

Key features

Reformat minified or poorly indented source code back to a human-readable form. Supports ES6+, JSX, and modern CSS.
Control indentation style, brace placement, line wrapping, newline behavior, operator position, and much more — all from a single config file or CLI flags.
Automatically inherit indentation settings from your project’s .editorconfig file by passing --editorconfig.
Beautify HTML templates written with Django, Handlebars, ERB, PHP, Smarty, and Angular control flow syntax without corrupting template tags.
Embed /* beautify ignore:start */ / /* beautify ignore:end */ or preserve directives directly in your source to protect sections from reformatting.
Apply different indent sizes or settings to JS, CSS, and HTML through a single .jsbeautifyrc config file with nested language keys.

Quick example

npm install -g js-beautify
js-beautify foo.js
Node.js library
var beautify = require('js-beautify');

var ugly = 'function foo(x){if(x>0){return x;}else{return -x;}}';
console.log(beautify.js(ugly, { indent_size: 2 }));
// Output:
// function foo(x) {
//   if (x > 0) {
//     return x;
//   } else {
//     return -x;
//   }
// }
Try it live at beautifier.io — no installation required.