Node.js
JS Beautify requires Node.js >= 14 .
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 (global)
npm (local)
yarn
pnpm
npm install --global js-beautify
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.
Install cssbeautifier (optional)
pip install cssbeautifier
Web / CDN
Embed JS Beautify directly in an HTML page using script tags from cdnjs. Three separate files cover JavaScript, CSS, and HTML formatting.
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 >
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.