CSS Inheritance

CSS Tutorial  >  Inheritance

In an HTML document, the tags have parent-child relationships. For example, <title> tag is always inside the <head> tag, so the <head> tag is the parent of the <title> tag. Inheritance means that the child node will inherit the styles defined for the parent node, unless that style (property) is explicitly defined for the child node.

For example, if the stylesheet is declared as follows:

p { color: #00FF00; }
strong { font-size:16px; }

the following HTML code,

<p>This is an example <strong>showing HTML inheritance.</strong></p>


This is an example showing HTML inheritance.

The font color for the entire sentence is green, even though no color property was defined for the <strong> tag. This is because <strong> is a child element of <p>, so the <strong> inherits the style defined for <p>, which is this case is the font color.

Next: CSS Class and CSS ID

Copyright © 2024   1keydata.com   All Rights Reserved   Privacy Policy   About   Contact

AdBlock Detected!

Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.