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
CSS in JS: The Good & Bad Parts
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Robin Frischmann
October 25, 2017
Programming
2.4k
6
Share
CSS in JS: The Good & Bad Parts
Slides for my talk at ReactiveConf 2017 in Bratislava, Slovakia.
Robin Frischmann
October 25, 2017
More Decks by Robin Frischmann
See All by Robin Frischmann
Reusability: Sharing components with joy
rofrischmann
1
250
Components done right™
rofrischmann
0
190
Other Decks in Programming
See All in Programming
20260320登壇資料
pharct
0
170
安いハードウェアでVulkan
fadis
1
930
存在論的プログラミング: 時間と存在を記述する
koriym
5
840
Kubernetes上でAgentを動かすための最新動向と押さえるべき概念まとめ
sotamaki0421
3
440
瑠璃の宝石に学ぶ技術の声の聴き方 / 【劇場版】アニメから得た学びを発表会2026 #エンジニアニメ
mazrean
0
190
PCOVから学ぶコードカバレッジ #phpcon_odawara
o0h
PRO
0
240
メッセージングを利用して時間的結合を分離しよう #phperkaigi
kajitack
3
570
Symfony + NelmioApiDocBundle を使った スキーマ駆動開発 / Schema Driven Development with NelmioApiDocBundle
okashoi
0
270
今こそ押さえておきたい アマゾンウェブサービス(AWS)の データベースの基礎 おもクラ #6版
satoshi256kbyte
1
230
「効かない!」依存性注入(DI)を活用したAPI Platformのエラーハンドリング奮闘記
mkmk884
0
310
まかせられるPM・まかせられないPM / DevTech GUILD Meetup
yusukemukoyama
0
110
2026-03-27 #terminalnight 変数展開とコマンド展開でターミナル作業をスマートにする方法
masasuzu
0
310
Featured
See All Featured
Become a Pro
speakerdeck
PRO
31
5.9k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
64
54k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
120
Building Adaptive Systems
keathley
44
3k
Amusing Abliteration
ianozsvald
1
150
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
110k
Accessibility Awareness
sabderemane
0
94
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
480
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.3k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.3k
The agentic SEO stack - context over prompts
schlessera
0
740
Transcript
CSS in JS The Good & Bad Parts ReactiveConf 2017
Robin Frischmann @rofrischmann @rofrischmann
None
rofrischmann/fela
Who is already familiar with CSS in JS ?
CSS in JS 101
CSS in JS !!!== inline style
const style = { fontSize: 12, color: 'red', ':hover': {
color: 'blue' }, '@media (min-width:320px)' { fontSize: 12 } } const style = ` font-size: 12px; color: red; &:hover { color: blue; } @media (min-width:320px) { font-size: 14px; } } ` Objects Template strings
The Problems
Choosing the “right” library 1
• aphrodite • babel-plugin-css- in-js • babel-plugin-pre- style • bloody-react-styled
• classy • csjs • css-constructor • css-light • css-loader • css-ns • cssobj • cssx-loader • emotion • es-css-modules • glamor • glamorous • hyperstyles • i-css • j2c • jsxstyle • linaria • pre-style • radium • react-css-builder • react-css- components • react-css-modules • react-cssom • react-cxs • react-fela • react-free-style • react-inline-css • react-inline-style • react-inline • react-jss • react-look • react-native-web • react-statics-styles • react-styl • react-style • react-styleable • react-stylematic • react-theme • react-vstyle • reactcss • restyles • scope-styles • smart-css • stile-react-media- queries • stilr • style-it • styled-components • styled-jsx • styletron-react • styling • superstyle • typestyle • uranium
Use what works for you!
1. Objects or Template Strings? 2. Working with Designers? 3.
Simplicity or Flexibility? 4. React-centric or Framework-agnostic? 5. Server-side Rendering?
None
Not everyone is used to JavaScript 2
1. Choosing a library is hard 2. Using CSS in
JS does not always turn out to be a good choice at all
The Benefits
It’s JavaScript! 1
Who has used or is using a preprocessor like Sass,
Less or Stylus? ?
JavaScript everywhere!
$primary-color = red .button { color: $primary-color; padding: 15px 20px;
font-size: 20px; } const primaryColor = 'red' const buttonStyle = { color: primaryColor, padding: '15px 20px', fontSize: 20 } (S)CSS JS
$vendors: "-webkit-", "-ms-", ""; @mixin prefix($property, $value) { @each $vendor
in $vendors { !#{$vendor}!#{$property}: !#{$value}; } } .button { @include prefix( 'border-radius', '5px' ) } const vendors = ['-webkit-', '-ms-', ''] function prefix(property, value) { return vendors.reduce( (style, vendor) !=> { style[vendor + property] = value return style }, {} ) } const buttonStyle = { !!...prefix( 'border-radius', '5px' ) } SCSS JS
Ecosystem
styled-components/polished
Computers do the hard work 2
– Phil Karlton “There are only two hard things in
Computer Science: cache invalidation and naming things.”
Naming CSS classes is hard
BEM smacss.com oocss.org getbem.com OOCSS SMACSS
Conventions !!!== enforced
Computers for the rescue!
Class Names? Non of my business!
– Alan B Smith “[…] the appeal of CSS-in-JS is
not simplicity, rather predictability and consistency.” Source: https://hackernoon.com/why-we-use-styled-components-at-decisiv-a8ac6e1507ac
Predictable Styling 3
Who has ever accidentally destroyed the layout or styles of
some part of the application, while actually working on something completely different? ?
const view = () !=> ( <div className={ 'text_green' }>
Some Text !</div> ) .text_green { color: green } JS(X) CSS
const view = state !=> ( <div className={ state.error ?
'text_red' : 'text_green' }> Some Text !</div> ) .text_red { color: red } .text_green { color: green } JS(X) CSS
const view = state !=> ( <div className={ state.error ?
'text_red' : 'text_green' }> Some Text !</div> ) .text_red { font-size: 20px; color: yellow; } .text_green { color: green } JS(X) CSS
UI = f(state)
#1 What is displayed #2 How is it displayed
How What Markup Styling HTML CSS
UI = f(state)
Style = f(state)
import { css } from 'any-css-in-js-library' const style = state
!=> ({ color: state.error ? 'red' : 'green' }) const view = state !=> ( <div className={css(style(state))}> Simple Text !</div> ) JS(X)
- Choosing a library is hard - Using CSS in
JS is not necessarily the best choice ✓ Power of JavaScript ✓ Unique generated classes ✓ Predictable UI Benefits Problems
@rofrischmann @rofrischmann
Thank you! @rofrischmann @rofrischmann