QuickDevGuide

Home › CSS

Specificity & Inheritance — CSS

Inheritance means child elements inherit certain properties from their parents — primarily text-related properties like color, font-family, font-size, and line-height. Layout properties like margin, padding, and border are NOT inherited. You can force inheritance with the inherit keyword or reset with initial/unset. Specificity Hierarchy Specificity determines which CSS rule wins when multiple rules target the same element. The specificity hierarchy (from highest to lowest): Inline styles (style="...") = 1000 points. ID selectors (#id) = 100 points. Class selectors (.class), attribute selectors ([type="text"]), and pseudo-classes (:hover) = 10 points. Element selectors (p, div) and pseudo-elements (::before) = 1 point. Example: If p { color: red; } and .text { color: blue; } both target…

Key Takeaways