js-beautify

Reformats and re-indents JavaScript, HTML, and CSS into clean, readable code

Tool
npm
v2.0.3
8,998 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
64 /100 Good
Development Activity 48
Maintenance 20
Community 88
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
76 /100 Good
Architecture 78
Code Quality 72
Innovation 70
Learning Curve 82

js-beautify is a long-running, widely used code formatter that takes minified, obfuscated, or inconsistently indented JavaScript, HTML, or CSS and reformats it into readable, consistently indented source. It ships as a Node.js library with a CLI (js-beautify, css-beautify, html-beautify), a browser-embeddable script, and a companion Python package (jsbeautifier), and it also partially deobfuscates scripts packed by common packers.

It has been maintained since 2008 and is the formatting engine behind the popular beautifier.io web tool, embedded in countless editor extensions and dev tool integrations that need to pretty-print arbitrary JS/HTML/CSS on the fly.

What You Get

  • A js-beautify CLI plus dedicated css-beautify and html-beautify executables for formatting files or piped stdin
  • A Node.js library API (beautify.js, beautify.css, beautify.html) for programmatic formatting inside build tools or editors
  • A browser-ready bundle (via cdnjs) exposing js_beautify, css_beautify, and html_beautify globals
  • A parallel Python implementation (jsbeautifier/cssbeautifier) with matching CLI and library interfaces
  • Partial deobfuscation of scripts packed by Dean Edwards’ packer and related tools
  • Extensive configuration via .jsbeautifyrc/EditorConfig for indent size, brace style, wrap length, and templating languages

Common Use Cases

  • Reformatting minified or obfuscated third-party JavaScript for readability during debugging
  • Powering an editor extension or IDE’s built-in “format document” command
  • Normalizing code style in a build pipeline before further static analysis
  • Embedding a formatter in a browser-based code playground or snippet tool

Under The Hood

Architecture - The codebase splits into three parallel beautifiers (js/src/javascript, js/src/css, js/src/html) that share a common tokenizing core in js/src/core (tokenizer.js, token.js, inputscanner.js, pattern.js, output.js). Each language beautifier tokenizes input into a stream, walks it applying indentation/brace-style rules from options.js, and re-emits formatted output via the shared output.js writer; a mirrored Python implementation under python/jsbeautifier and python/cssbeautifier reimplements the same core/tokenizer pattern for the pip-installable CLI. Tech Stack - Plain JavaScript (no framework), packaged for Node via js/index.js with CLI entrypoints under js/bin/, plus webpack-based bundling (webpack.config.js) for the browser distribution; the Python port depends only on the standard library. Runtime dependencies are minimal (config-chain, editorconfig, glob, js-cookie, nopt). Code Quality - Tests live under js/test/ (node, AMD, and browser “sanity” suites) and python/*/tests, covering each beautifier against fixture data in test/data/{javascript,css,html}; the project has run for over a decade with 3,300+ commits and 275 contributors, though the README itself flags that it is under-resourced for its popularity and actively seeking maintainers. API Design - The library API is a thin, well-documented beautify(code, options) signature mirrored across JS, Python, and CLI surfaces with underscore-cased option names matching CLI flag names one-to-one, which keeps the developer experience consistent across all four distribution channels (Node, browser, Python, CLI).

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers