Multi-Language Code Beautifier
Auto-detects HTML, CSS, JavaScript, PHP & JSON β formats instantly in the browser.
Live version: https://neikiri.dev/polyglot-formatter
Polyglot Formatter is a browser-based code beautifier that automatically detects the dominant language of your input and formats it with a single click. It supports HTML, CSS, JavaScript, PHP and JSON β including nested code blocks like <style> and <script> inside HTML, or mixed PHP/HTML files.
Everything runs client-side β no server, no build step, no account required.
- Auto-detection β Automatically identifies HTML, CSS, JavaScript, PHP and JSON
- Deep formatting β Formats nested
<style>/<script>blocks inside HTML, and structural PHP logic inside mixed files - Configurable indent β Choose between 2 or 4 spaces
- Line wrapping β Adjustable wrap length (40β300 characters)
- Preserve newlines β Option to keep existing line breaks in string values
- Deep mode β Optional aggressive formatting of nested string payloads (with safety warnings)
- Preserve quoted keys β Keeps JSON keys quoted as-is
- Syntax highlighting β Output is highlighted with Prism.js (Tomorrow Night theme)
- CodeMirror editor β Input editor with line numbers, bracket matching and auto-close
- Copy to clipboard β One-click copy of the formatted output
- Responsive layout β Panels stack vertically on mobile devices
- Dark theme β Material Darker color scheme throughout
- Post-format validation β Warns about potential issues after formatting
| Language | Detection | Formatting | Highlighting |
|---|---|---|---|
| HTML | <tag>, <!DOCTYPE> |
js-beautify html |
Prism markup |
| CSS | Selectors, @ rules |
js-beautify css |
Prism css |
| JavaScript | const, let, function⦠|
js-beautify js |
Prism javascript |
| PHP | <?php, <?= |
Custom PHP formatter | Prism php |
| JSON | Valid {β¦} / [β¦] |
JSON.parse + pretty-print |
Prism json |
No build step is required. Clone the repo and open index.html in your browser:
git clone https://github.com/neikiri/polyglot-formatter.git
cd polyglot-formatterThen open index.html in any modern browser. That's it.
All dependencies (CodeMirror, Prism.js, js-beautify) are loaded from CDN β no
npm installneeded.
- Paste or type code into the left Input panel.
- The editor auto-detects the language and switches syntax mode.
- Adjust options in the toolbar if needed:
- Indent β 2 or 4 spaces
- Preserve Newlines β prevents Deep Mode from adding line breaks inside strings
- Wrap β maximum line length before wrapping
- Deep mode β aggressive formatting of nested strings (use with caution)
- Preserve quoted keys β keeps JSON keys quoted
- Click Format.
- The formatted result appears in the right Output panel with syntax highlighting.
- Click Copy Output to copy the result to your clipboard.
Default formatting options are defined in js/config.js:
const APP_CONFIG = {
defaults: {
indentSize: 2,
preserveNewlines: true,
wrapLineLength: 120,
safeMode: true,
deepMode: false,
preserveQuotedKeys: true,
deepStringValues: false
}
};All options can be changed at runtime through the UI toolbar.
| Library | Version | Purpose |
|---|---|---|
| CodeMirror | 5.65.16 | Input code editor |
| Prism.js | 1.29.0 | Output syntax highlighting |
| js-beautify | 1.15.1 | HTML / CSS / JS formatting engine |
Pull requests are welcome. See CONTRIBUTING.md for details.
This project is still a work in progress and Iβm fully aware that the formatter currently contains a number of bugs and edge cases.
Building a reliable multi-language formatter (HTML β CSS β JS β PHP β JSON) is much more complex than I initially expected. Itβs very difficult to handle all possible nested combinations without introducing errors, and honestly β I underestimated how hard this problem really is.
Because of that, Iβd really appreciate your help π
If you find any bugs, broken formatting, or unexpected behavior, please report them here: π https://github.com/neikiri/polyglot-formatter/issues
Every report helps improve the project.
This project is licensed under the MIT License β see the LICENSE file for details.
neikiri GitHub: https://github.com/neikiri
π§ Email: neikiri@neikiri.dev

