CSS Errors
Unlike most programming languages, CSS never "crashes". When the browser meets something it does not understand, it quietly ignores that part and carries on. This is great for robustness — old browsers simply skip new features — but it means your mistakes produce no error message. The style just does not appear.
Learning how the browser recovers from errors makes debugging much faster.
How the browser recovers
| Mistake | What gets ignored |
|---|---|
Unknown property (colr: red;) |
Just that declaration |
Invalid value (color: blu;) |
Just that declaration |
| Missing semicolon between declarations | The broken declaration and the one after it |
Missing closing brace } |
Everything until a matching } is found — often the next rule |
Invalid selector (p..intro) |
The whole rule |
One invalid selector in a group (h1, p..x) |
The whole grouped rule |
Invalid properties and values
A typo in a property name or a value makes the browser drop only that one declaration. The rest of the rule still works.
<!DOCTYPE html>
<html>
<head>
<style>
.box {
font: 20px sans-serif;
padding: 16px;
backgound: lightblue; /* typo in property: ignored */
color: dakrred; /* typo in value: ignored */
border: 3px solid green; /* still works */
}
</style>
</head>
<body>
<div class="box">Find the two typos and fix them.</div>
</body>
</html>Missing semicolons
The semicolon is what separates declarations. Without it, the browser reads two declarations as one long, invalid value — and drops both.
<!DOCTYPE html>
<html>
<head>
<style>
p {
font: 20px sans-serif;
color: white
background: purple; /* lost together with color */
padding: 12px;
}
</style>
</head>
<body>
<p>Add the missing semicolon after "white".</p>
</body>
</html>The browser sees color: white background: purple;, which is not a valid color, so neither declaration applies. Notice that the text appears black on white.
Missing braces
A missing } is more destructive. The parser keeps reading the following rule as if it were still inside the first one, so the next rule is usually lost.
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: sans-serif; }
h1 {
color: crimson;
/* missing } here */
p {
color: white;
background: teal;
padding: 10px;
}
.after { color: orange; font-size: 24px; }
</style>
</head>
<body>
<h1>Heading</h1>
<p>I should be white on teal.</p>
<p class="after">Am I orange?</p>
</body>
</html>Look carefully: the p rule is swallowed into the h1 block, where p { is nonsense. Add the missing brace and everything comes back.
Invalid selectors break the whole group
If one selector in a comma-separated list is invalid, the entire rule is thrown away. This catches people out when they combine a modern pseudo-class with an old one.
/* if a browser does not know :fancy, NOTHING here applies */
h1, h2, p:fancy {
color: navy;
}Debugging checklist
- Open DevTools (F12 or right-click → Inspect). Select the element and look at the Styles panel. Invalid declarations are shown crossed out with a warning icon.
- Check spelling of property names and values.
- Check punctuation: every declaration needs
:and;, every block needs{and}. - Check the selector really matches your HTML — a class in HTML is
class="card", in CSS it is.card. - Check whether another rule wins. DevTools shows overridden declarations with a strike-through.
- Validate your stylesheet with an online CSS validator if all else fails.
Tip: Format your CSS with one declaration per line. Missing semicolons and braces are much easier to spot that way, and editors can highlight them.
Test yourself
What does the browser do with colr: red;?
- Shows an error page
- Ignores that declaration only
- Ignores the whole stylesheet
- Guesses you meant
color
In color: red background: blue;, which declarations apply?
- Both
- Only color
- Only background
- Neither
Where can you see which CSS declarations were rejected as invalid?
- In the browser DevTools Styles panel
- In the HTML source
- In the page title
- Nowhere - it is impossible to tell