Skip to content
Home Blog Web Development CSS Specificity and Inheritance: The Cascade

CSS Specificity and Inheritance: The Cascade

  • Web Development
Blueprint Digital
Blueprint Digital

Insights from the Blueprint Digital team.

Being a front end web developer, I use a lot of CSS to make websites look the way they do. Last week, I wrote about semantics in front end web development. Today, I will write about CSS concepts, specificity and inheritance.

CSS Specificity

Specificity in CSS refers to how specific a CSS selector is. The list below shows the levels of specificity from most specific to least specific:

  1. Inline styles applied directly to HTML tags by using the style attribute
  2. IDs such as #container
  3. Classes such as .foobar, attribute such as [type="text"], and Pseudo-classes such as :hover
  4. HTML tags such as ul, p, etc.

Specificity determines what styles will be applied to the elements on a page based on the weight of these selectors. The more specific style takes priority over the less specific style.

It is also important to note that !important will have priority over all other styles defined. This is one of the reasons why some developers argue that !important should be used sparingly.

CSS Inheritance

One of the first things a front end developer learns about when starting out is how to write HTML codes. One of the features of HTML is that certain elements could be nested inside other elements, as shown below:

<div id="foo">
	<div class="bar">
		<p class="qux">Content goes here.</p>
	</div>
</div>

Let us assume the CSS for the HTML above is something like this:

#foo {
	font-size: 14px;
        background: yellow;
}

.bar {
	color: red;
}

Because the font-size for #foo was defined and because .bar is nested inside #foo, the content inside .bar will have the font size of 14px. This is called inheritance. The paragraph text inside .bar will be red because of the color defined for .bar. This is referred to as paragraph inheriting the styles for .bar.

One thing that is not inherited is background. That is because the background property of an element is set to transparent by default.

CSS: Cascading Style Sheets

CSS specificity and inheritance bring up an important feature of CSS: the cascade. The cascade, as in Cascading Style Sheets, demonstrates how specificity and inheritance work together to influence the look of a web page. Let us consider the above HTML example again, and let us assume that the CSS below applies.

p {
	border: 1px solid #000;
	padding: 10px;
	font-size: 10px;
}

p.qux {
	font-size: 14px;
}

The paragraph in the above example will have border and padding applied to it even though the style for p.qux doesn’t state those properties. The paragraph, however, will not inherit font-size and will be 14px instead of 10px because it was defined on p.qux, which has a higher weight of specificity than p.

Generally, author style sheets, which the developers apply to a web page, will take priority, followed by user defined styles and then by browser defined styles. Within each stylesheet, specificity of selectors will determine how styles are defined.

Conclusion

Understanding these fundamentals about Cascading Style Sheets will make it easier to learn other concepts in CSS. If you enjoyed this post, check out my other CSS basics pots such as A look into CSS z-index property and CSS Box Model Explained.

Ready to Dominate Online and Grow Your Business?

Schedule time to connect with Blueprint about your online goals, or request a free review of marketing campaigns.

Related Posts

Lead Scoring for B2B: How to Decide Which Leads Your Sales Team Chases

Lead Scoring for B2B: How to Decide Which Leads Your Sales Team Chases

Every marketing team has handed sales a list of leads that went nowhere. After a few of those lists, sales stops trusting them, works its own referrals instead, and the two teams settle into a standing argument about lead quality. Underneath the argument is a simpler problem: nobody has written down what a good lead[...]
Why Your Blog Is Stealing Rankings From Your Service Page (and How to Stop It)

Why Your Blog Is Stealing Rankings From Your Service Page (and How to Stop It)

You publish a blog to support a service page, expecting it to bring in readers and pass authority down to the page that closes business. Months later the blog is outranking the service page for the term that drives leads, and the service page has slipped. The supporting piece has turned into a competitor, a[...]
Why B2B Online Marketing Looks Different in 2026

Why B2B Online Marketing Looks Different in 2026

By 2026, the B2B buyer has done most of the work before a vendor ever enters the conversation. The decision takes shape across Google, AI assistants, LinkedIn, and peer reviews, and it rarely rests with one person: a committee of five or more stakeholders now builds the shortlist. B2B online marketing has changed to match[...]
Previous
Next

Partner with BLUEPRINT to reach your online goals, grow your business and reshape your story.

Get in touch with BLUEPRINT

Reach out to request a discovery call, a free campaign review, or for all other inquiries.

Subscribe to our newsletter