Format, beautify and organize JavaScript code instantly with customizable formatting and syntax validation. Everything runs locally in your browser.
JS
PRETTY
Code
0 chars
Loading editor…
Paste JavaScript or upload a file to format it.
Waiting for code
TypeScript
Everything happens locally in your browser. Your source code is never uploaded.
What is JavaScript formatting?
JavaScript ignores whitespace almost everywhere. A function written as one 300-character line and the same function spread over fifteen lines are identical to the engine — both parse to the same syntax tree and run at the same speed. Formatting is entirely for the reader. It takes code whose structure is buried in a wall of text and puts that structure back on the screen: one statement per line, consistent indentation for nesting, and line breaks chosen by the same rule every time rather than by whoever typed it.
The same function, before and after
1function total(items,tax){const sum=items.reduce((a,i)=>a+i.price*i.qty,0);if(!tax)return sum;return sum*(1+tax)}23function total(items, tax) {4 const sum = items.reduce((a, i) => a + i.price * i.qty, 0);5 if (!tax) return sum;6 return sum * (1 + tax);7}
Nothing changed except whitespace. The second version runs the same and returns the same value — but you can see at a glance that there are three statements, one early return and one arrow function, and you could point at the line you wanted to change.
This tool works the way a real formatter has to: the file is parsed into a syntax tree and printed back out from that tree. It does not rearrange text with pattern matching, which is why it can be trusted with a five-thousand-line file. If the code cannot be parsed, nothing is printed — you get the error instead of a guess.
Everything here runs in your browser. The code people paste into a formatter carries endpoints, internal names and occasionally a key that should have been an environment variable, so nothing is uploaded, stored or logged.
Why format JavaScript?
Because inconsistent formatting costs attention on every single read, and reading is what people do with code. It also hides the specific mistakes JavaScript is prone to — a callback closed one brace early, a promise chain that silently returns nothing, an if whose body was never braced.
Reviews stop being archaeology. A reviewer can see the shape of a function — how deep it nests, how many branches it has, where it returns — without rebuilding it in their head first.
Diffs shrink to the actual change. With one statement per line and predictable breaking, adding an argument is a one-line diff, in a pull request or in a diff checker. Without it, reformatting noise buries the change nobody can then find.
Bundled code becomes readable.Code pulled from a browser’s Sources panel, a CDN or a build output arrives on one line. Formatting is the first step to understanding any of it.
Nesting stops being invisible. Four levels of callback look much like two until they are indented. Depth on the screen is depth in the program, and it is the most reliable signal that a function needs splitting.
Teams stop arguing about style. One agreed set of options, applied by a tool, ends the discussion about semicolons permanently.
Syntax errors surface immediately. A formatter has to parse before it can print, so it tells you about the unclosed brace on line 91 the moment you paste rather than when the build fails.
Supported JavaScript features
Everything a current engine runs, through ES2025, plus the whole of TypeScript and JSX. Two parsers are available — JavaScript and TypeScript — and both accept JSX; the difference is only whether type syntax is allowed as well. Leave detection on and the language is read off the source, or choose one in the options.
ES modules
import and export, default and named, namespace imports, re-exports, side-effect imports and dynamic import(). The leading import block can be sorted; an import further down the file is left where it is, because moving it could change the order side effects run in.
Async and await
async functions, async arrow functions, async generators, for await…of, and top-level await in a module. An await chain that fits stays on one line and expands one call per line when it does not, which is how you see where a sequence actually branches.
Classes
Fields, static fields, getters and setters, private #fields and #methods, static initialisation blocks, computed member names, and decorators on classes, methods and properties. Each member gets its own line, and a blank line you left between two of them is kept.
Arrow functions
Parentheses around a single parameter can be always or only where required. A concise body that fits stays on one line; a body that does not gets braces-worth of indentation without gaining braces it did not have.
Optional chaining
?., ?.[] and ?.() alongside ?? and the logical assignments ??=, ||= and &&=. Long safe-access chains break at the same points a plain member chain would, so the shape of the access is preserved rather than flattened.
JSX and TSX
Elements indent as a tree, attributes move onto their own lines when the opening tag overruns, children are wrapped in parentheses when a return spans lines, and fragments, conditionals and .map() calls are printed as the expressions they are.
TypeScript
Interfaces, type aliases, unions and intersections, generics with constraints and defaults, enums, namespaces, declaration files, abstract classes, parameter properties, satisfies, as const, and non-null assertions. Choose the parser or let detection find it.
Everything else through ES2025
Generators, template literals and tagged templates, destructuring with defaults and rest, spread, labelled statements, regular expressions with named groups, numeric separators, exponentiation, BigInt literals and import attributes.
Formatting features
Indentation
Two spaces, four spaces or tabs. Indentation means exactly one thing — this is inside that — so it follows the syntax tree and nothing else. A block, an object literal, a JSX child and a chained call each indent from wherever they opened, and the closing character returns to the level of the line that opened it.
Quotes
Single or double, applied consistently. Whichever you choose, a string containing that character takes the other one instead, so nothing ever has to be escaped: "it’s" stays in double quotes even when the file is otherwise single-quoted. Template literals are never converted, because a template literal is a different thing from a string.
Semicolons
Always, or omitted. Omitting them is safe here because it is done by the printer rather than by deleting characters: a line that begins with [ or ( keeps a leading semicolon, which is what stops the line before it being read as an index or a call.
Why the guard matters
1const a = 12const b = [1, 2]3;[b].forEach((x) => x) // without the ; this reads as b[...]
Line width
Adjustable from 40 to 200 characters, and it is a target rather than a limit. The printer fits what it can within the width and breaks at the outermost sensible point when it cannot, so an argument list collapses onto one line if it fits and expands one-per-line if it does not. A long string or a long identifier still runs past it — breaking those would change the code.
Import organisation
Sorting reorders the run of import statements at the very top of the file: packages first, then scoped packages, then aliased paths such as @/components, then relative paths, each group alphabetical.
Sorted imports
1import { useState } from "react";2import { z } from "zod";3import { Button } from "@acme/ui";4import { formatDate } from "@/lib/date";5import { Header } from "./header";
Only that leading run moves. An import further down the file stays exactly where it is, because moving it could change the order in which side effects run. Unused imports are not removed either: knowing an import is unused means resolving every name through every scope, which is a type checker’s job, and getting it wrong deletes working code.
Syntax highlighting
Keywords, class names, function names, JSX tags, strings, template literals, regular expressions, numbers, operators, decorators and comments each get their own treatment, in both panels and in both light and dark themes. Blocks fold from the gutter, and matching brackets are marked as you move through them. Colouring a pattern is as far as it goes, though — to find out what one actually matches, the regex tester runs it against sample text.
Validation
Parsing is validation, so it comes free. When the parser stops, you get the message, the line, the column, a caret pointing at the character and a note about what usually causes it — and the location is a button that takes you there.
Missing brackets, braces and parentheses, reported at the point the parser could no longer make sense of what followed.
Unterminated strings, template literals and comments — the most destructive class of error, because everything after the opening character is being read as something it is not.
Unexpected tokens, which is what a stray comma, a doubled operator or a keyword in the wrong place produces.
Malformed imports and exports, including an import with no specifier and an export of something that was never declared.
You will only ever see one error at a time, and that is deliberate: a parser stops at the first thing it cannot read, so everything after that point is unparsed rather than wrong. Listing seventeen errors caused by one missing brace would mean inventing sixteen of them.
JavaScript best practices
Make formatting a decision nobody makes
The value of consistent formatting is not that any particular style is better — it is that a reader stops noticing style at all. Agree on a set of options once, apply them with a tool, and put that tool in the commit hook so the question never reaches a code review. A team that has stopped discussing semicolons has bought itself real time.
Write functions that fit on a screen
A function you can see all of is a function you can reason about. Prefer early returns to nested conditionals, give the intermediate value a name instead of chaining six calls together, and take the deeply indented block out into its own function the moment the indentation starts running away.
An early return flattens the whole function
1function price(item, user) {2 if (!item) return 0;3 if (!item.available) return 0;4 if (user?.plan === "pro") return item.price * 0.8;5 return item.price;6}
Organise modules around one idea each
A module should be describable in a sentence without the word “and”. Export what callers need and keep the rest private; a file with twenty exports is usually several files. Prefer named exports to default ones — they survive renaming, autocomplete finds them, and a search for the name finds every use.
Name things for the person who reads them next
camelCase for variables and functions, PascalCase for classes and components, SCREAMING_SNAKE_CASE for module-level constants. Name a boolean as a question — isActive, hasAccess — and a function for what it does rather than how it does it. A single-letter name is fine in a two-line callback and nowhere else.
Comment the why, let the code carry the what
A comment restating the line below it is noise that goes stale. A comment explaining the business rule behind an odd-looking condition, or the bug that a workaround exists for, is worth more than the code around it. Formatting handles the what; only you can supply the why.
Write for the next change, not this one
Code is written once and read for years. Prefer const until you need let, prefer explicit over clever, and treat the first version of anything as a draft that somebody unfamiliar will have to edit under time pressure.
JavaScript formatter vs JavaScript minifier
They are opposites, and both are on this page. A formatter makes code easier for a person to read. A minifier makes it smaller for a browser to download. You format the code you keep and minify the copy you ship, and you never edit the minified copy by hand.
Notice what the minifier did and did not do. It removed the whitespace and renamed the parameters and the local, because those names are invisible from outside the function and shortening them saves real bytes across a whole bundle — it is why a production stack trace points at t and c, and why source maps exist. It left total alone, because something outside might call it by that name.
Minifying here is deliberately conservative in one respect: nothing declared at the top level is renamed or removed. A build tool minifying a finished bundle knows an unexported function has no callers and can delete it. This page has a fragment you pasted, and watching an unused class vanish would be alarming rather than helpful. So dead-code removal and renaming apply inside functions, and the top level is left alone.
One genuine limitation: TypeScript and JSX cannot be minified, here or anywhere. Both have to be compiled into JavaScript before minification means anything, because neither is what an engine runs. Format the TypeScript, compile it with tsc or your bundler, and minify what comes out.
And in real projects, minification is not something you do by hand at all — it is what your bundler does on the way to production, with source maps, tree shaking and code splitting alongside it. The button here is for the times you want to see what a snippet costs, or to check that something still works once the names are gone.
Common use cases
The same tool, reached for at different moments. Every one of them starts with code that arrived in a state nobody chose.
Web development
Code arrives from everywhere — a gist, a Stack Overflow answer, a colleague's message, a browser's Sources panel — and almost none of it arrives formatted. This is the first step before reading any of it.
React projects
A component with deeply nested JSX is unreadable until the tree is indented. Formatting also settles the arguments a team would otherwise have about where props go and when to wrap a return in parentheses.
Next.js
Server components, route handlers, middleware and generated metadata all mix async functions with JSX and types in one file. One formatter that handles all three keeps a project consistent across every kind of file in it.
Node.js
Scripts written quickly and kept forever. Formatting a utility script before committing it is the cheapest thing you can do for the person who has to change it in a year, which is usually you.
TypeScript
Type-heavy code has more to lay out than plain JavaScript: long unions, generic constraints, overload signatures. Consistent line breaking turns a wall of angle brackets into something with a shape.
API development
Route handlers, middleware chains and validation schemas are dense with nested objects and callbacks. Formatting shows the nesting depth honestly, which is often the first sign a handler is doing too much.
Debugging
Minified code from a production bundle is impossible to read and hard to reason about. Formatting it back out will not restore the original names, but it does restore the structure — enough to follow a stack trace to a line.
Learning JavaScript
Formatted code teaches structure. Seeing where the printer chooses to break a chain, indent a callback or wrap a return is a fast way to absorb the conventions a codebase expects of you.
Frequently asked questions
Is this JavaScript Formatter free?
Yes. Formatting, minifying, validating, uploading, downloading and every option are free, with no account, no sign-up and no cap on how many files you format.
Is my code uploaded anywhere?
No. The file is parsed and printed by JavaScript running in your browser. Nothing is sent to a server, nothing is stored and nothing is logged. You can disconnect from the network after the page loads and the tool keeps working — which matters, because the code people paste into formatters routinely contains API endpoints, internal class names and occasionally a key somebody forgot to move to an environment variable.
Will formatting change what my code does?
No. The file is parsed into a syntax tree and printed back out, so what changes is whitespace, line breaks, quote characters and — if you ask for them — semicolons and trailing commas. None of those alter the program. Strings, template literals, regular expressions and comments are reproduced exactly. If the code cannot be parsed, nothing is printed at all: you get the error rather than a guess.
Does it support TypeScript?
Yes, fully. Interfaces, type aliases, generics, enums, namespaces, declaration files, decorators, parameter properties, `satisfies`, const assertions and the rest of the type syntax are all parsed and formatted. Choose the TypeScript parser in the options, or let detection pick it — anything with an interface, an enum or a type annotation is read as TypeScript automatically.
Does it support React JSX?
Yes, and TSX. JSX elements are indented as a tree, attributes wrap onto their own lines when they overrun the line width, and expression containers are formatted like the expressions they are. Both parsers accept JSX, so a `.jsx` file and a `.tsx` file are both handled — the choice between them is only about whether type syntax is allowed as well.
Which JavaScript features are supported?
Everything through ES2025: modules, classes, private fields and methods, static blocks, async and await, top-level await, generators and async generators, optional chaining, nullish coalescing and its assignment forms, logical assignment, dynamic import, import attributes, numeric separators, `Object.groupBy`, the change-by-copy array methods, and decorators. If a current engine runs it, the formatter reads it.
Can I upload a JavaScript file?
Yes. Use the upload button or drag a file anywhere onto the tool. `.js`, `.mjs`, `.cjs`, `.jsx`, `.ts`, `.tsx`, `.mts` and `.cts` are all accepted, and the extension sets the parser — a `.ts` file with no annotations in it is still TypeScript. Files are read as UTF-8, so accented and non-Latin text in strings and comments survives intact.
How large a file can it handle?
Up to about 10 MB. Anything past 100 KB is parsed on a background thread, so the page keeps responding while a framework build is formatted — the parser has to read the whole file before it prints a character, and on the main thread that would freeze the tab. Formatting is also debounced, so typing never queues up work behind itself.
Can I minify JavaScript here?
Yes — the Minify button, or Ctrl/Cmd+Shift+M. It removes whitespace and comments, shortens names inside functions, and drops code inside a function that can never run. Names declared at the top level keep their names and nothing at the top level is deleted, because you have pasted a fragment rather than handed over a finished bundle, and watching an unused class disappear would be alarming rather than helpful.
Why can't it minify my TypeScript or JSX?
Because neither is JavaScript yet. Minifiers work on what an engine will actually run, and types and JSX both have to be compiled away first — by tsc, Babel, esbuild or whatever your bundler uses. That is true of every minifier, not a limitation here. Format the TypeScript, compile it, then minify the JavaScript that comes out.
What is the difference between formatting and minifying?
Opposite goals. Formatting makes code easier for a person to read: consistent indentation, one statement per line, predictable line breaks. Minifying makes it smaller for a browser to download: no whitespace, no comments, short names. You format the code you keep in version control and minify the copy you ship, and the minified copy is never edited by hand.
Can it check my code for syntax errors?
Yes — that comes free with parsing. Missing brackets, braces and parentheses, unterminated strings and template literals, unclosed comments, stray tokens and malformed import and export statements are all reported with the line and column where the parser stopped, and a note about what usually causes it. Click the location to jump straight there.
Why does it only ever report one error?
Because a parser stops at the first thing it cannot read, and everything after that point is unparsed rather than wrong. A single missing brace would otherwise produce a page of invented errors, all of them describing the same mistake. Fix the one that is reported and the next real problem, if there is one, appears.
What does sort imports do?
It reorders the run of import statements at the very top of the file: packages first, then scoped packages, then aliased paths such as `@/components`, then relative paths, with each group alphabetical. Only that leading run moves. An import further down the file stays exactly where it is, because moving it could change the order in which side effects run.
Why can't it remove unused imports?
Because knowing an import is unused means resolving every name in the file through every scope in it, which is a type checker's job rather than a formatter's — and getting it wrong deletes code that was doing something. Your editor and your linter both do this properly, with the whole project in view.
Why is there no sort object keys option?
Because key order in JavaScript is observable. `Object.keys`, `for…in`, `JSON.stringify` and spread all preserve insertion order for string keys, so reordering an object literal can change what a program outputs — and a formatter that changes behaviour is worse than no formatter. Sorting keys is a refactor, and belongs somewhere that can tell whether it is safe.
What does the line width setting actually do?
It is where lines are encouraged to break, not a hard limit. The printer fits as much as it can within the width and breaks at the outermost sensible point when it cannot, so an argument list or a chained call collapses onto one line if it fits and expands one-per-line if it does not. A long string or a long identifier will still run past it — breaking those would change the code.
Can I search inside a large file?
Yes. The search button, or Ctrl/Cmd+F, opens a search over the input with every match highlighted, a match counter, and previous and next buttons to step through them. It searches whatever is in the panel — variable names, function names, class names, imports, strings or comments. Escape closes it.
What do the statistics count?
Characters, lines, functions, arrow functions, async functions, classes, variables, imports, exports, comment lines, blank lines, file size and how long the formatting took. They are read from the text rather than from a syntax tree, deliberately: it means they are still there when the code will not parse, which is exactly when you want to know what is in the file. It also means an arrow function is any `=>`, including the ones inside callbacks.
Are there keyboard shortcuts?
Ctrl/Cmd+Enter formats, Ctrl/Cmd+Shift+M minifies, Ctrl/Cmd+Shift+C copies the output, Ctrl/Cmd+Shift+D downloads it, Ctrl/Cmd+Shift+L loads another sample, Ctrl/Cmd+Shift+Delete clears the input, and Ctrl/Cmd+F opens the search. Escape closes the search.
Does it work offline?
Once the page has loaded, yes. The parsers are fetched the first time you format something and cached after that, so from then on you can disconnect and keep working. A connection is only needed to load the page the first time.
Keep going
Tools that pair with this one
Same engine, same privacy model — everything below runs in your browser too.