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
Atomic CSS with Fela
Search
Ben Smithett
July 01, 2020
Programming
140
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Atomic CSS with Fela
Ben Smithett
July 01, 2020
More Decks by Ben Smithett
See All by Ben Smithett
Objects in Space: A practical guide to CSS display, position & z-index
bensmithett
0
75
The 12MB Web Page: A tale of perfect PageSpeed scores & developer happiness
bensmithett
1
360
The UI is an Application
bensmithett
0
1.2k
Hands on with the modern front end stack
bensmithett
0
1.3k
The New Front End Stack: A really really really high level introduction
bensmithett
1
550
Smarter Sass/Less Builds with Webpack (MelbJS Edition)
bensmithett
0
350
Smarter Sass builds with Webpack
bensmithett
1
260
Faking Real Time: Optimistic Updates & Eventual Consistency (Decompress 2015)
bensmithett
0
520
Other Decks in Programming
See All in Programming
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
18k
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
1
1.5k
OpenSpecのproposalにbrainstormingを持たせてみた
tigertora7571
1
210
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
4
1.6k
Built Our Own Background Agent at LayerX
layerx
PRO
10
5.2k
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
340
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
500
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
3
770
komatsuna「分散システムにおけるバグ分析手法」
komatsunaqa
0
250
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
150
AWS DevOps AgentのAzure接続機能を検証して見えた活用法/Use Cases Verified for the AWS DevOps Agent's Azure Connectivity Feature
masakiokuda
1
230
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
520
Featured
See All Featured
Odyssey Design
rkendrick25
PRO
2
750
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
430
sira's awesome portfolio website redesign presentation
elsirapls
0
320
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.5k
Utilizing Notion as your number one productivity tool
mfonobong
4
530
Crafting Experiences
bethany
1
250
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
450
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
490
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
630
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
320
How to Talk to Developers About Accessibility
jct
2
500
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
380
Transcript
Atomic CSS with
What is Atomic CSS? compose styles directly on HTML tags
instead of in abstract CSS classes
Normal: style composition in CSS classes .header { background: black;
padding: 10px; display: flex; } <div class='header'>
Normal: style composition in CSS classes .header { background: black;
padding: 10px; display: flex; } <div class='header'> Not normal: inline styles <div style='background: black; padding: 10px; display: flex;'>
Atomic CSS .bg-black { background: black; } .padding-s { padding:
10px; } .flex { display: flex; } <div class='bg-black padding-s flex'> Normal: style composition in CSS classes .header { background: black; padding: 10px; display: flex; } <div class='header'> Not normal: inline styles <div style='background: black; padding: 10px; display: flex;'>
why? Atomic CSS .bg-black { background: black; } .padding-s {
padding: 10px; } .flex { display: flex; } <div class='bg-black padding-s flex'> Normal: style composition in CSS classes .header { background: black; padding: 10px; display: flex; } <div class='header'> Not normal: inline styles <div style='background: black; padding: 10px; display: flex;'> 🚀P🚀E🚀R🚀F🚀O🚀R🚀M🚀A🚀N🚀C🚀E🚀 (among other reasons)
developing new features the normal way:
header.css .header { background: black; padding: 10px; display: flex; }
.header-logo { border: 0; }
header.css .header { background: black; padding: 10px; display: flex; }
.header-logo { border: 0; } footer.css .footer { background: black; padding: 10px; display: grid; } .footer-links { display: flex; flex-direction: column; }
CSS size (kb) Features added over time
CSS size (kb) Features added over time 🐌
CSS size (kb) Features added over time 🐌 code splitting
CSS size (kb) Features added over time 🐌 code splitting
CSS Modules `composes`
CSS size (kb) Features added over time 🐌 code splitting
CSS Modules `composes` lazy-load below-the-fold sections
header.css .header { background: black; padding: 10px; display: flex; }
.header-logo { border: 0; } footer.css .footer { background: black; padding: 10px; display: grid; } .footer-links { display: flex; flex-direction: column; }
developing new features with Atomic CSS:
styles.css .bg-black { background: black; } .padding-s { padding: 10px;
} .flex { display: flex; } .border-0 { border: 0; } header.template <div class='bg-black padding-s flex'> <img class='border-0' /> </div>
styles.css .bg-black { background: black; } .padding-s { padding: 10px;
} .flex { display: flex; } .border-0 { border: 0; } .grid { display: grid; } .flex-col { flex-direction: column; } header.template <div class='bg-black padding-s flex'> <img class='border-0' /> </div> footer.template <div class='bg-black padding-s grid'> <div class='flex flex-col' /> </div>
styles.css .bg-black { background: black; } .padding-s { padding: 10px;
} .flex { display: flex; } .border-0 { border: 0; } .grid { display: grid; } .flex-col { flex-direction: column; } header.template <div class='bg-black padding-s flex'> <img class='border-0' /> </div> footer.template <div class='bg-black padding-s grid'> <div class='flex flex-col' /> </div>
CSS size (kb) Features added over time
yay! but...
Hand-coding Atomic CSS is gross Learning an abstraction bg-black border-xl
flex pad-s instead of just writing the CSS you already know
Hand-coding Atomic CSS is gross bg-black border-xl flex pad-s not
CSS not on MDN
what if we could write dev-friendly not-very-performant-looking real CSS ...but
ship atomic classes?
write the CSS you know generate atomic classes
header.js <div className={css({ background: 'black', padding: 10, display: 'flex' })}>
<img className={css({ border: 0 })} /> </div>
header.js <div className={css({ background: 'black', padding: 10, display: 'flex' })}>
<img className={css({ border: 0 })} /> </div> footer.js <div className={css({ background: 'black', padding: 10, display: 'grid' })}> <div className={css({ display: 'flex',( flexDirection: 'column' })} /> </div>
header.js <div className={css({ background: 'black', a padding: 10, b display:
'flex' c })}> <img className={css({ border: 0 d })} /> </div> footer.js <div className={css({ background: 'black', a padding: 10, b display: 'grid' e })}> <div className={css({ display: 'flex',( c flexDirection: 'column' f })} /> </div>
header.js <div className={css({ background: 'black', a padding: 10, b display:
'flex' c })}> <img className={css({ border: 0 d })} /> </div> footer.js <div className={css({ background: 'black', a padding: 10, b display: 'grid' e })}> <div className={css({ display: 'flex',( c flexDirection: 'column' f })} /> </div> output HTML // header <div class='a b c'> <img class='d' /> </div> // footer <div class='a b e'> <div class='c f' /> </div> output CSS .a { background: black } .b { padding: 10px } .c { display: flex } .d { border: 0 } .e { display: grid } .f { flex-direction: column }
header.js <div className={css({ background: 'black', padding: 10, display: 'flex' })}>
<img className={css({ border: 0 })} /> </div> footer.js <div className={css({ background: 'black', padding: 10, display: 'grid' })}> <div className={css({ display: 'flex',( flexDirection: 'column' })} /> </div> 😱 CSS in JS!
It's the output that matters Authoring style is flexible 🙂
not so inline const root = { ... } const
logo = { ... } <div className={css(root)}> <img className={css(logo)} /> </div>
not so inline const root = { ... } const
logo = { ... } <div className={css(root)}> <img className={css(logo)} /> </div> import from another file import {root, logo} from './header.css.js' <div className={css(root)}> <img className={css(logo)} /> </div>
not so inline const root = { ... } const
logo = { ... } <div className={css(root)}> <img className={css(logo)} /> </div> import from another file import {root, logo} from './header.css.js' <div className={css(root)}> <img className={css(logo)} /> </div> (with enough Webpack tomfoolery)
not so inline const root = { ... } const
logo = { ... } <div className={css(root)}> <img className={css(logo)} /> </div> import from another file import {root, logo} from './header.css.js' <div className={css(root)}> <img className={css(logo)} /> </div> (with enough Webpack tomfoolery) Styled Components const Root = styled.div` background: black; padding: 10px; display: flex; ` const Logo = styled.img` border: 0; ` <Root> <Logo /> </Root>
You choose how you write CSS (IMHO just use JS
objects, ask me why later) Fela gives you optimised output
Unlearn "clever" optimisations
CSS size (kb) Features added over time 🐌 code splitting
CSS Modules `composes` lazy-load below-the-fold sections
CSS Modules `composes` code splitting lazy-load below-the-fold sections 🗑
🗑 📄 📄 📄 CSS files
<html> <head> <style>.a{background:black}.b{padding:10px}.c{display:flex}.d{border:0}</style> </head> <body> <div class='a b c'> <img
class='d' /> </div> <body> </html> just inline the initial render's CSS in <head>
fela.js.org styletron.org sanblas.netlify.app inspect new facebook.com in devtools Show me
more!