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
0
46
CSS Specificity
Matija Marohnić
October 09, 2020
Tweet
Share
More Decks by Matija Marohnić
See All by Matija Marohnić
Goodbye jsdom/happy-dom, hello Vitest Browser Mode!
silvenon
0
9
Introduction to Remix
silvenon
0
140
Cypress vs. Playwright
silvenon
0
160
Studying Strapi: an open source head headless CMS
silvenon
0
48
Make your JavaScript projects more accessible to newcomers
silvenon
0
78
React Hooks
silvenon
0
84
PostCSS
silvenon
0
45
CSS Custom Properties
silvenon
0
40
Maintainable Integration Testing in React
silvenon
0
48
Other Decks in Programming
See All in Programming
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
110
Package Management Learnings from Homebrew
mikemcquaid
0
210
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
370
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
450
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
220
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
6k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
490
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
990
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
AI時代の認知負荷との向き合い方
optfit
0
150
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
170
Featured
See All Featured
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
77
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
270
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
72
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
100
Writing Fast Ruby
sferik
630
62k
BBQ
matthewcrist
89
10k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.3k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
60
42k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
170
GraphQLとの向き合い方2022年版
quramy
50
14k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
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!