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
Apache Hive: Toward a Cloud Native Lakehouse
okumin
0
130
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
210
技術記事、 専門家としてのプログラマ、 言語化
mizchi
14
7.5k
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
500
共通化で考えるべきは、実装より公開する型だった
codeegg
0
250
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
190
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
350
地域 SRE コミュニティ最前線 - ホンマでっかSRE勉強会
tk3fftk
0
240
AI時代の仕事技芸論〜ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ(スクフェス仙台 2026バージョン)
kuranuki
0
650
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
360k
act1-costs.pdf
sumedhbala
0
230
SREは、MCPとSRE Agentをこう使え!
kazumax55
0
150
Featured
See All Featured
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
980
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Designing for Performance
lara
611
70k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
ラッコキーワード サービス紹介資料
rakko
1
3.9M
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
660
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
390
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
750
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.4k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
410
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
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!