January 05, 2024•CSS
Why isn't my CSS working? I've been staring at it for hours!
cssdebuggingtypos
The Answer: You probably have a typo in your CSS selector or property name! 🤦♂️
This happens to everyone. You write what you think is perfect CSS, but there's a tiny typo that breaks everything.
Common culprits:
-
Typos in class names:
/* You wrote */ .btn-primray { color: blue; } /* But your HTML has */ <button class="btn-primary">Click me</button>
-
Missing semicolons:
.my-class { color: red /* Missing semicolon! */ background: blue; }
-
Wrong property names:
.my-class { text-colour: red; /* Should be 'color' */ font-wieght: bold; /* Should be 'weight' */ }
-
Selector specificity issues:
/* This is more specific and overrides your styles */ div.container .my-class { color: green; } /* Your style gets overridden */ .my-class { color: red; }
How to debug:
- Use browser dev tools - Right-click → Inspect Element
- Check the computed styles - See what's actually being applied
- Look for crossed-out styles - These are being overridden
- Validate your CSS - Use a CSS validator to catch syntax errors
Pro tip: Use a good code editor with CSS IntelliSense. It'll catch most typos before you even save the file!
Remember: CSS is case-sensitive for class names but not for property names. background-Color
works, but .MyClass
and .myclass
are different! 🎨