JavaScript Beautifier
Format JavaScript and JSX locally, compare changes, and download a separate formatted file.
Settings
Format with Ctrl+Enter or ⌘+Enter. Drop a .js, .jsx, .mjs, .cjs, or .json file here (up to 2 MB).
Choose your options, then beautify to generate a fresh result.
Runs locally in your browser. Nothing is uploaded or sent to a server.
Paste JavaScript or JSX into JavaScript Input and click Beautify JavaScript to get readable, formatted code in a separate output. Choose indentation, line width, quote preference, and semicolons in Settings. Open or drop local .js, .mjs, .cjs, .jsx, or .json files up to 2 MB. Show changes compares source and result within a 100,000-character combined limit. Copy or download after reviewing syntax diagnostics. Formatting runs in your browser without executing your source code.
Updated
Related Tools
CSS Minifier
Compact CSS on your device with three comment policies, UTF-8 savings, and a .min.css download.
developer-toolsHTML Minifier
Choose which comments to keep, collapse whitespace, and review byte savings before downloading HTML.
developer-toolsJSON Formatter
Beautify or minify JSON, inspect its structure, and copy or download the result in your browser.
developer-toolsJSON Minifier
Minify and compress JSON in your browser. Remove whitespace, indentation and line breaks. Your data stays on your device.
What Does Beautifying JavaScript Change in Practice?
Paste compact JavaScript into JavaScript Input and click Beautify JavaScript to separate statements, space operators, and reveal nesting. For a reproducible example, leave Settings at its defaults: Indent set to 2 spaces, Line width set to 80, Prefer single quotes unchecked, and Semicolons checked. Enter this single line without a trailing newline:
const prices=[12,8,5];const total=prices.reduce((sum,price)=>sum+price,0);
The formatted result is:
const prices = [12, 8, 5];
const total = prices.reduce((sum, price) => sum + price, 0);
The footer reports 74 original bytes, 88 beautified bytes, and 2 output lines. The result includes a final newline, which counts toward its byte size but not an extra output line. No sum is evaluated: the formatter rewrites source text without running the array reduction. The longer output is expected because spaces and line breaks improve readability. Use Show changes to inspect exactly which text was added or removed before copying it into your project.
How Do You Beautify JavaScript or JSX?
Paste your source code into JavaScript Input, choose your formatting preferences, and click Beautify JavaScript. Open file reads a local source file into the same editor. The Sample button provides a compact object, an arrow function, and a regular expression so you can try the controls before working with your own code. The result appears separately from the input, keeping your original text available for comparison and correction.
The formatter parses the input before generating its output. This matters when punctuation has several meanings: a slash can begin a regular expression or represent division, and braces can belong to a block, an object, or a template expression. A parser understands these distinctions instead of inserting a newline after every punctuation character. JSX markup is accepted alongside JavaScript, so small components can be formatted without removing their markup first.
Which Formatting Settings Should You Choose?
Use the indentation style expected by your project: 2 spaces, 4 spaces, or tabs. Indentation makes nested blocks easier to follow, while line width controls when expressions and argument lists are usually broken across multiple lines. The available preferred widths are 80, 100, and 120 characters. This setting is a guide rather than a hard ceiling: a long string, URL, or another indivisible token may remain longer than the selected width.
Prefer single quotes changes the formatter's quote preference for JavaScript strings. The printer may choose a different quote when it avoids unnecessary escaping, and JSX attributes follow their own printing rules. The Semicolons checkbox controls ordinary statement terminators. Turning it off does not remove every semicolon: a leading semicolon can be necessary before a statement starting with an array or parentheses. Preserving that boundary prevents two statements from being interpreted as one expression.
How Do Local File Import and Download Work?
Open file accepts .js, .mjs, .cjs, .jsx, and .json files, with case-insensitive extension checks. The browser reads the selected file as text; the tool does not execute it. After formatting, Download creates a new file with a .beautified suffix before the original extension. For example, bundle.min.mjs becomes bundle.min.beautified.mjs. Code entered without an imported filename downloads as beautified.js. The original file on disk is not overwritten by opening or formatting it.
Copy and Download become available after a successful formatting run. Both use the same result, including its LF line endings and final newline. Changing the input or a formatting option clears that result, so run Beautify JavaScript again before exporting. The footer compares the original and formatted byte sizes and reports the output line count. Formatting often increases size by adding whitespace; it is intended for reading and editing rather than reducing transfer size.
Can You Format JSON Files as Well as JavaScript?
Yes, but the imported filename matters. Opening or dropping a file ending in .json selects the
JSON parser, while other supported filenames and code pasted without a filename use the JavaScript
parser. A file named data.json containing {"hello": [1,2]} produces
{ "hello": [1, 2] } followed by a newline and downloads as data.beautified.json.
The download also uses a JSON content type for that filename.
Simply pasting a JSON object does not switch parsers automatically. For JSON-only work, use JSON Formatter. Renaming unsupported source to .js also does not translate its syntax: the extension filter controls which files can be read, while the parser decides whether their contents are valid. There is no TypeScript parser option or batch directory import here.
How Do You Compare Changes and Handle Larger Inputs?
Show changes displays an inline source-to-result comparison, with removed text struck through and added text underlined. Its limit is 100,000 combined source and result characters, not 100,000 characters per editor. Whitespace differences are included. When that combined length is too large, the comparison shows a limit message; this does not remove the formatted output or prevent Copy and Download. Use Text Diff for a separate comparison.
| Operation | Boundary | What it means |
|---|---|---|
| Open or drop a file | 2,097,152 bytes maximum | Larger files are rejected before reading. |
| Format input | Over 51,200 UTF-8 bytes | Processing moves to a Worker with a 5-second timeout. |
| Show changes | 100,000 combined characters maximum | Larger comparisons show a message instead of a diff. |
The interface calls the file cap 2 MB and the Worker threshold corresponds to 50 KB. These are byte measurements; non-ASCII source can use more bytes than its visible character count suggests. The file cap is an import check, not a promise that any pasted input will finish. If a Worker times out, try a smaller complete module. Cancel stops the current task and clears its result; editing the input or changing settings also invalidates a pending result so older output cannot replace your latest revision.
What Should You Do When Formatting Fails?
Read the diagnostic and inspect the indicated input line. Missing quotes, incomplete expressions, and unclosed brackets can prevent parsing. Fix the source and retry; the tool keeps the input available when formatting fails. A successful parse does not establish that variables exist, imports resolve, or functions return the intended values. Those concerns require your project's tests and other development tools. TypeScript annotations and incomplete snippets may need to be converted into supported JavaScript before they can be formatted here.
For example, const value = ; is rejected with a diagnostic at line 1, column 15.
Also distinguish a formatting error from a logic error: a newline immediately after
return triggers JavaScript automatic semicolon insertion. Beautifying preserves that
statement boundary rather than moving a following object onto the return line and changing the
program. Formatting cannot recover meaningful variable names removed during minification or undo
obfuscation. Review the result and run your own tests before replacing working source.
How Can You Work Comfortably on a Small Screen?
The action buttons and formatting controls wrap to fit narrow screens, and long output lines scroll horizontally without changing the copied or downloaded text. You can use the file picker when pasting a long bundle is awkward. On a hardware keyboard, Ctrl+Enter or Command+Enter formats from the input editor. If the Paste button cannot access the clipboard, use your browser's normal paste action directly in the input instead. Local files, including files dropped onto the input, are limited to 2 MB. Available memory and formatting time still depend on your device.
How to Use JavaScript Beautifier
-
JavaScript Input
Paste JavaScript or JSX into JavaScript Input, choose Open file for a local file, or click Sample to try the formatter. You can also drop a supported file onto the input.
-
Settings
Open Settings. Choose Indent and Line width, then set Prefer single quotes and Semicolons to match your project.
-
Beautify JavaScript
Click Beautify JavaScript or press Ctrl+Enter or Command+Enter in the input. Correct any reported syntax error and try again.
-
Show changes
Enable Show changes to review the inline comparison. This view accepts up to 100,000 combined source and result characters.
-
Copy
Use Copy for the formatted text or Download for a separate file. Imported filenames receive a .beautified suffix before their extension; pasted code downloads as beautified.js.