Skip to main content

Node.js

JS Beautify requires Node.js >= 14.
1

Install the package

Install globally to get the js-beautify, css-beautify, and html-beautify executables on your PATH, or install locally to use it as a library in your project.
npm install --global js-beautify
2

Verify the installation

js-beautify --version
To install the latest beta or release candidate, use the next tag:
npm install js-beautify@next

Python

The Python package can only reformat JavaScript. Install the separate cssbeautifier package if you also need CSS formatting.
1

Install jsbeautifier

pip install jsbeautifier
2

Install cssbeautifier (optional)

pip install cssbeautifier
3

Verify the installation

js-beautify --version

Web / CDN

Embed JS Beautify directly in an HTML page using script tags from cdnjs. Three separate files cover JavaScript, CSS, and HTML formatting.
1

Add the script tags

Include the scripts you need before your own code. Use the minified versions in production.
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.4/beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.4/beautify-css.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.4/beautify-html.js"></script>
2

Call the global functions

Each script exposes a global function: js_beautify, css_beautify, and html_beautify.
<!DOCTYPE html>
<html lang="en">
  <body>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.4/beautify.min.js"></script>
    <script src="script.js"></script>
  </body>
</html>
You only need to include the script files for the languages you intend to format. If you only format JavaScript, beautify.min.js alone is sufficient.