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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
74
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
250
Faking Real Time: Optimistic Updates & Eventual Consistency (Decompress 2015)
bensmithett
0
510
Other Decks in Programming
See All in Programming
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
210
Creating Composable Callables in Contemporary C++
rollbear
0
170
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
180
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
270
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
14
5.8k
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
0
120
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
120
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
170
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
260
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
110
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
180
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
280
Featured
See All Featured
Mind Mapping
helmedeiros
PRO
1
260
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2k
Un-Boring Meetings
codingconduct
0
320
A Soul's Torment
seathinner
6
3k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.1k
Faster Mobile Websites
deanohume
310
32k
Building an army of robots
kneath
306
46k
4 Signs Your Business is Dying
shpigford
187
22k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
540
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
380
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Google's AI Overviews - The New Search
badams
0
1k
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!