Lorem ipsum dolor sit amet.
--- url: "https://web.dev/learn/css/inheritance" titulek: "Inheritance | web.dev" h1: "Inheritance Stay organized with collections Save and categorize content based on your preferences." popis: "Some CSS properties inherit if you don't specify a value for them. Find out how this works, and how to use it to your advantage in this module." jazyk: "en" kanonicka: "https://web.dev/learn/css/inheritance" drobecky: ["web.dev", "Resources", "CSS"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 01:48:34" znaku: 10059 slov: 1412 kodovani: "utf-8" sha256: "58762f4cfdf50279c6684055d4dc73f0471392007c8570a762ce7750075725e3" --- Inheritance Stay organized with collections Save and categorize content based on your preferences. [The CSS Podcast - 005: Inheritance](https://thecsspodcast.libsyn.com/005-inheritance) Say you just wrote some CSS to make elements look like a button. `I am a button link``.my-button { display: inline-block; padding: 1rem 2rem; text-decoration: none; background: pink; font: inherit; text-align: center; }` You then add a link element to an article of content, with a `class` value of `.my-button`. However there's an issue, the text is not the color that you expected it to be. How did this happen? Some CSS properties inherit if you don't specify a value for them. In the case of this button, it **inherited** the `color` from this CSS: `article a { color: maroon; }` In this lesson you'll learn why that happens and how inheritance is a powerful feature to help you write less CSS. Inheritance flow Take a look at how inheritance works, using this snippet of HTML: `
Lorem ipsum dolor sit amet.
` has italic text, because it's the deepest nested element. Inheritance only flows downwards, not back up to parent elements. Which properties are inherited by default? Here is the entire list of properties that are inherited by default, taken from the W3 reference of all CSS properties: [azimuth](https://developer.mozilla.org/docs/Web/SVG/Attribute/azimuth) [border-collapse](https://developer.mozilla.org/docs/Web/CSS/border-collapse) [border-spacing](https://developer.mozilla.org/docs/Web/CSS/border-spacing) [caption-side](https://developer.mozilla.org/docs/Web/CSS/caption-side) [color](https://developer.mozilla.org/docs/Web/CSS/color) [cursor](https://developer.mozilla.org/docs/Web/CSS/cursor) [direction](https://developer.mozilla.org/docs/Web/CSS/direction) [empty-cells](https://developer.mozilla.org/docs/Web/CSS/empty-cells) [font-family](https://developer.mozilla.org/docs/Web/CSS/font-family) [font-size](https://developer.mozilla.org/docs/Web/CSS/font-size) [font-style](https://developer.mozilla.org/docs/Web/CSS/font-style) [font-variant](https://developer.mozilla.org/docs/Web/CSS/font-variant) [font-weight](https://developer.mozilla.org/docs/Web/CSS/font-weight) [font](https://developer.mozilla.org/docs/Web/CSS/font) [letter-spacing](https://developer.mozilla.org/docs/Web/CSS/letter-spacing) [line-height](https://developer.mozilla.org/docs/Web/CSS/line-height) [list-style-image](https://developer.mozilla.org/docs/Web/CSS/list-style-image) [list-style-position](https://developer.mozilla.org/docs/Web/CSS/list-style-position) [list-style-type](https://developer.mozilla.org/docs/Web/CSS/list-style-type) [list-style](https://developer.mozilla.org/docs/Web/CSS/list-style) [orphans](https://developer.mozilla.org/docs/Web/CSS/orphans) [quotes](https://developer.mozilla.org/docs/Web/CSS/quotes) [text-align](https://developer.mozilla.org/docs/Web/CSS/text-align) [text-indent](https://developer.mozilla.org/docs/Web/CSS/text-indent) [text-transform](https://developer.mozilla.org/docs/Web/CSS/text-transform) [visibility](https://developer.mozilla.org/docs/Web/CSS/visibility) [white-space](https://developer.mozilla.org/docs/Web/CSS/white-space) [widows](https://developer.mozilla.org/docs/Web/CSS/widows) [word-spacing](https://developer.mozilla.org/docs/Web/CSS/word-spacing) Other CSS properties are not inherited by default. How inheritance works Every HTML element has every CSS property defined by default with an initial value. An initial value is a property that's not inherited and shows up as a default if the cascade fails to calculate a value for that element. Properties that can be inherited cascade downwards, and child elements get a computed value which represents its parent's value. This means that if a parent has `font-weight` set to `bold`, all child elements will be bold, unless: The child element has set a `font-weight` that's a different value. The user agent stylesheet defines a `font-weight` for that element. Explicitly inherit and control inheritance Inheritance can affect elements in unexpected ways. The `inherit` keyword You can make any property inherit its parent's computed value with the `inherit` keyword. A useful way to use this keyword is to create exceptions. `strong { font-weight: 900; }` This CSS snippet sets all `` elements to have a `font-weight` of `900`, instead of the default `bold` value, which would be the equivalent of `font-weight: 700`. `.my-component { font-weight: 500; }` The `.my-component` class sets `font-weight` to `500` instead. To make the `` elements inside `.my-component` also `font-weight: 500` add: `.my-component strong { font-weight: inherit; }` Now, the `` elements inside `.my-component` have a `font-weight` of `500`. You could explicitly set this value, but if you use `inherit` and the CSS of `.my-component` changes in the future, you can guarantee that your `` element automatically stays up to date with it. The `initial` keyword Inheritance can cause problems with your elements and `initial` provides you with a powerful reset option. You learned earlier that every property has a default value in CSS. The `initial` keyword sets a property back to that initial, default value. `aside strong { font-weight: initial; }` This snippet removes the bold weight from all `` elements inside an `