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
82
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CSS Specificity
Matija Marohnić
October 09, 2020
Transcript
20 slides
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!
More Decks by Matija Marohnić
See All by Matija Marohnić
oxlint & oxfmt: linting and formatting from the future
silvenon
0
58
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
71
Make your JavaScript projects more accessible to newcomers
silvenon
0
110
React Hooks
silvenon
0
110
PostCSS
silvenon
0
76
CSS Custom Properties
silvenon
0
77
Other Decks in Programming
See All in Programming
AI時代のシニアエンジニアとは
yosuke_furukawa
PRO
15
11k
プロジェクトコードをキレイキレイしよう!暗黙的な参照を読み解く静的解析
ostk0069
0
210
GraphQL の onError と Nullability のこれから
quramy
0
210
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
370
LLM 101: Exploring LLMs, Starting with Tokens.
dalinaum
0
100
複数ドメインを一つのアプリに統合するFlutterの設計と運用_FlutterKaigi2026登壇資料(須永高弘)
takahirosunaga
0
170
Claude Code ハーネスDeep Dive – 君はどこまで制御する? -
takateeen_knj
6
5.5k
Modernizing iOS Apps
seyfoyun
0
150
Goコンパイラを作ってGoをもっと理解する / Build a Go compiler to better understand Go
ikura_hamu
0
130
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
650
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
1.2k
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
260
Featured
See All Featured
Building the Perfect Custom Keyboard
takai
2
950
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
77k
Claude Code のすすめ
schroneko
67
230k
From π to Pie charts
rasagy
1
440
YesSQL, Process and Tooling at Scale
rocio
174
15k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
SEO for Brand Visibility & Recognition
aleyda
0
4.9k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
1
300
The untapped power of vector embeddings
frankvandijk
2
2k
Being A Developer After 40
akosma
PRO
92
590k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Automating Front-end Workflow
addyosmani
1370
210k