CSS as
Bytecode
@rtfeldman
Why so much frustration?
CSS was never intended to create
user interfaces
The Languages That
Almost Became CSS
Zack Bloom
1991
content only
AUTHORS create content using HTML
END USERS style it using stylesheets
Separating Content and Presentation
PWP, 1993
(BODY fontSize=normal� BGColor=white� FGColor=black� (H1 fontSize=largest� BGColor=red� FGColor=white)�)
FOSI
<outspec> � <docdesc>� <charlist>� <font size="12pt" bckcol="white" fontcol="black">� </charlist>� </docdesc>� <e-i-c gi="h1"><font size="24pt" bckcol="red"></e-i-c>� <e-i-c gi="h2"><font size="20pt" fgcol="white"></e-i-c>� <e-i-c gi="a"><font fgcol="red"></e-i-c>� <e-i-c gi="cmd kbd screen listing example">
<font style="monoser">
</e-i-c>�</outspec>
DSSSL
(define (create-heading heading-font-size)� (make paragraph� font-size: heading-font-size� font-weight: 'bold))��(element h1 (create-heading 24pt))�(element h2 (create-heading 18pt))
“Style sheets are an artificial construct inflicted on us because of the whole non-presentation philosophy we've been using”
—Mosaic browser creator, 1994
CSS, 1996
End users can style content!
body {
vertical-align: middle;
}
fast forward 20 years...
The Web has become the biggest
user interface
delivery platform in history
designed for
used for
creators styling content
building user interfaces
end users styling
the content they read
Why would articles need content to be horizontally and vertically centered?
1995
basic realtime interactivity
gigantic multibillion dollar webapps
keep JS semantics
no relation to JS
Compile-to-JS
elm
keep CSS semantics
no relation to CSS
style-elements
Compile-to-CSS
style-elements
style-elements
Compiles to JS, CSS, and DOM
Written in Elm
Clean-slate semantics
style-elements Design Goals
Create maintainable user interfaces
Long-term cross-platform support
Have one compatibility table
new set of layout primitives
clear
your
mind
1
2
column
1
row
1
row
2
3
row
row
1
2
3
spacing
spacing
spacing
spacing
column
1
2
3
padding
below
1
2
column
1
row
2
3
row
column
below
row? column? below?
row? column? below?
alignLeft
center
alignRight
width (fillPortion 1)
within
Responsiveness
if viewportWidth < 640 then
menu center
Responsiveness
if viewportWidth < 640 then
menu center
else if viewportWidth < 1024 then
Responsiveness
if viewportWidth < 640 then
menu center
else if viewportWidth < 1024 then
List.append [ logo ] (menu alignRight)
Responsiveness
if viewportWidth < 640 then
menu center
else if viewportWidth < 1024 then
List.append [ logo ] (menu alignRight)
else
List.append [ logo, tagline ] (menu alignRight)
Responsiveness
Accessibility
Alt text for images is a required argument
row
column
below/within
spacing
padding
alignment
fillPortion
Responsive!
Designed for maintainability
How should deeply nested layouts interact?
How can we make consistent APIs?
“If it compiles, it styles”
early adopter:
25K → 15K
lines of code
CAUTION: Massive effort, under heavy development!
Clean-Slate Semantics
100% separate package ecosystem, no npm
no runtime exceptions in 2 years and 200,000 LoC
semantic versioning automatically enforced
elm
Want to learn more?
Friday Workshop!
GUIDE
guide.elm-lang.org
SLACK
elmlang.herokuapp.com
CSS was never intended
to create user interfaces
...but we can build a new foundation
by using CSS as bytecode!
@rtfeldman
github.com/rtfeldman/style-elements-demo