×
Course: CSS Basics

Inheritance [13/15]

Another core mechanism in CSS is inheritance. It means that some styles can be passed on from a parent element to its descendants (i.e., elements nested in it).

For example, all the elements within the body tag are its descendants. If the styles of body make text color red, the text color in all the other elements would also become red.

Another example: the ul tag is the parent tag for all the li tags contained within it. If you italicize the ul font, this will apply to all the li elements within it.


Do it
HTML
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Inheritance</title> </head> <body> <h1>CSS Properties</h1> <p>There is a huge multitude of properties in CSS. They can be classified into the following groups:</p> <ul> <li>Text formatting</li> <li>Styling sizes, paddings and margins</li> <li>Element positioning</li> <li>Page layout</li> <li>Decorative: colors, background, shadows;</li> <li>etc.</li> </ul> </body> </html>
CSS
body { } ul { }
HTML Academy
  1. For the body tag, set color: red;.
  2. For ul, set font-style: italic;.
Theory Check Next