๐ŸŒ
GitHub
github.com โ€บ beautifier โ€บ js-beautify
GitHub - beautifier/js-beautify: Beautifier for javascript ยท GitHub
Using the above example would have the following result: ... Inherit indent_size of 4 spaces from the top-level setting. The files would also end with a newline. ... Inherit the HTML end_with_newline setting. Override their indentation to 2 spaces. ... Override the top-level setting to an indent_size of 1 space. ... Inherit indent_size of 4 spaces from the top-level setting. Set preserve-newlines to true. In addition to the js-beautify executable, css-beautify and html-beautify are also provided as an easy interface into those scripts.
Author ย  beautifier
๐ŸŒ
Beautifier
beautifier.io
Online JavaScript beautifier
Chrome, in case the built-in CSS and javascript formatting isn't enough for you: โ€” Quick source viewer by Tomi Mickelsson (github, blog), โ€” Javascript and CSS Code beautifier by c7sky, โ€” jsbeautify-for-chrome by Tom Rix (github), โ€” Pretty Beautiful JavaScript by Will McSweeney โ€” Stackoverflow Code Beautify by Making Odd Edit Studios (github).
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ js-beautify
js-beautify - npm
The configuration option names are the same as the CLI names but with underscores instead of dashes. For example, --indent-size 2 --space-in-empty-paren would be { indent_size: 2, space_in_empty_paren: true }.
      ยป npm install js-beautify
    
Published ย  Feb 27, 2025
Version ย  1.15.4
Author ย  Einar Lielmanis
Homepage ย  https://beautifier.io/
๐ŸŒ
Snyk
snyk.io โ€บ advisor โ€บ js-beautify โ€บ js-beautify code examples
Top 5 js-beautify Code Examples | Snyk
formatCode = memoize(2)((language, code) => { let formattedCode = code; if (language === 'jsx') { try { formattedCode = beautify(code, { indent_size: 2, brace_style: 'collapse,preserve-inline', end_with_newline: true, wrap_line_length: 80, e4x: true, }); } catch (error) { console.warn("Couldn't format code", formattedCode); // eslint-disable-line no-console } } return formattedCode; });
๐ŸŒ
Code Beautify
codebeautify.org โ€บ jsviewer
Best Javascript Beautifier tool work as JavaScript Formatter, Viewer and Prettier
It helps to beautify/format your Javascript. JS Prettier allows loading the Javascript Source Code URL to beautify. Use your JS URL to format.
๐ŸŒ
EasyRetro
easyretro.io โ€บ tools โ€บ js-beautifier
JS Beautifier (Simple and Easy) | EasyRetro
In this article, we will see what exactly is JavaScript, its importance, and how to maintain it by using our JS Beautifier.
๐ŸŒ
CodeSandbox
codesandbox.io โ€บ examples โ€บ package โ€บ js-beautify
js-beautify examples - CodeSandbox
Use this online js-beautify playground to view and fork js-beautify example apps and templates on CodeSandbox.
๐ŸŒ
Snyk
snyk.io โ€บ advisor โ€บ js-beautify โ€บ functions โ€บ js-beautify.html
How to use the js-beautify.html function in js-beautify | Snyk
mediamonks / muban / build-tools ... template({ content, page, publicPath: config.dist.publicPath, }); // make it pretty const html = beautifyHtml(templateStandaloneResult, { indent_size: 2 }); // output to disk return new Promise((resolve, reject) => { fs.writeFile(path.resol...
๐ŸŒ
Unibeautify
unibeautify.com โ€บ docs โ€บ beautifier-js-beautify
JS-Beautify Beautifier ยท Unibeautify
A .unibeautifyrc.json file would look like the following: { "LANGUAGE_NAME": { "beautifiers": [ "JS-Beautify" ] } }
Find elsewhere
๐ŸŒ
JSON Formatter
jsonformatter.org โ€บ jsbeautifier
Best JSBeautifier to beautify / format JavaScript
This Javascript Beautifier that supports indentation levels: 2 tab spaces, 3 tab spaces, and 4 tab spaces. Download JS, once it's formatted, created or modified and this js file can be opened in Sublime, VSCode, and Notepad++ alternative.
๐ŸŒ
JS Beautify
prettifyjs.net
JS Beautify and Minify - Online
Begin with the "type (or paste) here..." area to enter your data, then hit the "minify" or "beautify" buttons respectively. After a blink of any eye, the results will be shown below these buttons. Alternatively, use the "click (or tap) here..." area to select JS files from your device, then hit the corresponding button.
๐ŸŒ
CloudDefense.ai
clouddefense.ai โ€บ code โ€บ javascript โ€บ example โ€บ js-beautify
Top 10 Examples of js-beautify code in Javascript
' if (/^\\.view\\.view-main/.test(myApp.views[v].selector)) {\n' + ' mainView = myApp.views[v]\n' + ' } else if (/^#right-panel-view/.test(myApp.views[v].selector)) {\n' + ' rightView = myApp.views[v]\n' + ' }\n' + ' }\n' + ' if (mainView === null) {\n' + ' myApp.alert("Main view not found.")\n' + ' }\n' + ' if (rightView === null) {\n' + ' myApp.alert("Right panel view not found.")\n' + ' }\n' + ' var $$ = window.Dom7;\n' + jsFile + '\n' + '}\n' jsFile = beautify.js(jsFile, {indent_size: 2, end_with_newline: true}) fs.writeFileSync(path.resolve(env.app, 'kitchen-sink-' + theme + '.js'), jsFil
Top answer
1 of 10
76

First, pick your favorite Javascript based Pretty Print/Beautifier. I prefer the one at http://jsbeautifier.org/, because it's what I found first. Downloads its file https://github.com/beautify-web/js-beautify/blob/master/js/lib/beautify.js

Second, download and install The Mozilla group's Java based Javascript engine, Rhino. "Install" is a little bit misleading; Download the zip file, extract everything, place js.jar in your Java classpath (or Library/Java/Extensions on OS X). You can then run scripts with an invocation similar to this

java -cp js.jar org.mozilla.javascript.tools.shell.Main name-of-script.js

Use the Pretty Print/Beautifier from step 1 to write a small shell script that will read in your javascript file and run it through the Pretty Print/Beautifier from step one. For example

//original code    
(function() { ... js_beautify code ... }());

//new code
print(global.js_beautify(readFile(arguments[0])));

Rhino gives javascript a few extra useful functions that don't necessarily make sense in a browser context, but do in a console context. The function print does what you'd expect, and prints out a string. The function readFile accepts a file path string as an argument and returns the contents of that file.

You'd invoke the above something like

java -cp js.jar org.mozilla.javascript.tools.shell.Main beautify.js file-to-pp.js

You can mix and match Java and Javascript in your Rhino run scripts, so if you know a little Java it shouldn't be too hard to get this running with text-streams as well.

2 of 10
64

UPDATE April 2014:

The beautifier has been rewritten since I answered this in 2010. There is now a python module in there, an npm Package for nodejs, and the jar file is gone. Please read the project page on github.com.

Python style:

$ pip install jsbeautifier

NPM style:

$ npm -g install js-beautify

to use it (this will return the beatified js file on the terminal, the main file remains unchanged):

$ js-beautify file.js

To make the changes take effect on the file, you should use this command:

$ js-beautify -r file.js

Original answer

Adding to Answer of @Alan Storm

the command line beautifier based on http://jsbeautifier.org/ has gotten a bit easier to use, because it is now (alternatively) based on the V8 javascript engine (c++ code) instead of rhino (java-based JS engine, packaged as "js.jar"). So you can use V8 instead of rhino.

How to use:

download jsbeautifier.org zip file from http://github.com/einars/js-beautify/zipball/master

(this is a download URL linked to a zip file such as http://download.github.com/einars-js-beautify-10384df.zip)

old (no longer works, jar file is gone)

java -jar js.jar  name-of-script.js

new (alternative)

install/compile v8 lib FROM svn, see v8/README.txt in above-mentioned zip file

./jsbeautify somefile.js

-has slightly different command line options than the rhino version,

-and works great in Eclipse when configured as an "External Tool"

๐ŸŒ
GitHub
github.com โ€บ yasuyk โ€บ web-beautify
GitHub - yasuyk/web-beautify: Format HTML, CSS and JavaScript/JSON by js-beautify
(require 'web-beautify) ;; Not necessary if using ELPA package (eval-after-load 'js2-mode '(define-key js2-mode-map (kbd "C-c b") 'web-beautify-js)) ;; Or if you're using 'js-mode' (a.k.a 'javascript-mode') (eval-after-load 'js '(define-key js-mode-map (kbd "C-c b") 'web-beautify-js)) (eval-after-load 'json-mode '(define-key json-mode-map (kbd "C-c b") 'web-beautify-js)) (eval-after-load 'sgml-mode '(define-key html-mode-map (kbd "C-c b") 'web-beautify-html)) (eval-after-load 'web-mode '(define-key web-mode-map (kbd "C-c b") 'web-beautify-html)) (eval-after-load 'css-mode '(define-key css-mode-map (kbd "C-c b") 'web-beautify-css))
Starred by 223 users
Forked by 21 users
Languages ย  Emacs Lisp 82.2% | Makefile 17.8%
๐ŸŒ
HTML Cleaner
html-cleaner.com โ€บ js
JavaScript Cleaner - Free online JS Beautifier
End script and style with new line Detect packers and obfuscators Space after conditional "if" Support XML-like syntax Comma-first list style Sustain array indentation Break lines on chained methods Unescape encoded printable chars Use JSLint formatting Indent <head> and <body> ... Always keep a backup and verify your code before publishing! We use cookies to collect anonymous visitor analytics and to show personalized ads. This website doesn't send your code to the server and doesn't save it. We use cookies to improve user experience. Please report if you find an error or you have any suggestion. This free online JavaScript code beautifier and cleaner tool allows you to tidy and optimize your code.
๐ŸŒ
FreeFormatter
freeformatter.com โ€บ javascript-beautifier.html
Free Online Javascript Beautifier / Formatter - FreeFormatter.com
This free online tool lets you beautify/format your JavaScript code with no side effects.
๐ŸŒ
js-beautify
js-beautify.com
js-beautify.com
Beautify JavaScript/HTML(ctrl-enter) What is javascript beautifier? What does the tool do? What is JavaScript? This website uses cookies to improve user experience. By using our website you consent to all cookies in accordance with our Cookie Policy.
๐ŸŒ
Jpkc
jpkc.com โ€บ tools โ€บ beautify
Beautify โ€” Beautify JavaScript, HTML, CSS, JSON etc. based on JS Beautifier
Use JSLint-happy formatting tweaks? Indent <head> and <body> sections? Use a simple textarea for code input? Beautify JavaScript, CSS or HTML (ctrl-enter) Beautify JavaScript, CSS or HTML (ctrl-enter)