Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

React
  • One Request, Two Answers: the Same Post as an HTML Page and as JSON
  • A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx
  • How a Web Page Works: HTML Tags, Elements and Attributes
  • Semantic HTML: header, nav, main, aside and footer as Page Landmarks
  • HTML Forms: Labels, Names, Input Types and Where the Data Goes (GET vs POST)
  • CSS Basics: Selectors, Which Rule Wins, and the Box Model
  • CSS Flexbox vs Grid: A Nav Bar, a Card Row and a Dashboard
  • Responsive CSS: Viewport, Mobile-First Media Queries, clamp() and Dark Mode with Tokens
  • JavaScript for People Who Already Code: Syntax, Modules and Five Surprises
  • JavaScript Arrays the Functional Way: map, filter, reduce, find, sort and Object.entries
  • Async JavaScript: Promises, async/await, fetch and Promise.all
  • JavaScript in the Page: the DOM, querySelector and Events
  • npm, package.json and Vite: What npm install Fetches and How Vite Serves and Builds Your Page
  • TypeScript Essentials: Types Checked, Then Erased (Interfaces, Unions, Generics)
  • Why React, JSX and Components: The Page as a Function of Data
  • React Props and Composition: Data Down, Calls Up, Children in the Slot
  • Routing With React Router: One Page, Many Addresses
  • React Component Tests With Vitest and Testing Library: Test What the User Sees
  • End-to-End Tests for a React App With Playwright: A Full Dress Rehearsal
  • Why AI-Built Websites All Look the Same, and Four Levels That Fix It
  • Visual Hierarchy, Spacing and the 8-Point Grid: Tell the Eye What to Read First
  • Colour, Contrast and Dark Palettes: 60-30-10, Semantic Tokens and Ratios You Can Compute
  • Typography That Sells: Type Scale, Line Length and Free Font Pairings
  • The UI Element Catalogue: Buttons to Toasts, Their Jobs, States and shadcn/ui Names
  • Design Tokens: Primitive and Semantic Tokens, from Figma to CSS to Tailwind
  • Tailwind CSS 4 in React: Utility Classes, Responsive Prefixes, Hover and Dark Mode
  • shadcn/ui in React: Components You Own, Edit and Commit
  • Design Tokens to a Tailwind Theme: Light and Dark Mode with @theme inline
  • Motion in React: Entrance, Hover, Exit and Layout Animations
  • A React Dashboard: Stat Cards, a Recharts Line Chart and a Sortable Table
  • Accessibility in Practice: Dialogs, Menus and the Keyboard in React
  • Reference-Driven Design: Extract a DESIGN.md From a Site You Admire and Build From It
  • Components, Variants and Variables: One Design System in Figma and in CSS
  • Figma MCP Server: Build a React Component From a Frame, Then Write It Back
  • Claude Design: From a Brief to a Clickable Prototype, Then Hand It Off to Claude Code
  • Critiquing AI-Generated UI: Six Checks for Every Screen
  • The AI Design Landscape: Prompt to UI, Prompt to App, and Design to Code
  • Your Brand Rules Folder: One Folder Every AI-Built Page Follows
  • The Best-Practice UI Prompt: Plain Sentences That Beat the Average AI Page
  • UI Ideas From Figma Make, Google Stitch and ChatGPT: One Prompt, Three Designs
  • Google Stitch From a Sketch or Screenshot: Show the Layout, Say What to Keep
  • Stitch to Figma to Code: Turn a Stitch Screen Into Code That Uses Your Tokens
  • Figma Make: Prompt to Prototype With a Four-Part Prompt
  • Upgrade a Dated UI From One Screenshot (or a Reference Image)
  • States and Feedback: Make Every Click Get an Answer
  • A Design-Loop Skill: Claude Screenshots, Scores and Fixes Its Own UI
  • Copy Without the AI Tells: A Copy Pass on a Landing Page
  • React State, Events, Lists and Conditional Rendering: Follow One Click
  • React useEffect: When It Runs, What Cleanup Is For, and When You Don't Need One
  • Lifting State Up, Refs and React DevTools: Put State Where It Is Needed
  • Forms and Actions in React 19: Controlled Inputs, Form Actions, useActionState and useFormStatus
  • React Context and Custom Hooks: Share One Value, Reuse the Logic
  • Server State With TanStack Query: One Key, One Request, One Cache
  • Mutations and Optimistic Updates in TanStack Query: Change Data, Then Tell the Cache
  • Generate TypeScript Types, Query Hooks and Zod From an OpenAPI Spec With Orval
  • A Mock Backend in the Browser With Mock Service Worker, Generated From the Spec
  • A React Client for a FastAPI API: The CORS Wall, CORSMiddleware and the Vite Proxy
  • Forms With React Hook Form and Zod: The API's Rules in the Browser, the Server's Errors Under the Field
  • JWT Auth in a React Client With a FastAPI Backend: Log In, Carry the Token, Let the Server Decide
  1. Blog
  2. /
  3. React
  4. /
  5. Fundamentals

Design Tokens to a Tailwind Theme: Light and Dark Mode with @theme inline

Name a colour once and one switch changes the whole page: tokens.css with :root and .dark values, @theme inline in index.css, a React page with only token classes, a ThemeToggle that flips one class on html, and what one hard-coded bg-white breaks.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Fundamentals

What you will learn

  • Store light and dark values under the same token names in tokens.css
  • Register the tokens with Tailwind CSS 4 using @theme inline
  • Build a React page that uses only token classes like bg-page and text-ink
  • Switch the whole theme by toggling one dark class on the html element

Before you start

  • Tailwind CSS 4 in React
  • Design Tokens: Primitive and Semantic Tokens

Think about a paint tin with a label. The label says page. It describes the wall behind everything. In light mode the paint inside is almost white, and in dark mode it is a deep navy. The label never changes. Only what is in the tin does.

Those labels are design tokens: names for values. In this article you take the colours from a design, turn them into a Tailwind CSS 4 theme, and flip a whole React page between light and dark with one switch. The page is small: a card with a Done badge, a title, an owner and a button.

The labels: page, card, ink, brand

TokenJobLightDark
--pageThe wall behind everything#f8fafc#0b1120
--cardA panel on the wall#ffffff#1e293b
--inkMain text#0f172a#f1f5f9
--brandButtons and links#4f46e5#818cf8
--ok-bgThe Done badge#dcfce7#14532d

The page asks for page, never for a colour. Change what is in the tin and every wall follows.

From Figma to a class, one name all the way

One token name from Figma to a Tailwind class 1. Figmacolor/page 2. tokens.css--page 3. @theme inline--color-page 4. Classbg-page The name never changes. Only the value behind it does.
The token "page" from the design file to the class in the component.

The designer creates a variable in Figma called color/page. You copy the name and its values into a CSS file as --page. You register it in the Tailwind theme as --color-page: var(--page), which links your variable to Tailwind. Tailwind then gives you the class bg-page. If the idea of tokens is new, the background is in primitive and semantic design tokens. Here we wire them into a React app that switches themes.

tokens.css: names and values

:root {
  --page: #f8fafc;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-soft: #475569;
  --line: #e2e8f0;
  --brand: #4f46e5;
  --on-brand: #ffffff;
  --ok-bg: #dcfce7;
  --ok-ink: #166534;
}

.dark {
  --page: #0b1120;
  --card: #1e293b;
  --ink: #f1f5f9;
  --ink-soft: #94a3b8;
  --line: #334155;
  --brand: #818cf8;
  --on-brand: #0b1120;
  --ok-bg: #14532d;
  --ok-ink: #bbf7d0;
}

:root on line 1 holds the light values. .dark on line 13 repeats the same names with dark values. Look at --brand on line 19: same name, but a lighter indigo, because a light indigo reads better on a dark page. Only the values change, never the names.

index.css: @theme inline

@import "tailwindcss";
@import "./tokens.css";

@theme inline {
  --color-page: var(--page);
  --color-card: var(--card);
  --color-ink: var(--ink);
  --color-ink-soft: var(--ink-soft);
  --color-line: var(--line);
  --color-brand: var(--brand);
  --color-on-brand: var(--on-brand);
  --color-ok-bg: var(--ok-bg);
  --color-ok-ink: var(--ok-ink);
  --radius-card: 1rem;
}

First Tailwind is imported, then the tokens file. Then @theme inline tells Tailwind about the names. --color-page: var(--page) gives you bg-page, text-page and so on.

Why inline? Because the colour must be read from your variable at the moment the page is drawn. That is what lets it change between light and dark. And it is not only colours: --radius-card: 1rem gives you the class rounded-card.

App.tsx: only token classes

import { ThemeToggle } from "./ThemeToggle";

export default function App() {
  return (
    <main className="min-h-screen space-y-6 bg-page p-6 text-ink">
      <header className="flex justify-between">
        <h1 className="text-2xl font-bold">Team tasks</h1>
        <ThemeToggle />
      </header>
      <section className="rounded-card bg-card p-6 shadow">
        <span className="rounded-full bg-ok-bg px-3 text-ok-ink">
          Done
        </span>
        <h2 className="mt-3 text-xl font-semibold">Write report</h2>
        <p className="mb-4 text-ink-soft">Owner: Emma</p>
        <button className="rounded bg-brand px-4 py-2 text-on-brand">
          Open task
        </button>
      </section>
    </main>
  );
}

main uses bg-page and text-ink. The card uses bg-card and rounded-card. The button uses bg-brand with text-on-brand. There are no colour codes anywhere. The component says what it is, and the theme decides how it looks.

The switch: one class on html

import { useState } from "react";

export function ThemeToggle() {
  const [dark, setDark] = useState(() =>
    document.documentElement.classList.contains("dark")
  );

  function flip() {
    const next = !dark;
    document.documentElement.classList.toggle("dark", next);
    localStorage.setItem("theme", next ? "dark" : "light");
    setDark(next);
  }

  return (
    <button
      onClick={flip}
      className="rounded-lg border border-line px-3 py-1"
    >
      {dark ? "Light mode" : "Dark mode"}
    </button>
  );
}

On line 10, a click toggles one class, dark, on the html element. The moment it is there, the .dark values win and the whole page changes. Line 11 saves the choice in localStorage so the browser remembers it. The button label follows the state: "Light mode" when dark is on, "Dark mode" otherwise.

One more line, in index.html, puts the class back before the page paints, so there is no flash of light on reload:

<script>
  document.documentElement.classList.toggle("dark", localStorage.getItem("theme") === "dark");
</script>

The same set, light then dark

The Team tasks page twice. Left, light: a white card on a pale page with a light green Done badge, the title Write report, Owner: Emma and an indigo Open task button, and a Dark mode button at the top. Right, dark: a slate card on a navy page, a dark green badge, light text, a softer indigo button and a Light mode button.
Left: no class on html. Right: after the click, class="dark".

The badge, the card and the button all adapted. None of the classes changed. Only the variable values did. Do not worry about memorising the colours. With AI you can generate a whole palette in seconds. You need the foundation so you know where it goes.

Break it: one hard-coded colour ignores the switch

Change the card on line 10 of App.tsx:

// before
<section className="rounded-card bg-card p-6 shadow">
// after
<section className="rounded-card bg-white p-6 shadow">

Switch to dark mode:

Dark mode with the broken card: the page is navy, but the card stays white and the light Write report title is almost invisible on it.
The page turned dark, the card stayed white, and the title almost vanished.

Everything else turned dark, but the card stays white, and the light title is almost invisible on it. bg-white never reads a token. It does not know the theme exists. Go back to bg-card and the card follows the theme again.

Why this pays off in a big app

TaskColour codes in classesTokens
Change the brand colourEdit every fileEdit one line
Add dark modeRepeat it on every classWrite one .dark block
Match the designerCopy values by eyeSame names as Figma
Keep a big app tidyColours slowly drift apartOne source of truth

Common mistakes

  • Forgetting the script in index.html. Without it, a dark-mode user sees a flash of light on every reload.
  • Mixing dark: prefixes with tokens. With tokens you do not need dark:bg-slate-800 on each tag. The .dark block does it once.
  • One stray bg-white or hex colour. It is the one thing that will not switch.

Recap

Tokens are names for values. The theme connects those names to Tailwind. The switch is one class on html. One name, both themes. We covered the foundations, and AI can generate the rest. Try it yourself: add a --warn-bg and --warn-ink pair to both blocks, register them in @theme inline, and add a "Due soon" badge that works in both modes.

Keep going in React · 28 of 59

Previous
shadcn/ui in React: Components You Own, Edit and Commit
Next post
Motion in React: Entrance, Hover, Exit and Layout Animations
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Related posts

One Request, Two Answers: the Same Post as an HTML Page and as JSON

Ask a Django blog for the same post twice: once as a 12,731-byte HTML page built by a template, once as 2,976 bytes of JSON built by a serializer. Compare the headers, see who builds the page, and why the server still owns every write.

A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx

Make a blog design from a prompt in Figma Make, download src.zip, unzip it with Python's zipfile module, and read the two files that matter: App.tsx with its selectedPost state and BlogCard.tsx with its props.

How a Web Page Works: HTML Tags, Elements and Attributes

A web page is a text file full of labelled pieces. Learn tags, attributes and nesting with three tiny pages, and see what breaks when an attribute or a closing tag is wrong.

Semantic HTML: header, nav, main, aside and footer as Page Landmarks

The same page written as div soup and with semantic tags looks identical, but only one gives screen readers and search engines landmarks and an outline. Plus tables, div, span and the one-main rule.

On this page

  • The labels: page, card, ink, brand
  • From Figma to a class, one name all the way
  • tokens.css: names and values
  • index.css: @theme inline
  • App.tsx: only token classes
  • The switch: one class on html
  • The same set, light then dark
  • Break it: one hard-coded colour ignores the switch
  • Why this pays off in a big app
  • Common mistakes
  • Recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.