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
52
0
Share
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
26
Goodbye jsdom/happy-dom, hello Vitest Browser Mode!
silvenon
0
14
Introduction to Remix
silvenon
0
150
Cypress vs. Playwright
silvenon
0
170
Studying Strapi: an open source head headless CMS
silvenon
0
54
Make your JavaScript projects more accessible to newcomers
silvenon
0
86
React Hooks
silvenon
0
91
PostCSS
silvenon
0
55
CSS Custom Properties
silvenon
0
52
Other Decks in Programming
See All in Programming
Going Multiplatform with Your Android App (Android Makers 2026)
zsmb
2
400
AI-DLC Deep Dive
yuukiyo
7
1.8k
AWS re:Invent 2025の少し振り返り + DevOps AgentとBacklogを連携させてみた
satoshi256kbyte
3
160
AI時代の脳疲弊と向き合う ~言語学としてのPHP~
sakuraikotone
1
1.9k
おれのAgentic Coding 2026/03
tsukasagr
1
140
Claude Codeをカスタムして自分だけのClaude Codeを作ろう
terisuke
0
120
Swift Concurrency Type System
inamiy
0
490
Vibe하게 만드는 Flutter GenUI App With ADK , 박제창, BWAI Incheon 2026
itsmedreamwalker
0
550
Running Swift without an OS
kishikawakatsumi
0
790
3分でわかるatama plusのQA/about atama plus QA
atamaplus
0
160
의존성 주입과 모듈화
fornewid
0
130
事業会社でのセキュリティ長期インターンについて
masachikaura
0
250
Featured
See All Featured
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
170
WCS-LA-2024
lcolladotor
0
530
Paper Plane
katiecoart
PRO
1
49k
Six Lessons from altMBA
skipperchong
29
4.2k
From π to Pie charts
rasagy
0
160
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Optimising Largest Contentful Paint
csswizardry
37
3.6k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
64
53k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.1k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
A better future with KSS
kneath
240
18k
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!