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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
350
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
510
Other Decks in Programming
See All in Programming
ITヒヤリハットを整理してみた ~ライフサイクルと原因から考える再発防止策~
koukimiura
1
110
Apache Hive: Toward a Cloud Native Lakehouse
okumin
0
140
『コードを書く以外の』エンジニアリング〜課金基盤移行プロジェクト推進のためのTips4選
yuriko1211
0
510
分散システム、なんですぐ死んでしまうん?耐障害性を高めたいあなたのためのレジリエンスパターン入門
mshibuya
7
6.5k
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
270
AI時代の仕事技芸論〜ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ(スクフェス仙台 2026バージョン)
kuranuki
0
670
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
380
20260623_Loop Engineeringで自分の分身の問い合わせBotを作る
ryugen04
0
230
関数型プログラミングのメリットって何だろう?
wanko_it
0
180
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
4
1.1k
Foundation Models frameworkで画像分析
ryodeveloper
1
120
共通化で考えるべきは、実装より公開する型だった
codeegg
0
250
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.7k
Building the Perfect Custom Keyboard
takai
2
820
The Cult of Friendly URLs
andyhume
79
6.9k
Color Theory Basics | Prateek | Gurzu
gurzu
0
390
Six Lessons from altMBA
skipperchong
29
4.3k
Paper Plane
katiecoart
PRO
2
52k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.7k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
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!