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
Matija Marohnić
October 09, 2020
Programming
64
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
31
Goodbye jsdom/happy-dom, hello Vitest Browser Mode!
silvenon
0
24
Introduction to Remix
silvenon
0
160
Cypress vs. Playwright
silvenon
0
170
Studying Strapi: an open source head headless CMS
silvenon
0
57
Make your JavaScript projects more accessible to newcomers
silvenon
0
93
React Hooks
silvenon
0
95
PostCSS
silvenon
0
66
CSS Custom Properties
silvenon
0
55
Other Decks in Programming
See All in Programming
Foundation Models frameworkで画像分析
ryodeveloper
1
120
Apache Hive: Toward a Cloud Native Lakehouse
okumin
0
130
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
490
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
0
110
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
0
200
Claude Team Plan導入・ガイド
tk3fftk
0
200
AI 輔助遺留系統現代化的經驗分享
jame2408
1
1.2k
AI時代の仕事技芸論〜ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ(スクフェス仙台 2026バージョン)
kuranuki
0
640
霧の中の代数的エフェクト
funnyycat
1
390
Embedded SREと共に達成した会員管理システムのAWS移行 - SRE NEXT 2026 ランチスポンサーセッション
niftycorp
PRO
1
2.6k
OSINT for SRE: 学術論文とポストモーテムから探る システム障害の共通パターン / SRE NEXT 2026
tomoyk
1
3.7k
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
360
Featured
See All Featured
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.6k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
340
Bash Introduction
62gerente
615
220k
RailsConf 2023
tenderlove
30
1.5k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
460
Into the Great Unknown - MozCon
thekraken
41
2.6k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
590
Context Engineering - Making Every Token Count
addyosmani
9
1k
How to Think Like a Performance Engineer
csswizardry
28
2.7k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.6k
Code Reviewing Like a Champion
maltzj
528
40k
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!