The Unseen Performance Costs of Modern CSS-in-JS Libraries

This piece draws heavily on data gathered by Aggelos Arvanitakis, but its most useful takeaway comes at the very end.

Investigate whether a zero-runtime CSS-in-JS library can work for your project. Sometimes we tend to prefer writing CSS in JS for the DX (developer experience) it offers, without a need to have access to an extended JS API. If you app doesn’t need support for theming and doesn’t make heavy and complex use of the css prop, then a zero-runtime CSS-in-JS library might be a good candidate.

With "zero-runtime," styles are still authored in a CSS-in-JS syntax, but the output is ordinary .css files, just as a CSS preprocessor would emit. That moves the tool into an entirely different category: it becomes purely a developer tool, so the people visiting the site no longer bear the cost of using it.

The leading zero-runtime CSS-in-JS library is Linaria, whose syntax the author finds quite nice.

import { css } from 'linaria';
import fonts from './fonts';

const header = css`
  text-transform: uppercase;
  font-family: ${fonts.heading};
`;

<h1 className={header}>Hello world</h1>;

The author is likewise a fan of the just do scoping for me capability that CSS modules provides, which is achievable in a zero-runtime style as well.