CSS TutorialLesson #11
CSS Errors
Errors in CSS can lead to unexpected behavior or styles not being applied correctly.
Errors in CSS can lead to unexpected behavior or styles not being applied correctly.
This page shows common CSS mistakes, and how to avoid them.
Missing Semicolons
Forgetting a semicolon at the end of a property declaration can break the style rule.
Example
Example Code
css.bad {
color: red
background-color: yellow;
}Invalid Property Names
Using a property name that does not exist will simply be ignored by the browser.
Example
Example Code
css.bad {
colr: blue;
font-size: 16px;
}Invalid Values
Correct properties but invalid values will also be ignored.
Example
Example Code
css.bad {
width: -100px;
color: green;
}Unclosed Braces
If you forget to close a brace }, the entire rule may be ignored.
Example
Example Code
css.bad {
padding: 20px;
margin: 10px;Extra Colons or Braces
Typos like extra colons or misplaced braces can cause rules to break.
Example
Example Code
css.bad {
color:: blue;
}Tips to Avoid CSS Errors
- Use a code editor with syntax highlighting.
- Validate your CSS with a CSS linter or validator.
- Write CSS in small sections and test frequently.
Interactive Code Examples
CSS Example 1
cssInteractive runnable CSS example from EA Academy.
Live Output Preview:
CSS Example 2
cssInteractive runnable CSS example from EA Academy.
Live Output Preview:
CSS Example 3
cssInteractive runnable CSS example from EA Academy.
Live Output Preview:
CSS Example 4
cssInteractive runnable CSS example from EA Academy.
Live Output Preview:
CSS Example 5
cssInteractive runnable CSS example from EA Academy.
Live Output Preview: