The React core team finally have opinions about CSS
Tags: react, css, performance
Published: 2022-06-24 14:52:16

---
title: The React core team finally have opinions about CSS
published: true
description: CSS-in-JS, performance, and the best way to style a React application
tags: React, CSS, performance
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
---

At a [recent Q&A](https://youtu.be/jWafEXS7EE0?t=1276) Dan Abramov talked of the React core team becoming more opinionated about styling approaches:

“We used to be very unopinionated about styling. We’re getting a few more opinions now because there are a few more constraints like streaming server rendering, server components. We start caring a bit more about performance. Overall we’re thinking __for dynamic stuff just use inline styles. For things that don’t change use something that compiles to CSS so that it doesn’t have extra runtime costs__. A lot of these approaches with runtimes are really expensive.” 

This statement reiterated what had already been [said by Sebastian Markbage](https://github.com/reactwg/react-18/discussions/110#:~:text=While%20this%20technique,use%20at%20Facebook.).

CSS-in-JS solutions with a runtime include libraries like Emotion and Styled Components, which still remain popular. 

Their impact on performance is a topic that Alex Russell, a Product Manager on Microsoft Edge, has harped on about for years, referring to the approach as a "full-on catastrophe", [writing](https://twitter.com/slightlylate/status/1517173353869561857): 

"At load time we can parallelise parsing of CSS, JS, and HTML. But when you stuff your CSS into JS, it means we need to parse & run JS to get rules into the doc."

Facebook/Meta had announced plans to open source [their own zero-runtime CSS-in-JS tool](https://engineering.fb.com/2020/05/08/web/facebook-redesign/), but that was several years ago so may never happen. There are several open source alternatives. An engineer at Airbnb recently [blogged about](https://medium.com/airbnb-engineering/airbnbs-trip-to-linaria-dc169230bd12) that companies move from a runtime CSS-in-JS library to [Linaria](https://github.com/callstack/linaria), a zero runtime option. 

There’s also [Vanilla Extract](https://vanilla-extract.style/) from Mark Dalgleish (a co-creator of CSS Modules), another zero runtime tool that involves writing styles in TypeScript and compiling them to static CSS files at build time. In my opinion the idea of writing styles in Typescript sounds appalling, but it’s not without its fans.

It’s been Tailwind, a [JIT (Just In Time) compiled](https://tailwindcss.com/blog/tailwindcss-v3#just-in-time-all-the-time) atomic CSS library (with no client-side runtime), that has really taken off, with fifty eight thousand GitHub stars at the time of writing. 

Or you could _just write CSS_. With CSS itself getting more powerful with features like `@layer`, it’s fair to say that some of the original rationale for CSS-in-JS is less relevant today. Importing a SASS or CSS file at the top of a JSX file still works well for me. As someone that spends time designing in the browser I’d be happy to never see an unreadable machine-generated class like `.atm_5tsdf` ever again.