Skip to content
Aarrange

CSS Validator

Paste CSS or a whole HTML page. See every error with its line and a fix, and which browsers support each feature. Nothing leaves your browser.

0
Rules
0
Advice
0
Errors
Input
Tab types a tab. Press Escape, then Tab, to leave the editor.
Result
The result shows here as you type.Try , or .Checks every property and value against the CSS specs, and says which features are not in all browsers yet.Only to indent CSS, use the CSS Formatter. For the HTML around it, the HTML Validator.
On this page

About CSS Validator

Updated

What is a CSS Validator?

A CSS validator, or CSS checker, compares your style sheet with the CSS specs. It finds properties that do not exist, values a property does not take, a missing semicolon or brace, a calc() with no space around -, and selectors a browser cannot read, such as a >> b or a pseudo-class with a typo. A browser does not tell you about these mistakes. It drops the line and goes on, so the style is simply missing. A validator shows each dropped line and why.

How to use this tool

Paste your CSS, open a file, or drop one on the editor. The tool checks it when you stop typing. Paste a whole HTML page and it checks the CSS in each <style> block and style attribute, at its real line in the page. Attributes such as data-style and Vue :style are not CSS, so the tool does not check them. A style attribute that holds a { is template code, not CSS: the tool skips it, and a note says so.

The Result pane lists each error with its line and column, says what is wrong in plain words, and says how to fix it. For a typo it gives the nearest real name. The editor marks the error you pick, the first one at the start. Click an error in the list to go to it. A value that uses var() is not checked, because its real value is known only in the browser. The Summary counts these values.

Errors and advice

Errors are CSS that a browser drops. Advice is CSS that works, but has a better way: a vendor prefix such as -webkit-appearance that the standard name now replaces, an old name such as color-adjust or word-wrap, or a hack for Internet Explorer such as *zoom. Advice shows with a triangle, in the list and in Notes. Advice never makes the CSS invalid. Turn Prefixes off in Options to hide it.

Browsers

The Browsers view lists every CSS feature in your text, from display: grid to @container, with its Baseline status and the first version of Chrome, Firefox and Safari that has it. Limited features come first: they are missing from at least one browser, so give those browsers a fallback. Newly available features work in all current browsers, but not in older ones. The number at the end of each row is the line of the first use. Click a feature, or press Enter on it, to go to that line. The Notes view lists the advice and a note for each Limited and Newly available feature. Turn each kind off in Options: Prefixes, Limited and New.

Fix and Format

Fix repairs only what has one safe answer. It changes a misspelled property, keyword or unit to the one real name it is close to, such as colr to color and 10xp to 10px, and a common wrong name such as font-color to color. It adds a missing ; or :, deletes the space in 6 px, corrects !imprtant, and deletes a stray }. For a block that was never closed, it adds the } at the end of the text, or at the end of its <style> block. This keeps what the browser reads now. Then move the } to where the block should end. In an HTML page it changes only the CSS, never the quotes of a style attribute. It does not guess a color, a number or a unit: only you know what #fffff should be, or which unit width: 100 needs. Undo takes back Fix and Format.

Format indents the CSS with 2 spaces, 4 spaces or tabs. On an HTML page it formats the whole page as HTML, with the CSS in each <style> block, as the HTML Formatter does. For more format options, use the CSS Formatter. To check the HTML around your CSS, use the HTML Validator.

Common CSS errors

A missing semicolon

Each declaration ends with ;. Without it, the next line becomes part of the value, and the browser drops both. The last declaration in a block may leave it out, but it is safer to always write it.

Invalid
.card h2 {
  font-size: 1.25rem
  margin-bottom: 0.5rem;
}
Fixed
.card h2 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

A typo in a property or a value

A browser does not know colr or flexx, so it drops the line without a word. The tool gives the nearest real name.

Invalid
.button {
  colr: #222;
  display: flexx;
}
Fixed
.button {
  color: #222;
  display: flex;
}

A space between a number and its unit

6 px is two values: the number 6 and the word px. A length needs the unit right after the number.

Invalid
.button { border-radius: 6 px; }
Fixed
.button { border-radius: 6px; }

A block that is never closed

Every { needs its }. When a @media block is not closed, all rules after it count as inside it, so they apply only at that screen width. Fix adds the } at the end of the text. If the rules after the block belong outside it, move the } up to where the block ends, as in the example below.

Invalid
@media (max-width: 600px) {
  .grid {
    grid-template-columns: 1fr;
  }

.footer {
  text-align: center;
}
Fixed
@media (max-width: 600px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

.footer {
  text-align: center;
}

A value the property does not take

padding cannot be negative, z-index takes whole numbers only, and a hex color has 3, 4, 6 or 8 digits. The error says what the property takes.

Invalid
.card {
  padding: -4px;
  z-index: 2.5;
  color: #fffff;
}
Fixed
.card {
  padding: 4px;
  z-index: 3;
  color: #ffffff;
}

This tool and the W3C CSS validator

The W3C CSS Validation Service has checked CSS since 1997, and many people still use it. We ran both on the same files. On a test file with eight mistakes, both found all eight. W3C gave the line of each error. This tool gave the line and column, a fix line for each, and repaired five of them with Fix.

On a file of valid modern CSS, W3C gave 7 errors: for @container, container-type, @property, view-transition-name, anchor-name, position-anchor and anchor(). All of these work in current browsers, and this tool passed the file. W3C also sends your CSS to its server. This tool runs in your browser, so you can check CSS that is not public yet.

Other CSS resources

CSS Validator FAQ

How do I validate my CSS?

Paste the CSS in the editor, open a .css file, or drop one on it. You can also paste a whole HTML page: the tool checks the CSS in its <style> blocks and style attributes. The check runs when you stop typing and lists every error at once, each with its line, column and a sentence on how to fix it. Click Fix to repair the safe ones. CSS with no errors gets the words Valid CSS.

How do I fix CSS errors?

Start with the first error in the list: one missing ; or } can make the browser drop the lines after it. Read the fix line under each error. A typo in a property or a keyword gets the nearest real name, such as color for colr. Click Fix to repair a typo with one clear answer (also in a unit, such as 10xp, and a common wrong name, such as font-color), a missing semicolon, a space between a number and its unit, and an unclosed block. Fix adds the missing } at the end of the text, so the browser reads the CSS the same way; move it to where the block should end. Errors that need a choice, such as a color with five hex digits or a number with no unit, stay for you.

Is this the same as the W3C CSS validator?

No, but it checks the same thing: your CSS against the CSS specs. The W3C CSS Validation Service at jigsaw.w3.org is the classic reference. It sends your CSS to its server and gives the line of each error. Its grammar is behind the browsers, so it reports valid modern CSS as errors. On our test file of modern CSS it gave 7 false errors, for @container, @property, anchor() and other features that all current browsers have. This tool gives line and column, a fix for each error, and browser support, in your browser.

Why does a validator say my valid CSS is wrong?

CSS grows each year, and a validator only knows the grammar it was built with. A checker that is a few years behind reports new properties, functions and at-rules as errors, even when every browser reads them. This tool uses css-tree, which follows the current specs, and checks each feature against Baseline data. A value it cannot check yet, such as one with var(), is counted under Not checked, never called an error.

What does Baseline mean?

Baseline is a label from the W3C WebDX group for when a web feature works in Chrome, Edge, Firefox and Safari. Widely available: in all of them for 2.5 years or more. Newly available: in all of them, but only recently, so older browsers lack it. Limited: missing from at least one. The Browsers view lists each feature in your CSS with its status and the first browser versions that have it. Turn the notes for each group on or off in Options.

Are vendor prefixes errors?

No. -webkit-, -moz- and -ms- names are valid CSS: the specs allow a prefix for each browser. Here they are advice. The note says which browsers read the prefixed name and whether the standard name now works everywhere, so you can delete the old line. Old Internet Explorer hacks such as *zoom and _height are advice too. Turn Prefixes off in Options to hide them.

Can it check Sass, SCSS or Less?

No, and it says so. Sass and Less are languages that build to CSS. A browser cannot read $brand, @include or darken(), so the tool marks them as errors with the words Sass or Less, not as random typos. Build the file first, then check the CSS it makes. Nesting is real CSS now, so nested rules pass, also rules that start with a tag name such as p.

Is my CSS uploaded?

No. The check runs in your browser with css-tree, an open source CSS parser, and the browser data comes from the web-features package. Your CSS stays on your computer. A few seconds after the page has loaded, the checker is in your browser, and you can go offline and still validate.