Skip to main content

CSS Formatter

Format CSS with one consistent style.

CSS input

Ln 1, Col 1
CSS

Result

Your result will appear here

Add CSS above, then choose Format.

Add CSS on the left, then choose Format.

Waiting for input

2 spaces

Format CSS you maintain with one consistent style: the same indentation, spacing and spelling everywhere. Runs the same formatter as CSS Beautifier.

What is CSS Formatter?

CSS Formatter is a free online tool that gives hand-written CSS one consistent style in your browser: the same indentation, one declaration per line, even spacing around colons, commas and braces, and the same spelling for numbers, colors and quotes. Use it before a review or a commit, so a diff shows what you changed and not how the lines happened to be laid out.

CSS Beautifier runs this same formatter, so the same input gives the same result on either page. This page is for CSS you maintain: what each rule selects and sets does not change, your comments and the order of your rules stay, and nothing is repaired, renamed or sorted.

What it supports

  • Standard CSS, including at-rules such as @media, @font-face, @keyframes, @layer and @page, and the native CSS nesting that browsers support. Comments are kept.
  • Indentation of 2 or 4 spaces, never tabs. Line breaks in the result are always the same kind, whatever your text used.
  • What is made uniform: property names and hexadecimal colors in lowercase, double quotes instead of single quotes, even spacing after colons and commas, and a semicolon after the last declaration of each block. A value with several comma-separated parts, such as a transition list, can be put one part per line.
  • Numbers are written in one spelling, so a number may look different afterwards: 0.50px becomes 0.5px, 10.0 becomes 10, .5 becomes 0.5 and 1E3 becomes 1e3. Its value does not change.
  • Names stay as you wrote them: class names and element names in selectors keep their case, and so do the names and the values of custom properties.
  • A run of blank lines becomes one blank line, and the blank lines you keep stay where they are.
  • Nothing is fetched: @import and url() stay as text. Properties and values are not checked against the CSS specifications, so a made-up property is formatted like a real one.

Good to know

  • These are refused, with no result: an unclosed block, string, comment, parenthesis or square bracket; a stray }, ) or ]; and an unquoted url() that contains a space or a quote. The message gives the line and column, and nothing is repaired. A literal ) or ] inside a name or an address has to be written as \) or \]. Parentheses or square brackets nested more than 64 levels deep are refused as well.
  • Sass, SCSS and Less are not supported. A $variable, @mixin, @include, a Less @variable: value, a // comment or #{interpolation} is refused, and a Less mixin call such as .rounded(); is refused as a syntax error. The tool never compiles or converts anything, and it does not detect every Less construct: some look like plain CSS and are formatted as such.
  • A text with only a comment is formatted. A text with only blank lines has nothing to format, so you get a note asking for content.
  • Large files can be slow to format, and minified CSS gets longer when it is formatted. If a run is stopped at the time limit, or the result would pass the size limit, try a smaller input.
  • If indentation would make the result far larger than the size limit, the tool stops before formatting. Use 2 spaces or less nesting.

How do I use CSS Formatter?

  1. Paste or type your CSS in the input box. Nothing runs while you type.
  2. Pick the indentation your project uses, “2 spaces” or “4 spaces”, and press “Format”.
  3. Compare the result with your input. A rule that cannot be read as standard CSS is refused with its line and column, so you can fix it and run the tool again.
  4. Press “Copy” to paste the formatted CSS into your project, or “Download” to save it as formatted.css.

Examples

Bring a hand-written file to one style

Paste the CSS below and press “Format” with “2 spaces” selected. The uneven indentation and the stray spaces go, COLOR becomes color, the hexadecimal colors become lowercase, .5em 1.50em becomes 0.5em 1.5em, the single quotes become double quotes and the missing semicolon after the last declaration is added. The class name .btn keeps its case, and the run of blank lines inside the first rule becomes a single blank line.

.btn   {
        COLOR:#FFF;
   background : #0A66C2;


  padding:.5em  1.50em;
    font-family: 'Inter', sans-serif
}

.btn:hover{background:#084E96}
.btn {
  color: #fff;
  background: #0a66c2;

  padding: 0.5em 1.5em;
  font-family: "Inter", sans-serif;
}

.btn:hover {
  background: #084e96;
}

A stray closing parenthesis

There is one parenthesis too many at the end of the calc(). The tool does not guess which one was meant, so it refuses and points at the extra one.

.a{width:calc(100% - 2rem));}

This closing parenthesis ()) has no matching opening parenthesis. Remove it, or add the opening parenthesis it belongs to. To write a literal parenthesis in a name or an address, escape it as \).

Line 1, column 27

Custom properties stay as written

The value of a custom property (a name that starts with --) means whatever the code that reads it decides, so the tool does not rewrite it: #FFF and 1.50rem stay as written, apart from the spaces around them. Outside a custom property, 1.0em becomes 1em.

:root{--Brand-Color:#FFF;--Gap:  1.50rem }
.btn{color:var(--Brand-Color);padding:var(--Gap) 1.0em}
:root {
  --Brand-Color: #FFF;
  --Gap: 1.50rem;
}
.btn {
  color: var(--Brand-Color);
  padding: var(--Gap) 1em;
}

A Less mixin call

A mixin call is Less, not CSS: to CSS it looks like a declaration with no colon. Less is not supported, so the tool refuses and points at the line where it stopped understanding.

.btn{
  .rounded();
  color:red
}

The CSS is not valid at this point. For example, a declaration has no colon, a rule has no selector, or the text is not CSS at all. CSS is never repaired for you, so fix it and run the action again. This tool formats standard CSS only, so Sass, SCSS and Less syntax can also cause this.

Line 2, column 3

Limits and privacy

Size limits

  • Input: up to 2,000,000 bytes of UTF-8 text (about 2 MB). Accented letters and emoji take more than one byte each. Larger input is rejected.
  • Result: also up to 2,000,000 bytes. If the complete result would be larger, the tool shows only an incomplete preview of the first 100,000 bytes, and that preview cannot be copied or downloaded.
  • Nesting: up to 256 levels of open braces, parentheses and square brackets counted together inside each other. Deeper CSS is refused because it is beyond what the tool processes.
  • Brackets: an independent cap of 64 open parentheses and square brackets counted together, within the combined nesting limit above. Deeper CSS is refused because it is beyond what the tool processes.
  • Time: a run that takes longer than its time limit is stopped. Try a smaller input.

Is my text sent to a server?

No. The text you type or paste, or open from a local file, is processed locally in your browser, in a dedicated Web Worker. It is never uploaded or sent to the server (a file you open is read in your browser only), and it is not written to storage, cookies or the address bar.

“Copy” puts the result on your clipboard and “Download” saves it as a file, but only when you press the button. The file is created in your browser, so nothing is uploaded.

For the full details, see the Privacy Policy

Related tools and pages

Your text stays in the page when you switch tools in the same tab, so you can try the same text in another tool. Reloading or closing the tab ends it.

All tools

Format, validate and convert JSON, YAML, XML, CSV, HTML, CSS and Markdown, plus Base64, URL and JWT.

JSON

  • JSON Formatter

    Format JSON with one consistent layout: even indentation, one value per line, your values untouched. Runs the same formatter as JSON Beautifier.

  • JSON Validator

    Check whether your text is valid JSON. If it is not, see the first problem with its line and column, highlighted in your text.

  • JSON Diff

    Compare two JSON documents by structure, ignoring key order, and see every added, removed and changed path in one list.

  • JSON Schema Validator

    Validate JSON against a JSON Schema (draft 2020-12, or draft-07 through $schema) and see each error with the path where it occurs.

  • JSON Schema Generator

    Generate a JSON Schema (draft 2020-12) from a sample JSON document, ready to copy and refine.

  • JSON Beautifier

    Beautify minified or unevenly spaced JSON into readable, indented text, with your values untouched. Runs the same formatter as JSON Formatter.

Convert JSON

  • JSON to CSV

    Convert a JSON list of objects, or the first list of objects inside an object, to plain CSV text.

  • CSV to JSON

    Convert CSV to a JSON array of objects, using the header row as keys. Comma, semicolon and tab separators are detected, and values stay as text.

  • JSON to XML

    Convert JSON to plain, readable XML, with your numbers and text copied exactly as written.

  • XML to JSON

    Convert XML to JSON, with attributes as @name keys and repeated elements gathered into arrays so the structure carries over.

  • JSON to YAML

    Convert JSON to readable block YAML with 2 or 4 spaces of indentation, keeping every value and every number exactly as you wrote it.

  • YAML to JSON

    Convert YAML to JSON with anchors and aliases resolved. A file with several documents becomes a JSON array.

YAML

  • YAML Validator

    Check whether your YAML is valid under the YAML 1.2 Core rules, in one or several documents, and see the line and column of the first problem.

  • YAML Viewer

    Explore a YAML document as a tree you can open and close, with anchors, tags and aliases marked on the row where they appear.

  • YAML Formatter

    Format YAML with consistent indentation while keeping comments and values.

HTML, XML and CSS

  • HTML Formatter

    Format HTML into readable, indented markup. The result is plain text: scripts do not run and nothing in your HTML is loaded.

  • XML Formatter

    Format XML with clear indentation while preserving its content and meaning.

  • CSS Beautifier

    Beautify minified CSS into readable rules, one declaration per line, without changing what the CSS does. Runs the same formatter as CSS Formatter.

  • CSS Formatter

    Format CSS you maintain with one consistent style: the same indentation, spacing and spelling everywhere. Runs the same formatter as CSS Beautifier.

Encode & Decode

  • Base64 Encode/Decode

    Encode text to Base64 or decode Base64 back to text as UTF-8, with an option for the URL-safe Base64URL alphabet.

  • URL Encode/Decode

    Encode or decode text with %XX sequences, either as a URL component or as a full URL whose separators stay intact.

  • JWT Decoder

    Decode a JWT in your browser to read its header and payload, see the exp, iat and nbf dates and whether it has expired. The signature is not verified.

Markdown

New
  • Markdown Editor

    Free online Markdown editor and viewer: write or open an MD file, see a live GFM preview, then copy or download your Markdown.

  • Markdown to PDF

    Convert Markdown to PDF in your browser. Pick A4 or Letter paper and the margins, preview the document and download a real PDF file.

  • Markdown to Text

    Convert Markdown to plain text without losing code or punctuation. Choose how links appear, then copy the text or download a TXT file.

  • Markdown to Word

    Convert Markdown to Word: download an editable DOCX file that keeps headings, lists, tables and links. It runs in your browser.

  • Markdown to HTML

    Convert Markdown to HTML in your browser. Get an HTML fragment or a full document, check the preview, then copy or download it.

  • Markdown Table Generator

    Markdown table generator with an editable grid and column alignment. Import CSV or TSV, then copy or download the Markdown table.

  • Word to Markdown

    Convert Word to Markdown: open a DOCX file and get its headings, lists, links and tables as editable Markdown, all in your browser.

  • HTML to Markdown

    Convert HTML to Markdown from pasted markup or a local file. Scripts never run; headings, lists, links and simple tables carry over.

  • Markdown Formatter

    Markdown formatter that tidies your source and lists style suggestions for headings, spaces and the final newline. Review it before you copy.

  • Markdown to Image

    Convert Markdown to an image: choose the width and theme, preview your note or table and download a PNG or JPEG file.

  • Markdown to Rich Text

    Convert Markdown to rich text and copy it, formatted, into a document editor. Plain text is the fallback when rich copy is unavailable.

  • Markdown Table to JSON/CSV

    Convert a Markdown table to JSON or CSV. Review the headers and pick each column's type, so IDs and leading zeros stay as they are.

  • Excel to Markdown

    Convert Excel to Markdown: open an XLSX file, pick a sheet or a cell range and get a Markdown table without uploading the file.

  • Markdown to Excel

    Convert Markdown tables to Excel: download an XLSX file whose cells stay text, so leading zeros survive and nothing becomes a formula.

  • Paste to Markdown

    Paste to Markdown: turn copied rich text or HTML into Markdown. For plain text, apply heading and list actions yourself, then copy.

  • Markdown Compare

    Markdown compare: paste two versions or open two files and see which lines were added or removed in the source text.

  • Markdown to Mind Map

    Convert Markdown to a mind map: headings and lists become a map you can navigate and export. Built with Markmap, no account needed.

  • Mermaid Editor

    Mermaid live editor in your browser: write diagram code, see the preview and any syntax errors, and export SVG or PNG without an account.

  • Discord Markdown Preview

    Discord Markdown preview: check bold, code blocks and spoilers in an approximate local preview, then copy the message. No Discord account.

  • Obsidian Markdown Converter

    Obsidian Markdown converter: adapt [[wiki links]] and embeds to standard Markdown and list the files your note refers to.

  • GitHub README Viewer

    GitHub README viewer: paste or open a README, see a GFM preview and set a base URL for relative links. Nothing is fetched from GitHub.

  • PDF to Markdown

    Convert PDF to Markdown locally: extract its text layer or run OCR on selected pages without text. Review and edit before copying or downloading.

  • Image to Markdown

    Convert an image to Markdown with OCR in your browser: read text from a PNG or JPEG, correct it, then copy or download. Accuracy varies.