Cascade & Inheritance

The Cascade

When several rules set the same property on an element, the browser decides in this order:

  1. Importance: !important declarations win.
  2. Specificity: the more specific selector wins.
  3. Source order: if specificity is equal, the rule written last wins.

Inheritance

Example

Some properties (mostly text-related: color, font, line-height) are inherited by children; others (border, padding, background) are not:

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    .parent { color: #1971c2; font-family: Georgia; border: 2px solid #1971c2; padding: 8px; }
    .child-inherit-border { border: inherit; }
  </style>
</head>
<body>

<div class="parent">
  Parent text
  <p>Child paragraph: inherits color and font, but not the border.</p>
  <p class="child-inherit-border">This child forces border: inherit.</p>
</div>

</body>
</html>

Result