Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
CSS Specificity
Search
Matija Marohnić
October 09, 2020
Programming
76
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
50
Goodbye jsdom/happy-dom, hello Vitest Browser Mode!
silvenon
0
37
Introduction to Remix
silvenon
0
180
Cypress vs. Playwright
silvenon
0
190
Studying Strapi: an open source head headless CMS
silvenon
0
68
Make your JavaScript projects more accessible to newcomers
silvenon
0
110
React Hooks
silvenon
0
110
PostCSS
silvenon
0
75
CSS Custom Properties
silvenon
0
71
Other Decks in Programming
See All in Programming
コードで差別化できない時代の ソフトウェアエンジニアリング / Software Engineering in an Era Where Code Doesn’t Differentiate
kishida
2
180
Simple Storage Service(S3) is not simple
iwatsukayura
0
290
當我們開始不讀 Code - AI Agent 時代,Code Review 與 Clean Code 還剩下什麼?
jame2408
1
220
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
180
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
220
ジョジョの世界をXRで再現する
mofurune
0
160
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
910
Workers Cache を知る
syumai
0
360
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
180
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.6k
AmebaブログはKMPから卒業します
kmars0605
0
190
APNsからLive Activityを開始する話
yumnumm
0
170
Featured
See All Featured
Being A Developer After 40
akosma
92
590k
Designing for Performance
lara
612
70k
The untapped power of vector embeddings
frankvandijk
2
1.9k
Designing for Timeless Needs
cassininazir
1
530
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3.1k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
360
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Skip the Path - Find Your Career Trail
mkilby
1
260
Designing Experiences People Love
moore
143
24k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
Building Flexible Design Systems
yeseniaperezcruz
330
41k
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!