Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
CSS Specificity
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Matija Marohnić
October 09, 2020
Programming
58
0
Share
CSS Specificity
Matija Marohnić
October 09, 2020
More Decks by Matija Marohnić
See All by Matija Marohnić
oxlint & oxfmt: linting and formatting from the future
silvenon
0
27
Goodbye jsdom/happy-dom, hello Vitest Browser Mode!
silvenon
0
16
Introduction to Remix
silvenon
0
150
Cypress vs. Playwright
silvenon
0
170
Studying Strapi: an open source head headless CMS
silvenon
0
55
Make your JavaScript projects more accessible to newcomers
silvenon
0
87
React Hooks
silvenon
0
91
PostCSS
silvenon
0
60
CSS Custom Properties
silvenon
0
52
Other Decks in Programming
See All in Programming
PHPでバイナリをパースして理解するASN.1
muno92
PRO
0
430
Claude CodeでETLジョブ実行テストを自動化してみた
yoshikikasama
0
1.2k
How We Practice Exploratory Testing in Iterative Development( #scrumniigata ) / 反復開発の中で、探索的テストをどう実施しているか
teyamagu
PRO
3
730
運転動画を検索可能にする〜Cosmos-Embed1とDatabricks Vector Searchで〜/cosmos-embed1-databricks-vector-search
studio_graph
1
660
AIを導入する前にやるべきこと
negima
2
340
書き換えて学ぶTemporal #fukts
pirosikick
2
360
Spec-Driven Development with AI Agents (Workshop, May 2026)
antonarhipov
3
320
実用!Hono RPC2026
yodaka
2
300
継続的な負荷検証を目指して
pyama86
1
510
いつか誰かが、と思っていた フロントエンド刷新5年間の実践知
kiichisugihara
1
260
PicoRuby for IoT: Connecting to the Cloud with MQTT
yuuu
2
760
Are We Really Coding 10× Faster with AI?
kohzas
0
120
Featured
See All Featured
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
540
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
360
Building an army of robots
kneath
306
46k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
110
Paper Plane (Part 1)
katiecoart
PRO
0
7.2k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.3k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
65
54k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
130
A Modern Web Designer's Workflow
chriscoyier
698
190k
Transcript
Matija Marohnić CSS Specificity
A little bit about me • frontend developer and blogger
• obsessed with generating static sites • DX evangelist • open source • automate all the things • follow me on Twitter: @silvenon
MDN Web docs “Specificity is the means by which browsers
decide which property values are the most relevant to an element and, therefore, will be applied.”
X Y Z type selectors, pseudo-elements class selectors, attribute selectors,
pseudo-classes ID selectors
0 0 1 type selectors, pseudo-elements class selectors, attribute selectors,
pseudo-classes ID selectors
0 1 2 type selectors, pseudo-elements class selectors, attribute selectors,
pseudo-classes ID selectors
1 2 2 type selectors, pseudo-elements class selectors, attribute selectors,
pseudo-classes ID selectors
0 54 0 type selectors, pseudo-elements class selectors, attribute selectors,
pseudo-classes ID selectors A trick to bump specificity
0 1 0 type selectors, pseudo-elements class selectors, attribute selectors,
pseudo-classes ID selectors
• these don’t affect specificity: • universal selector (*) •
combinators (+, >, ~, etc.) • negation pseudo-class (:not())
0 0 0 type selectors, pseudo-elements class selectors, attribute selectors,
pseudo-classes ID selectors
0 1 1 type selectors, pseudo-elements class selectors, attribute selectors,
pseudo-classes ID selectors
1 0 0 0 type selectors, pseudo-elements class selectors, attribute
selectors, pseudo-classes ID selectors inline style
1 0 0 0 1 type selectors, pseudo-elements class selectors,
attribute selectors, pseudo-classes ID selectors inline style !important
When to use !important • as little as possible •
basically only to override third-party styles
An alternative to !important Lorem ipsum dolor, sit amet consectetur
adipisicing elit.
The best way to increase specificity is…
• the lower the specificity, the easier it is to
manage • plus, this way we keep repetition out of HTML …source order.
The color of the paragraph is: 1. red 2. green
3. blue 4. fuchsia Quiz!
Happy styling!