Inheritance: Which Properties Pass Down and Why
How properties pass from parent to child: which inherit and which don't, why children inherit computed values (the line-height trap), why inherited values lose to any matching rule, why form controls ignore your fonts, and special cases.
kvi5hnuCode Sprout team member9 min readOn this page
Set font-family on <body>, and every paragraph, heading and list item uses that font, although no rule mentions them. That's inheritance: for some properties, an element without its own value takes the value of its parent. It's why a stylesheet can be short, and also the cause of some confusing results.
What inheritance does
The cascade (article 17) picks a value for each property of each element from the rules that match it. When no rule sets a property for an element, there are two possibilities:
- If the property is inherited, the element takes the value of its parent.
- If it isn't, the element takes the property's initial value, defined by the specification:
transparentforbackground-color,0formargin,noneforborder-style.
.promo {
color: #8a3b12; /* inherited */
font-family: Georgia, serif; /* inherited */
border: 2px solid #f4c95d; /* not inherited */
padding: 0.75rem; /* not inherited */
}
The heading, paragraph and <em> take the color and font of the <div>, but they don't each get a border and padding. Inheritance passes values down the tree, through every level, until an element sets its own value. Values never flow upward, from a child to its parent.
Which properties inherit
The rule of thumb: text properties inherit, box properties don't. If borders or padding were inherited, every nested element would get its own border.
| Inherited | Not inherited |
|---|---|
color | background and its longhands |
font and all font properties | border, margin, padding |
line-height, letter-spacing, word-spacing | width, height and their min and max |
text-align, text-indent, text-transform, text-shadow | display, position, float, overflow |
white-space, word-break, hyphens | box-shadow, outline, opacity |
direction, writing-mode | transform, filter, z-index |
visibility, cursor | grid and flexbox properties |
list-style and its longhands | vertical-align, text-decoration |
border-collapse, border-spacing, caption-side | content, counter-reset, counter-increment |
quotes, color-scheme, accent-color | animation, transition |
custom properties (--name) |
When you're unsure about a property, check its MDN page: the "Formal definition" section says Inherited: yes or no. Custom properties inherit unless they're registered with inherits: false (article 28).
Children inherit computed values
A child doesn't inherit the value as you wrote it. It inherits the parent's computed value: a relative value already resolved as far as possible. Usually that's what you want, but it has one well-known trap:
body { font-size: 1rem; line-height: 150%; } /* computes to 24px for a 16px font */
h1 { font-size: 2.5rem; } /* 40px text, but still a 24px line height */
The percentage is computed once, on <body>, and every descendant inherits the resulting length, so large headings get a line height smaller than their text, and their lines overlap. The same happens with em values. A unitless number avoids it, because the number itself is inherited and each element multiplies it by its own font size:
.percent { line-height: 150%; }
.number { line-height: 1.5; }
div { font-family: Georgia, serif; font-size: 16px; margin-bottom: 1rem; }
h2 { font-size: 2.2rem; margin: 0; width: 18rem; }
This is why line-height is almost always written as a plain number (article 45).
Inherited values lose to any matching rule
An inherited value has no specificity at all. Any declaration that matches the element itself, however weak its selector, beats it:
#toolbar { color: white; background: #1a1a1a; }
a:link { color: #1d4ed8; } /* a weak selector, but it matches the link itself */
Links inside #toolbar are blue, not white. #toolbar is far more specific, but its color only reaches the link through inheritance, and the a:link rule applies directly. The browser's own stylesheet works the same way: its a:link color beats the color inherited from your toolbar. Fix it with a rule for the links themselves:
#toolbar a { color: inherit; } /* take the parent's value explicitly */
The same thing makes * rules dangerous. * { color: #333; } matches every element, so it beats every inherited color, and setting color on a container no longer affects the text inside its children.

In both left panels, the inherited value is there, but a rule from the browser's stylesheet matches the element itself and wins.
Elements that ignore inheritance
The browser's default stylesheet sets some inherited properties directly on certain elements, which blocks inheritance for them:
-
Form controls (
<button>,<input>,<select>,<textarea>) get their own font, size and color, so they don't follow the page's font. That's why many resets include:cssbutton, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; } -
Links get a color for
:linkand:visited. -
Headings get a
font-sizeandfont-weight, and<strong>,<em>and<code>get font changes. -
Tables inherit normally in standards mode. In quirks mode, the mode used without a doctype, table cells don't inherit some font properties, one more reason to always use
<!doctype html>.
DevTools show what's going on: the Styles pane lists the default stylesheet's rules as "user agent stylesheet", and groups inherited rules under Inherited from headings (article 4).
Special cases
A few properties aren't inherited but still affect descendants:
text-decorationisn't inherited, but an underline is drawn across all the inline content of the element, including its children. A child can't remove it withtext-decoration: none; it can only add its own decoration. To avoid underlining part of the text, put the decoration on a smaller element instead.opacityisn't inherited, but it applies to the element and everything inside it as one group. A child of a 50% transparent element can't become opaque again.visibilityis inherited, and a child of a hidden element can setvisibility: visibleto show itself. That's unlikedisplay: none, which removes the whole subtree.- The background of
<body>is propagated to the canvas, the whole browser window, when<html>has no background of its own (article 48). That's why abodybackground covers the full viewport even when the body is short.

The first two children try to opt out and can't. The third can, because visibility really is inherited and the child's own value replaces it.
Pseudo-elements such as ::before, ::marker and ::first-line inherit from the element they belong to. In web components, inheritance follows the flattened tree: slotted children inherit from the slot they're shown in, and shadow trees inherit from their host (article 14).
Controlling inheritance
You can force or prevent inheritance for any property with the global keywords (article 18):
.card a { color: inherit; } /* take the parent's color */
.reset-box { all: unset; } /* inherit inherited properties, reset the rest */
.wide { line-height: initial; } /* the property's initial value */
Inheritance also makes a good design tool: set fonts, color and line height once, on <body> or :root, and override them only where a component needs something different.
What's current
- Inheritance works the same in all browsers, as it has since CSS 1.
font: inheritfor form controls is in nearly every modern reset.- Registered custom properties (
@property) can opt out of inheritance withinherits: false, which is Baseline since July 2024.
Common questions
Why doesn't my <button> use the page's font?
The browser's stylesheet sets a font directly on form controls, and a direct declaration beats an inherited value. Add button, input, select, textarea { font: inherit; } to your base styles.
Why are links inside my colored box still blue?
The browser's a:link rule matches the link directly, and any matching rule beats an inherited value, however specific the rule on the box is. Use .box a { color: inherit; }.
Is background-color inherited?
No. Its initial value is transparent, so a child shows the parent's background through itself, which looks like inheritance but isn't. That difference matters when you read the value in DevTools or with getComputedStyle().
opacity isn't inherited, so why does a parent with opacity: 0.5 fade its children?
Because opacity applies to the parent's whole rendering, children included, after they're painted. The children's own opacity still computes to 1, and setting it to 1 can't make them more opaque than the faded group they're painted in (article 31). To fade only the background, use a translucent color such as rgb(0 0 0 / 0.5).
How can I tell whether a property inherits? Look at the "Formal definition" on its MDN page, or set it on a parent and see what the child's Computed tab shows. Inherited values are listed in the Styles pane under "Inherited from".
Summary
- When no rule sets a property, inherited properties take the parent's value, and others take their initial value.
- Text-related properties inherit. Box, layout and background properties don't.
- Children inherit computed values, so use unitless
line-heightvalues to avoid fixed line heights inherited by larger text. - Inherited values have no specificity, so any matching rule, including the browser's defaults and
*, beats them. - Form controls and links have default styles that block inheritance. Use
inheritto restore it. text-decorationandopacityaren't inherited but still affect descendants, while a hidden element's child can becomevisibleagain.
Practice questions
A navigation bar has the rule below. The links in it are blue, and the search button uses a different font. Explain both, and fix them.
nav { color: white; font-family: system-ui; }
Answer
The browser's default styles set a color on links and a font on buttons directly, and those declarations beat values the elements would inherit. Fix with nav a { color: inherit; } and nav button { font: inherit; }, or a global rule for form controls.
What's the line height of an <h2> with font-size: 36px inside this article, and how would you make it scale?
article { font-size: 18px; line-height: 2em; }
Answer
36px. 2em computes to 36px on the article, and the <h2> inherits that length, so its line height equals its font size, which is cramped. Use line-height: 2 (unitless), so the heading computes 2 × 36px = 72px, or set a separate line height on headings.
Why does the first rule stop the second from coloring the text inside <div class="alert"><p>Payment failed</p></div>?
* { color: #333; }
.alert { color: #b3261e; }
Answer
The <p> would get the red color only by inheritance, but * matches the <p> itself, and any matching declaration beats an inherited value. The paragraph is #333. Set colors on body instead of *, so they're inherited and don't block anything.
Which of these does a child element inherit from its parent: padding, font-style, border, cursor, background-image, visibility?
Answer
font-style, cursor and visibility.
Previous: Specificity: How CSS Decides Which Selector Wins
Next: The Cascade: Origins, !important, Inline Styles and Source Order

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.