CSS Errors
CSS Errors
CSS errors are common, especially when you are learning. Unlike HTML, CSS does not show clear error messages, so styles may fail silently.
When CSS does not work as expected, it is usually caused by small syntax mistakes, incorrect selectors, or rule conflicts.
Missing Semicolons
Each CSS declaration should end with a semicolon. Missing semicolons can cause rules to be ignored.
p {
color: blue
font-size: 16px;
}
The corrected version:
p {
color: blue;
font-size: 16px;
}
Incorrect Property Names
If a property name is incorrect, the browser will ignore it.
p {
text-colour: red;
}
The correct property name is:
p {
color: red;
}
Invalid Values
CSS properties accept specific values. Invalid values will be ignored by the browser.
h1 {
font-size: big;
}
A valid example:
h1 {
font-size: 32px;
}
Selectors Not Matching
If your selector does not match any HTML elements, the styles will not be applied.
.box {
background: yellow;
}
If no element uses class="box", this rule has no effect.
Forgetting to Link CSS
One of the most common mistakes is forgetting to link the CSS file to the HTML document.
<link rel="stylesheet" href="styles.css">
Make sure the file path is correct and the CSS file actually exists.
Overridden Styles
Sometimes CSS works, but another rule overrides it due to specificity or source order.
p {
color: red;
}
p {
color: blue;
}
The second rule wins because it appears later in the stylesheet.
Debugging Tips
- Check your CSS syntax carefully
- Use browser developer tools to inspect elements
- Disable rules one by one to find conflicts
- Keep your CSS clean and organized
What’s Next?
Next, you will start learning how to work with colors in CSS.