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 Modules, CSS Variables and the Future of Re...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Glen Maddern
May 11, 2016
Technology
9
1.3k
CSS Modules, CSS Variables and the Future of Reusable CSS
Presented at CSSConf Budapest, 2016 <3
Glen Maddern
May 11, 2016
Tweet
Share
More Decks by Glen Maddern
See All by Glen Maddern
The Road to Styled Components & the Road Ahead
geelen
2
240
The Road to Styled Components
geelen
2
1.4k
Styled Components and the Road to Unification
geelen
2
290
The Future of Reusable CSS
geelen
2
220
Other Decks in Technology
See All in Technology
仕様書駆動AI開発の実践: Issue→Skill→PRテンプレで 再現性を作る
knishioka
2
680
20260208_第66回 コンピュータビジョン勉強会
keiichiito1978
0
180
今日から始めるAmazon Bedrock AgentCore
har1101
4
410
OWASP Top 10:2025 リリースと 少しの日本語化にまつわる裏話
okdt
PRO
3
820
【Oracle Cloud ウェビナー】[Oracle AI Database + AWS] Oracle Database@AWSで広がるクラウドの新たな選択肢とAI時代のデータ戦略
oracle4engineer
PRO
2
170
登壇駆動学習のすすめ — CfPのネタの見つけ方と書くときに意識していること
bicstone
3
120
20260204_Midosuji_Tech
takuyay0ne
1
160
SRE Enabling戦記 - 急成長する組織にSREを浸透させる戦いの歴史
markie1009
0
130
ランサムウェア対策としてのpnpm導入のススメ
ishikawa_satoru
0
180
AzureでのIaC - Bicep? Terraform? それ早く言ってよ会議
torumakabe
1
580
セキュリティについて学ぶ会 / 2026 01 25 Takamatsu WordPress Meetup
rocketmartue
1
310
OpenShiftでllm-dを動かそう!
jpishikawa
0
130
Featured
See All Featured
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
250
Discover your Explorer Soul
emna__ayadi
2
1.1k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
1
56
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.9k
ラッコキーワード サービス紹介資料
rakko
1
2.3M
YesSQL, Process and Tooling at Scale
rocio
174
15k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
100
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Documentation Writing (for coders)
carmenintech
77
5.3k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.6k
Transcript
Reusable CSS CSS VARIABLES, CSS MODULES & THE FUTURE OF
@glenmaddern
HELLO BUDAPEST! ♥
Reusable CSS CSS VARIABLES, CSS MODULES & THE FUTURE OF
@glenmaddern
None
WHY IS IT SO HARD TO SHARE CSS?
WHY IS IT SO HARD TO REUSE CSS?
import something from 'somewhere' something.leftPad()
THE HUMAN BRAIN IS A (IN)CONSISTENCY-DETECTING MACHINE
http://semantic-ui.com
http://semantic-ui.com
http://semantic-ui.com
http://www.novolume.co.uk/blog/all-websites-look-the-same/
http://graphicriver.net/
None
WE DON'T NEED MORE TOOLING TO MAKE OUR CURRENT COMPONENTS
THEMEABLE WE NEED TO START BUILDING BETTER COMPONENTS
st ep #1
RESPONSIVE COMPONENTS
A COMPONENT SHOULD RESPOND TO ITS ENVIRONMENT • • RATHER
THAN THE ENVIRONMENT OVERRIDING THE COMPONENT
OUTSIDE-IN OVERRIDES
https://en.wikipedia.org/wiki/Margaret_Hamilton_(scientist)
http://semantic-ui.com
MAKE YOUR COMPONENTS LESS RESPONSIBLE & MORE RESPONSIVE
layout
PADDING CONTENT MARGIN
PADDING CONTENT MARGIN
.component { width: 50%; margin-top: 2rem; flex-grow: 1; } ❌
.parent { display: flex; padding: 1rem; } .parent > *
{ flex-grow: 1; } ONE ONE TWO ONE TWO THREE
.parent { display: flex; padding: 1rem; } .parent > *
{ flex-grow: 1; } .parent > * + * { margin-left: 1rem; } ONE ONE TWO ONE TWO THREE
.parent { display: flex; padding: 1rem; } .parent > *
{ flex-grow: 1; } .parent > * + * { margin-left: 1rem; } .parent > :first-child { flex: 0 0 50%; } ONE TWO ONE TWO THREE ONE TWO THREE FOUR
LAYOUT IS THE CONCERN OF THE p arent
DEMO: CURRENTCOLOR
https://www.youtube.com/watch?v=jPOBVaomzLE
css v ari able s
http://caniuse.com/#feat=css-variables
CSS CUSTOM PROPERTIES CSS VARIABLES =
.component { --size: 2rem; width: calc(2 * var(--size)); height: var(--size);
} .component
.component { --size: var(--spacing, 2rem); width: calc(2 * var(--size)); height:
var(--size); } .component .container .component .container { --spacing: 1rem; }
.component { --size: var(--spacing, 2rem); width: calc(2 * var(--size)); height:
var(--size); } .component .component.large .large { --spacing: 4rem; /* or */ --size: 4rem; }
.component { background: var(--bg, black); color: var(--fg, white); }
.component { background: var(--bg, black); color: var(--fg, white); } (bg,
fg) => <Component style.../>
DEMO: INVERTED BUTTON
INHERITANCE THE CASCADE vs
st ep #2
EXPLICIT COMPONENTS
http://semantic-ui.com/elements/button.html
http://jxnblk.com/rebass/#Button
DEMO: DOCUMENTATION
NAMING MISMATCHES?
.container .container { --grid-size: 1rem; } .component .component .component {
--size: var(--spacing, 2rem); width: calc(2 * var(--size)); height: var(--size); }
.component .container .component.fix .container { --grid-size: 1rem; } .fix {
--spacing: var(--grid-size); } .component { --size: var(--spacing, 2rem); width: calc(2 * var(--size)); height: var(--size); }
st ep #3
RESILIENT COMPONENTS
w arning: re act
import styles from './MediaObject.css' const MediaObject = ({ title, image,
text }) => ( <div className={styles.outer}> <img className={styles.img} src={ image }/> <div className={styles.inner}> <h1 className={styles.h1}>{ title }</h1> <p className={styles.p}>{ text }</p> </div> </div> )
import styles from './MediaObject.css' const MediaObject = ({ title, image,
text, theme=styles }) =>( <div className={theme.outer}> <img className={theme.img} src={ image }/> <div className={theme.inner}> <h1 className={theme.h1}>{ title }</h1> <p className={theme.p}>{ text }</p> </div> </div> ) https://github.com/css-modules/css-modules/issues/147
DEMO: INTERNAL STRUCTURE DOCS
✅ RESPOND TO ENVIRONMENT ✅ USE INTERNAL VARIABLES ✅ EXPOSE
INTERNAL STRUCTURE
t hank you! @glenmaddern