JavaScript formatter
Make JavaScript easier to read with consistent indentation, spacing and line breaks.
- 1Add input
- 2Adjust settings
- 3Get your result
Tool input and files are processed in this browser without being uploaded.
Before you start
Format pasted JavaScript or one local file with Prettier. Choose two- or four-space indentation and a quote preference; the code is processed in your browser without being run.
How to use this tool
- Paste code into “JavaScript” or choose one UTF-8 file. Clear the text box to use the file, or remove the file to work with pasted code alone.
- Under “Options”, choose 2 or 4 spaces for “Indentation” and set “Quote preference”. Then select “Format JavaScript”.
- Review the formatted code. Use “Copy result” to copy it or “Download” to save formatted.js. Run the formatter again if you change the input or options.
Supported inputs and limits
Paste up to 1 MiB of UTF-8 text, or choose one UTF-8 file up to 10 MiB. The file picker accepts .js, .mjs and .txt files. Filenames can contain up to 512 UTF-16 code units; one visible character may use more than one code unit. Pasted text takes priority whenever the box is nonempty, even if it contains only spaces. A selected file is still checked and read.
Worked example
Example input
const x={a:1,b:"text"};Example options
{}Example output
const x = { a: 1, b: "text" };
When something does not work
Check the JavaScript syntax and indentation, then select “Format JavaScript” to retry. If a file will not format, save it as UTF-8 in another application and select it again, or remove it and paste the code. Shorten an overlong filename or reduce input that exceeds the size limits. After changing input or cancelling, run the formatter again before using the result.
Frequently asked questions
Are my files uploaded?
No. Formatting happens in your browser. A workspace can remain in memory when you visit other tools in the same tab, but it has size and time limits and may be removed. Refreshing or closing the tab clears it. Save any results you need.
What does successful formatting tell me?
Prettier could parse and format the input; you still need to check how the program behaves. Formatting does not compile TypeScript, minify code or restore original variable names from minified code. The quote setting is a preference: Prettier may use the other quote style to avoid extra escaping. JSX attribute quotes follow separate rules and are not controlled by this setting.
Documentation & further reading
Related tools
JSON formatter and string tools
Format or minify JSON, sort object keys, or convert between plain text and a JSON string.
JavaScript regex tester
Test JavaScript patterns against text and inspect matches, positions and capture groups.
Compare text
Compare two texts line by line, with a side-by-side view of changes.
HTML formatter
Format HTML source with consistent indentation and review the result as text.