Sometimes CSS styles don't show up because other styles are stronger. Debugging specificity helps find and fix these conflicts.
Debugging specificity issues in CSS
/* No special syntax, but understanding selector types helps */ selector { property: value; }
Specificity depends on the type of selector: inline styles, IDs, classes, elements.
More specific selectors override less specific ones.
p { color: blue; }
.class { color: red; }
#id { color: green; }div p { font-size: 16px; }
.container p { font-size: 18px; }p { margin: 10px; }
p.special { margin: 5px; }This example shows three paragraphs. The first uses a simple element selector, so text is blue. The second uses a class, which is more specific, so text is red. The third uses an ID and a class; the ID is most specific, so text is green.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Debug Specificity</title> <style> p { color: blue; } .highlight { color: red; } #unique { color: green; } </style> </head> <body> <p>This text is blue.</p> <p class="highlight">This text is red because of the class.</p> <p id="unique" class="highlight">This text is green because ID is more specific.</p> </body> </html>
Use browser DevTools (right-click element -> Inspect) to see which CSS rules apply and their specificity.
Inline styles (style="...") have the highest specificity but should be used sparingly.
Adding !important can force a style but can make debugging harder; use it only when necessary.
Specificity decides which CSS rule wins when multiple rules target the same element.
ID selectors are stronger than class selectors, which are stronger than element selectors.
Use browser tools to check and fix specificity problems easily.