Skip to content

CSS Tutorial CSS Inheritance

CSS Inheritance

Lesson 165 of 182 2 min read By Deepak Paswan Updated Oct 4, 2026

When you set color on a parent, its children get that color without a rule of their own. That is inheritance.

index.html
HTML
<style>
  .card { color: #1a5276; font-family: Georgia, serif; border: 2px solid #d94a00; padding: 10px; }
</style>
<div class="card">
  <h3>The Slow Garden</h3>
  <p>The text, the heading and even this paragraph are blue Georgia. But only the card has a border.</p>
</div>

The color and font went down to the children. The border and the padding did not.

Why some do and some do not

  • Properties about text are mostly inherited, since you want a whole paragraph to look consistent.
  • Properties about boxes are not, since a border on a container should not repeat on every child.
Usually inheritedUsually not inherited
colorbackground
font-family, font-size, font-weightborder
line-heightmargin, padding
text-align, text-transformwidth, height
list-styledisplay, position
visibility, cursoroverflow, opacity

What this means in practice

  • Set your base typography once on body and everything follows.
  • Set a text color on a dark section and every heading and paragraph inside turns light.
  • A box property such as background needs its own rule, or transparent backgrounds let the parent show through.

Some elements break the chain

Form controls (input, button, textarea, select) have their own default font and do not inherit it. Links have their own color from the browser. You fix that with font: inherit and color: inherit. See Form Styling Basics.

lightbulb
Check in the inspector
In the developer tools, the Computed tab can show where a value came from. Inherited values are marked as coming from an ancestor.

Next: inherit, initial, unset and revert let you control this explicitly.