Mr. Tools

How to

How to use the CSS Formatter

Paste CSS and the formatted version appears on the right at once. If something cannot be read, a band above the input box shows the line and column with the reason, and that line is marked. What you enter is never sent anywhere and stays only on this device.

CSS Formatter thumbnailCSS Formatter thumbnail
Steps
4 steps
Guide
With screenshots
Content
Notes and FAQ

Use Cases

When to use it

  • Make CSS crammed onto one line easy to read
  • Find where a } or a semicolon is missing
  • Minify CSS before publishing to make it smaller
  • Tidy up CSS you got from someone else into a consistent shape

Capabilities

What this tool can do

  • Format pasted CSS at once (Indent space 2, Indent space 4, or Indent tab)
  • Minify by removing spaces, line breaks, and comments, and by writing values in a shorter way
  • Show the line and column of anything that cannot be read, with the reason
  • Keep comments that start with /*! when minifying
  • Copy the result or save it as formatted.css

Steps

Steps

The order of operations and checkpoints are listed so you can proceed while looking at the screen.

STEP 1

Paste your CSS

Paste CSS into the "Input" box on the left. While the box is empty, you can also press "Paste" in the bar at the bottom. There is no convert button: the formatted CSS appears in "Result" on the right at once. You can format a whole file or just a few rules.

Screen with the input box and the result box outlined in red

Checkpoints

  • Formatted CSS appeared in "Result" on the right
  • No red band is showing above the input box

Where to look on screen

01
Paste and sample

"Paste" puts in the CSS you have copied as it is. To try the tool first, "Insert sample" puts in sample CSS.

Screen with "Paste" and "Insert sample" in the bar at the bottom outlined in red

STEP 2

Fix any errors

If something cannot be read, a red band appears above the input box and shows where and why, such as "Line 2, column 14: A semicolon (;) is missing". That line gets a red mark. Fix it as the band says, and the band disappears and the result appears.

Screen with the error band and the marked line outlined in red

Checkpoints

  • The red band is gone
  • Formatted CSS appeared in "Result" on the right

Where to look on screen

01
Error band

Shows the line and column of the mistake and what kind of mistake it is. How to fix each kind is listed below in "Common mistakes and how to fix them".

Screen with the error band above the input box outlined in red

STEP 3

Choose a format

Under "Format" at the top, choose an indent width or Minify. Indented code is best for people to read. Minify is best for making the files you publish smaller.

Screen with the Format menu and the result box outlined in red

Checkpoints

  • The shape of the result fits where you will use it

Where to look on screen

01
Format

Choose from Indent space 2, Indent space 4, Indent tab, and Minify.

Screen with the Format menu outlined in red
02
Minify

Removes spaces, line breaks, and comments to make one line, and also writes values in a shorter way.

Screen with the minified result box outlined in red

STEP 4

Copy or save the result

Check "Result" on the right, then press "Copy", or press "Save" to get a file.

Screen with the result box outlined in red

Checkpoints

  • The result is not cut off

Where to look on screen

01
Copy and Save

"Copy" copies the formatted CSS, and "Save" saves it as formatted.css.

Screen with "Copy" and "Save" in the result box outlined in red

Common mistakes and how to fix them

We entered common typing mistakes and checked the message the band shows for each.

Band message and fix for each mistake
MistakeCSS enteredBand messageHow to fix
Missing }.a { color: red;Line 1, column 1: A { has no matching }Add } at the end
Missing colon.a { color red; }Line 1, column 6: Something here cannot be read. Check the colon (:) after the propertyAdd : after color
Missing semicolon.a { color: red background: blue; }Line 1, column 16: A semicolon (;) is missingAdd ; after red
Extra }.a { color: red; } }Line 1, column 20: There is an extra }Delete the last }
Missing ) in @media@media (max-width:600px { … }Line 1, column 8: A ( has no matching )Add ) after 600px
Missing ) in url(.a { background: url(x.png; }Line 1, column 21: A ( has no matching )Add ) after x.png
Missing selector{ color: red; }Line 1, column 1: There is no selector before {Write a selector such as .a before {

If you enter text that is not CSS, you see "This could not be read as CSS. Check that the pasted text is CSS". An extra semicolon, as in .a{color:red;;}, is not an error and is removed when the CSS is formatted.

How does the character count change with each format?

We compared the formats using the 166 characters of CSS that "Insert sample" puts in (written with an indent of 4 spaces).

Characters by format
FormatCharacters
Indent space 2150
Indent space 4166
Indent tab142
Minify107

Minifying turned 166 characters into 107, about 36% fewer. The more indents and line breaks your CSS has, the more minifying removes.

What changes when you minify?

InputAfter minifying
color: #ffffffcolor:#fff
margin: 0pxmargin:0
/* comment */Removed
/*! license */Kept
An empty .b { }Removed

It does not make shortcuts that change the order of your code, such as merging rules with the same contents.

Notes

Notes

Important points are grouped with reasons so you can make decisions before using the tool.

Missing }

A missing } points to the start of that rule

Follow the code down from the spot in the band to find where the } is missing.

Minify

Minifying also shortens how values are written

#ffffff becomes #fff, and 0px becomes 0. The page looks the same.

Comments

Start a comment with /*! to keep it

Normal comments are removed when you minify. Start license notices and similar comments with /*! and they stay.

FAQ

Questions about CSS Formatter

Questions that make decisions easier before use are summarized first.

How is the error spot shown?

A band above the input box shows where and why, such as "Line 2, column 14: A semicolon (;) is missing". That line gets a mark.

What changes when I minify?

Spaces, line breaks, comments, and empty rules are removed, and values are shortened, such as #ffffff to #fff and 0px to 0. The order of your rules does not change.

Can I keep comments when I minify?

Comments that start with /*! are kept. Use them for license notices and similar text.

Can it format the <style> inside HTML?

This page is for CSS only. To format a whole HTML file, use the HTML Formatter, and the inside of <style> is formatted too.

Is the CSS I enter sent anywhere?

No. Formatting runs in your browser. So you can pick up where you left off after reopening the page, what you enter is kept only in this device's browser.

Next guides

Related guides

Related guides are listed next so you can continue without getting lost.