Help
  • Click the "Example" button to see a JS formatting demo

JS Formatter

This free online JavaScript formatter beautifies and reindents messy JS code — and can minify it back down for production with optional name mangling.

All tools on this site run entirely in your browser locally. No data is uploaded to any server.

Features:

  • Beautify: Re-indent JavaScript into a clear code structure, with 2, 3 or 4 spaces per level (2 by default)
  • Minify: Strip whitespace and line breaks, compressing everything into a single line
  • Mangle names: Shorten variable and function names to protect your code logic
  • Compress: Apply safe optimizations to further reduce output size

FAQ:

  • Q: Do I need to click Format, and why does it read the right pane?
    A: No: typing in the left pane reformats into the right pane automatically. Format reads the right pane instead, so you can tidy code you've edited there or expand a minified one-liner back into readable JS. Copy, Minify and Save use the right-hand text too. Typing in the left pane again regenerates the right pane, so manual edits there are overwritten.
  • Q: Can I change the indentation?
    A: Yes. The toolbar offers 2, 3 or 4 spaces (2 by default), reformats as soon as you switch, and remembers your choice. The only option under Settings is Line Wrap, which controls how long lines are displayed in the right pane, not the output. The Minify checkboxes in the toolbar affect minification only.
  • Q: Does Minify just strip whitespace?
    A: No. Minify runs Terser on the right-hand text. "Mangle variable names" and "Compress and optimize" are both checked by default, so names are shortened and expressions rewritten as well as whitespace being removed. Uncheck either one to keep the original names or skip the optimizations.
  • Q: Can Format bring back the original code after minifying?
    A: No. Format only re-indents the text: shortened names, removed statements and rewritten expressions stay that way. If the code has a syntax error, Minify shows a "JS format error" message with the parser's explanation and leaves the right pane unchanged; fix the error and try again.
  • Q: What do the fold button and the 3/12 counter do?
    A: The button collapses or expands every block at once; the arrows beside the line numbers fold individual blocks. The counter shows the cursor line and the total line count, so 3/12 means line 3 of 12. It disappears when the right pane is empty.
  • Q: Why does clicking Sample twice clear the editor?
    A: Sample is a toggle: the first click loads a sample script, and a second click clears both panes if you haven't changed it. Edit the sample and clicking Sample again restores the original instead.

Common uses:

  • Cleaning up unformatted or copied JS for easier reading and debugging
  • Compressing JavaScript to reduce page load size
  • Obfuscating variable names to protect front-end logic
  • Spotting syntax and structural issues in scripts