Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Inheritance | Selecting and Targeting Elements
CSS Foundations

bookInheritance

When you apply CSS to an element, certain properties are automatically passed down to its child elements. This process is called inheritance. Inheritance helps you keep your stylesheets cleaner and more efficient, because you do not need to repeat common styles for every element.

index.html

index.html

style.css

style.css

copy

Not all CSS properties are inherited. Inheritable properties include those related to text and font, such as color, font-family, and font-size. These properties will be passed from a parent element to its children unless specifically overridden. For instance, if you set color on a parent <div>, all text inside that <div> will display in that color unless a child element has its own color rule.

Non-inheritable properties are usually those that affect the layout or the box model, such as border, margin, padding, and background-color. These properties apply only to the element you select, not to its children. In the example above, the border and background-color set on .parent do not affect the <p> or <span> elements inside it.

Understanding which properties inherit by default allows you to write CSS more efficiently and predict how your styles will cascade throughout your HTML structure.

question mark

Which CSS property is typically inherited by child elements?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 7

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you give examples of how inheritance works in CSS?

Which CSS properties are inherited by default?

How can I override inherited styles for a specific element?

Awesome!

Completion rate improved to 6.67

bookInheritance

Swipe to show menu

When you apply CSS to an element, certain properties are automatically passed down to its child elements. This process is called inheritance. Inheritance helps you keep your stylesheets cleaner and more efficient, because you do not need to repeat common styles for every element.

index.html

index.html

style.css

style.css

copy

Not all CSS properties are inherited. Inheritable properties include those related to text and font, such as color, font-family, and font-size. These properties will be passed from a parent element to its children unless specifically overridden. For instance, if you set color on a parent <div>, all text inside that <div> will display in that color unless a child element has its own color rule.

Non-inheritable properties are usually those that affect the layout or the box model, such as border, margin, padding, and background-color. These properties apply only to the element you select, not to its children. In the example above, the border and background-color set on .parent do not affect the <p> or <span> elements inside it.

Understanding which properties inherit by default allows you to write CSS more efficiently and predict how your styles will cascade throughout your HTML structure.

question mark

Which CSS property is typically inherited by child elements?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 7
some-alt