Slide 1

Slide 1 text

Atomic CSS with

Slide 2

Slide 2 text

What is Atomic CSS? compose styles directly on HTML tags instead of in abstract CSS classes

Slide 3

Slide 3 text

Normal: style composition in CSS classes .header { background: black; padding: 10px; display: flex; }

Slide 4

Slide 4 text

Normal: style composition in CSS classes .header { background: black; padding: 10px; display: flex; }
Not normal: inline styles

Slide 5

Slide 5 text

Atomic CSS .bg-black { background: black; } .padding-s { padding: 10px; } .flex { display: flex; }
Normal: style composition in CSS classes .header { background: black; padding: 10px; display: flex; }
Not normal: inline styles

Slide 6

Slide 6 text

why? Atomic CSS .bg-black { background: black; } .padding-s { padding: 10px; } .flex { display: flex; }
Normal: style composition in CSS classes .header { background: black; padding: 10px; display: flex; }
Not normal: inline styles
🚀P🚀E🚀R🚀F🚀O🚀R🚀M🚀A🚀N🚀C🚀E🚀 (among other reasons)

Slide 7

Slide 7 text

developing new features the normal way:

Slide 8

Slide 8 text

header.css .header { background: black; padding: 10px; display: flex; } .header-logo { border: 0; }

Slide 9

Slide 9 text

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; }

Slide 10

Slide 10 text

CSS size (kb) Features added over time

Slide 11

Slide 11 text

CSS size (kb) Features added over time 🐌

Slide 12

Slide 12 text

CSS size (kb) Features added over time 🐌 code splitting

Slide 13

Slide 13 text

CSS size (kb) Features added over time 🐌 code splitting CSS Modules `composes`

Slide 14

Slide 14 text

CSS size (kb) Features added over time 🐌 code splitting CSS Modules `composes` lazy-load below-the-fold sections

Slide 15

Slide 15 text

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; }

Slide 16

Slide 16 text

developing new features with Atomic CSS:

Slide 17

Slide 17 text

styles.css .bg-black { background: black; } .padding-s { padding: 10px; } .flex { display: flex; } .border-0 { border: 0; } header.template

Slide 18

Slide 18 text

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
footer.template

Slide 19

Slide 19 text

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
footer.template

Slide 20

Slide 20 text

CSS size (kb) Features added over time

Slide 21

Slide 21 text

yay! but...

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

Hand-coding Atomic CSS is gross bg-black border-xl flex pad-s not CSS not on MDN

Slide 24

Slide 24 text

what if we could write dev-friendly not-very-performant-looking real CSS ...but ship atomic classes?

Slide 25

Slide 25 text

write the CSS you know generate atomic classes

Slide 26

Slide 26 text

header.js

Slide 27

Slide 27 text

header.js
footer.js

Slide 28

Slide 28 text

header.js
footer.js

Slide 29

Slide 29 text

header.js
footer.js
output HTML // header
// footer
output CSS .a { background: black } .b { padding: 10px } .c { display: flex } .d { border: 0 } .e { display: grid } .f { flex-direction: column }

Slide 30

Slide 30 text

header.js
footer.js
😱 CSS in JS!

Slide 31

Slide 31 text

It's the output that matters Authoring style is flexible 🙂

Slide 32

Slide 32 text

not so inline const root = { ... } const logo = { ... }

Slide 33

Slide 33 text

not so inline const root = { ... } const logo = { ... }
import from another file import {root, logo} from './header.css.js'

Slide 34

Slide 34 text

not so inline const root = { ... } const logo = { ... }
import from another file import {root, logo} from './header.css.js'
(with enough Webpack tomfoolery)

Slide 35

Slide 35 text

not so inline const root = { ... } const logo = { ... }
import from another file import {root, logo} from './header.css.js'
(with enough Webpack tomfoolery) Styled Components const Root = styled.div` background: black; padding: 10px; display: flex; ` const Logo = styled.img` border: 0; `

Slide 36

Slide 36 text

You choose how you write CSS (IMHO just use JS objects, ask me why later) Fela gives you optimised output

Slide 37

Slide 37 text

Unlearn "clever" optimisations

Slide 38

Slide 38 text

CSS size (kb) Features added over time 🐌 code splitting CSS Modules `composes` lazy-load below-the-fold sections

Slide 39

Slide 39 text

CSS Modules `composes` code splitting lazy-load below-the-fold sections 🗑

Slide 40

Slide 40 text

🗑 📄 📄 📄 CSS files

Slide 41

Slide 41 text

.a{background:black}.b{padding:10px}.c{display:flex}.d{border:0}
just inline the initial render's CSS in

Slide 42

Slide 42 text

fela.js.org styletron.org sanblas.netlify.app inspect new facebook.com in devtools Show me more!