CSS Inheritance and Specificity

Understanding how CSS rules are applied

Inheritance Example

This paragraph inherits the text color from its parent element.

The font size is also inherited from the parent.

Specificity Example

This paragraph uses the element selector.

This paragraph uses a class selector.

This paragraph uses an ID selector.

This paragraph has both ID and class selectors.

CSS Specificity Order

Element selector → lower priority

Class selector → higher priority

ID selector → highest priority