Code Beautifier
Instant syntax highlighting and formatting for HTML, CSS, JavaScript, JSON, and XML. Unminify code, fix indentation, and validate syntax client-side.
About
Legacy codebases and minified production assets often present a significant readability challenge. Developers frequently encounter single-line source files where logic flow is obscured by the absence of whitespace. This tool restores structural integrity to raw string data by applying language-specific indentation rules and lexical analysis.
Accuracy in code formatting is not merely cosmetic. It is essential for version control diffing, debugging logic errors, and maintaining architectural standards. A missing bracket or a misaligned block in languages like Python or YAML (though this tool focuses on web standards) can alter execution flow. This utility processes strings locally within the browser, ensuring that sensitive logic or proprietary algorithms are never transmitted to a server. It handles the structural tokenization of n nested levels, transforming messy input into a strictly indented output stream.
Formulas
The indentation logic can be modeled as a function of token depth. For any given line Li, the indentation level di is calculated based on the cumulative state of open and closed delimiters in previous lines:
Where O represents the count of opening tokens (e.g., {, [, <) and C represents closing tokens. The total visual whitespace W is then the product of depth and the user-defined constants for tab width w:
Reference Data
| Language | Block Delimiter | Standard Indentation | MIME Type |
|---|---|---|---|
| HTML5 | Tags < > | 2 Spaces | text/html |
| CSS3 | Braces { ... | 4 Spaces or 1 Tab | text/css |
| JavaScript | Braces/Function Scope | 2 or 4 Spaces | application/javascript |
| JSON | Object/Array [] | 2 Spaces | application/json |
| XML | Tags < > | 2 Spaces | application/xml |
| Minified | None (Newlines removed) | 0 Spaces | n/a |
| Strict Mode | Pragma Directive | Varies | n/a |
| JSX (React) | Component Tags | 2 Spaces | text/jsx |