Přejít k hlavnímu obsahu
← 🎨 CSS as a design system·Modul B8 · Lekce 9
ÚkolRead the theory above. Then build a single styled button in plain CSS (no CSS-in-JS): .button { padding: 8px 16px; background: #3B82F6; color: white; border-radius: 8px; border: none; cursor: pointer; }.

CSS-in-JS: případ proti (pro vývojáře Pythonu)

75 XP6 min
Teorie

What is CSS-in-JS

Libraries like styled-components, Emotion, Stitches:

const Button = styled.button`
  background: ${props => props.primary ? "#3B82F6" : "#e5e7eb"};
  color: white;
  padding: 8px 16px;
`;

Styles live inside JS, generated at runtime, injected into a <style> tag.

Why this got popular (2016-2020)

  • CSS modules + Sass were verbose.
  • Themes were hard to wire up.
  • Dynamic styles (based on props) needed JS anyway.
  • Tooling was JS-heavy already.

Why it's losing in 2026

  1. Runtime cost. Every render parses + serializes styles. Real perf hit.
  2. Larger bundles. Library + your styles + theme tokens ship together.
  3. Hydration cost. Styles initialize AFTER React boots — flicker.
  4. Native CSS caught up. @scope + @layer + custom properties + nesting do everything styled-components did, natively.
  5. Tailwind exists. For dynamic-style use cases, Tailwind's class composition + JS conditionals is faster.

The 2026 answer

For a backend dev who just wants a UI:

  • Don't reach for styled-components.
  • Do use plain CSS files OR Tailwind.

CSS in a .css file is faster, easier to debug, and produces smaller bundles. The "ergonomic" arguments for CSS-in-JS evaporated when native CSS shipped scoping, nesting, and custom properties.

When CSS-in-JS still makes sense

  • Existing codebases (don't rewrite a working styled-components app).
  • Component libraries that need to ship "themeable" components (Radix, Mantine).
  • Pages with truly per-user, runtime-computed styles.

For 95% of "I just need a UI on my Python backend" — plain CSS or Tailwind wins.

This lesson is theory-only — no code task. Read, understand, move on.

🔒

Zaregistruj se a začni programovat

Teorie je otevřená pro každého. Editor, živý náhled a check se odemknou s 7denní zkušební verzí zdarma — karta vyžadována, zrušíš kdykoli.

Registrace — zkušební verze zdarma →

Prvních 10 lekcí v každé trase je zdarma. Karta není potřeba.

← PředchozíDalší lekce →

Jeden tip k Pythonu nebo webu denně — e-mailem

Krátké, ručně psané, žádný spam. Odhlásit jedním klikem.