What you can do with Code Formatter
- Format javascript code
- Beautify css
How this developer utility works
Beautify JavaScript, HTML, CSS, or JSON with Prettier in the browser; safely minify JavaScript with Terser or compact JSON by parsing and serializing it.
Example input
const foo = "bar";function test(){console.log(foo)}Example output
const foo = 'bar';
function test() {
console.log(foo);
}Practical workflow
- Select the language: JavaScript, HTML, CSS, or JSON.
- Paste code up to 1,000,000 characters and click Beautify to format any supported language.
- For JavaScript or JSON, click Minify; HTML and CSS minification is not offered because this tool does not bundle dedicated minifiers for those syntaxes.
- Compare the result in the output panel, then copy it when you are done.
Common use cases
- Use syntax-aware JavaScript minification before checking a production bundle in its real build pipeline.
- Pretty-print a JSON payload from an API response or log line.
- Normalise quotes and indentation in a code sample before pasting it into documentation.
Important notes and limitations
- Beautify uses Prettier (standalone build) with fixed settings: 2-space indentation, semicolons, and single quotes for JavaScript. There are no per-run style options.
- Minify uses Terser for JavaScript and JSON.parse/JSON.stringify for JSON; HTML and CSS are formatted but their Minify button is disabled because no syntax-aware minifier is provided for those languages.
- Input and formatted or minified output are limited to 1,000,000 characters to bound browser parsing and memory use.
- Formatting runs entirely in your browser; source code and language stay in tab memory and clear when you reload or leave the tool. Results clear when the source or language changes.
CLI code formatting & beautification tools
Format JavaScript/TypeScript with Prettier
npx prettier --write 'src/**/*.{ts,tsx,js}'Applies opinionated, standardized code formatting rules across source files according to .prettierrc.
Format Python with Ruff
ruff format ./srcHigh-performance Rust-based Python code formatter compatible with Black rules at 100x speed.
Formatter AST errors & syntax compatibility
SyntaxError: Unexpected token ... (Prettier parser failure)
Cause: Code contains experimental language syntax (e.g. decorators, pipeline operator) unsupported by default parser.
Solution: Configure parser override in prettier options (e.g. '--parser babel-ts' instead of default 'typescript').
Inconsistent formatting on git commit across developers
Cause: Developers running differing local formatter versions or conflicting editor extension settings.
Solution: Enforce formatting via pre-commit hooks (lint-staged + husky) and CI validation gates ('prettier --check .').
Continue your workflow
- JSON Beautifier — validate and explore JSON with a dedicated viewer.
- SQL Formatter — format SQL queries, which this tool does not cover.
Frequently asked questions
Why were my double quotes changed to single quotes?
The JavaScript formatter runs Prettier with singleQuote enabled. Strings that contain a single quote keep double quotes, as Prettier does.
Can I change the indentation width?
Not in this tool — it is fixed at two spaces to match the most common Prettier configuration.
Is the minified JavaScript safe to deploy?
It uses Terser to parse and optimize JavaScript, but you should still run your tests and production build because application behavior depends on your target environment and build settings.
Does it format TypeScript or SQL?
No. Supported languages are JavaScript, HTML, CSS, and JSON. Use the SQL Formatter for queries and the JSON to TypeScript tool for type generation.