What is inheritance in CSS?

Some CSS properties are inherited: a child element gets the value of its parent if you do not set one. Text properties like color, font-family, font-size and line-height are inherited. Box properties like margin, padding and border are not.

body { color: #333; font-family: Arial, sans-serif; }   /* all text inside inherits it */

.box { border: 1px solid red; }       /* the children do not get the border */
.child { border: inherit; }           /* force inheritance */

See CSS Specificity.


Learn more about the similar topics:
Tutorials
CSS Selectors
CSS Specificity
CSS Pseudo-classes and Pseudo-elements
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What is the CSS class selector?
What is grouping in CSS and what is it used for?
What are child selectors in CSS?
What is the difference between id and class selector in CSS?
What is specificity in CSS?
What does !important do in CSS?
What are pseudo-classes and pseudo-elements in CSS?