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 Modules, CSS Variables and the Future of Re...
Search
Glen Maddern
May 11, 2016
Technology
1.3k
9
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CSS Modules, CSS Variables and the Future of Reusable CSS
Presented at CSSConf Budapest, 2016 <3
Glen Maddern
May 11, 2016
More Decks by Glen Maddern
See All by Glen Maddern
The Road to Styled Components & the Road Ahead
geelen
2
270
The Road to Styled Components
geelen
2
1.5k
Styled Components and the Road to Unification
geelen
2
310
The Future of Reusable CSS
geelen
2
240
Other Decks in Technology
See All in Technology
PHPカンファレンス関西の招待状 / Invitation to PHP Conference Kansai
ykanoh
0
110
⾮構造化データを価値に変える AI エージェント基盤とその組織
ivry_presentationmaterials
0
190
Conditional PED-ANOVA: Hyperparameter Importance in Hierarchical & Dynamic Search Spaces
pfn
PRO
0
130
実践!Cloud Run ハンズオン!! / Cloud Run handson
y0hgi
2
280
Rust で関数型ドメインモデリング
takonda
0
140
DevelopersIO 2026 知識の地図を描く ─ オントロジーとは何か?
ishikawa_satoru
1
1.7k
実体験から学ぶ分析エージェントの開発と運⽤
recruitengineers
PRO
8
2.4k
しろおびから始める!ログ活用の第一歩
shumei_ito
0
950
AI導入は済んだ。次は統制を作り替える番だ_AI×開発組織 Summit 2026
techtekt
PRO
0
210
go-sqletch
moznion
0
140
Optunaの最新リリースv5.0について
pfn
PRO
0
120
USB PDを使ってスマホを労わりたい
raspython3
0
180
Featured
See All Featured
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
360
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
3.4k
Test your architecture with Archunit
thirion
2
2.4k
A better future with KSS
kneath
240
18k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
460
Large-scale JavaScript Application Architecture
addyosmani
516
110k
WENDY [Excerpt]
tessaabrams
14
40k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8.1k
Darren the Foodie - Storyboard
khoart
PRO
4
4k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
990
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
520
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
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