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

Components, Variants and Variables: One Design System in Figma and in CSS

Build a button, badge and card once, give them variants, and bind every colour to a variable with Light and Dark modes. Then see the same set in HTML: tokens.css, modifier classes and data-theme.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Fundamentals

What you will learn

  • Explain a main component and its instances, and why one edit updates every copy
  • Use variant properties (style, size, state) instead of copy-and-paste buttons
  • Bind fills to variables with Light and Dark modes so a mode switch repaints everything
  • Map components, variants, variables and modes to CSS classes, modifiers, custom properties and data-theme

Before you start

  • The UI Element Catalogue: Buttons to Toasts, Their Jobs, States and shadcn/ui Names
  • Basic HTML and CSS custom properties

Think of a cookie cutter. It is one master shape. Press it again and again and every cookie has the same shape. Swap the icing jar and every cookie changes colour, without you touching a single cookie by hand.

That is the whole idea behind a small design system. The cutter is a component, the different shapes you can press are variants, and the icing jar is a variable. This article builds a button, a badge and a card that way in Figma, then shows the same set in HTML and CSS, in light and dark mode.

A component is a master you reuse

In Figma you draw a button (a rectangle plus a "Save" label, with auto layout, corner radius 10 and padding 10 / 18), then choose Create component and name it Button. That is the main component. Drag two copies into a frame called "Login form", and those copies are instances.

Change the main component, say the corner radius from 10 to 14, and both instances follow. Change it once and every button in the project changes.

Variants: many looks from one master

A real button has more than one look. Instead of copying it, add variant properties to the main component:

PropertyValues
Styleprimary, secondary, danger
Sizesmall, medium, large
Statedefault, hover, disabled

Three styles and three sizes already give nine buttons, all inside one component, and you drew only one. On an instance you pick the look from a dropdown.

Badge and card

The badge has one property, Status: success, warning or error. The card has a title, a line of text, a badge and a button, and that badge and button are instances. Components can sit inside other components, so you build the small pieces first and the card simply reuses them.

Variables: a value for every mode

A variable is a named value. In a collection called "Colors" with two modes, Light and Dark, each variable holds one value per mode. The button's fill is not painted with a colour; it is bound to color/primary. The label binds to color/on-primary, the card fill to color/surface, the text to color/text.

One name, two values Variable Light Dark color/surface #ffffff #1e293b color/page #f1f5f9 #0f172a color/text #0f172a #f1f5f9 color/primary #4f46e5 #818cf8 color/danger #dc2626 #f87171 Button fill is bound to color/primary: the mode decides the colour.
Same name, two values. The two columns are the modes. Values from the project's tokens.css.

Light to dark, step by step

  1. Select the frame that holds the set.
  2. Change its mode from Light to Dark.
  3. Every variable gives its dark value; surface becomes the deep blue grey.
  4. Every layer bound to a variable repaints: buttons, card and badges.

You never recoloured a single layer. You only changed the mode.

A colour typed by hand ignores the mode

Now type #FFFFFF by hand into one card's fill and switch to Dark. The text turns light, as it should, but this fill is not bound to anything, so it stays white, and the light text disappears on it. The rule: no hand-typed colours inside components. Rebind it to color/surface and it works again.

The same set in HTML and CSS

Here is how the same ideas look in code. The variables are CSS custom properties, one block per mode:

/* Design variables (tokens). One name, two values: one per mode. */
:root,
[data-theme="light"] {
  --color-surface: #ffffff;
  --color-page: #f1f5f9;
  --color-text: #0f172a;
  --color-muted: #475569;
  --color-border: #cbd5e1;
  --color-primary: #4f46e5;
  --color-on-primary: #ffffff;
  --color-danger: #dc2626;
  --color-success-bg: #dcfce7;
  --color-success-text: #166534;
  --color-warning-bg: #fef3c7;
  --color-warning-text: #92400e;
  --color-error-bg: #fee2e2;
  --color-error-text: #991b1b;
  --radius: 10px;
  --space: 16px;
}

[data-theme="dark"] {
  --color-surface: #1e293b;
  --color-page: #0f172a;
  --color-text: #f1f5f9;
  --color-muted: #94a3b8;
  --color-border: #475569;
  --color-primary: #818cf8;
  --color-on-primary: #0f172a;
  --color-danger: #f87171;
  --color-success-bg: #14532d;
  --color-success-text: #bbf7d0;
  --color-warning-bg: #78350f;
  --color-warning-text: #fde68a;
  --color-error-bg: #7f1d1d;
  --color-error-text: #fecaca;
}

The components are classes, and variants are modifier classes. Colours come only from variables:

/* Components. Variants are modifier classes. Colours come only from variables. */
.ds-btn {
  font: 600 16px system-ui, sans-serif;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 2px solid var(--color-primary);
  background: var(--color-primary);
  color: var(--color-on-primary);
  cursor: pointer;
}
.ds-btn.secondary { background: transparent; color: var(--color-primary); }
.ds-btn.danger { background: var(--color-danger); border-color: var(--color-danger); color: var(--color-on-primary); }
.ds-btn.small { padding: 6px 12px; font-size: 14px; }
.ds-btn.large { padding: 14px 26px; font-size: 18px; }
.ds-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.ds-badge {
  display: inline-block;
  font: 700 13px system-ui, sans-serif;
  padding: 4px 10px;
  border-radius: 999px;
}
.ds-badge.success { background: var(--color-success-bg); color: var(--color-success-text); }
.ds-badge.warning { background: var(--color-warning-bg); color: var(--color-warning-text); }
.ds-badge.error { background: var(--color-error-bg); color: var(--color-error-text); }

.ds-card {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space);
  font-family: system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ds-card h3 { margin: 0; font-size: 20px; }
.ds-card p { margin: 0; color: var(--color-muted); }

The page shows the same set twice, and only data-theme changes (an excerpt of index.html):

  <!-- the same set twice: only data-theme changes -->
  <section class="mode" data-theme="light">
    <h2>Light mode</h2>
    <div class="row">
      <button class="ds-btn">Save</button>
      <button class="ds-btn secondary">Cancel</button>
      <button class="ds-btn danger">Delete</button>
      <button class="ds-btn" disabled>Disabled</button>
    </div>
    <div class="row">
      <span class="ds-badge success">Done</span>
      <span class="ds-badge warning">Pending</span>
      <span class="ds-badge error">Late</span>
    </div>
    <article class="ds-card">
      <h3>Order #1042</h3>
      <p>2 items, ready to ship.</p>
      <div class="row"><span class="ds-badge success">Paid</span><button class="ds-btn small">Open</button></div>
    </article>
  </section>

The dark section is the same markup with data-theme="dark". Change --color-primary in tokens.css, refresh, and every primary button on the page changes.

Figma and code, side by side

IdeaFigmaCode
A reusable pieceComponent (main + instances)A class, or a React component
Another lookVariantA modifier class (.ds-btn.danger) or a prop
A shared valueVariableA CSS custom property (--color-primary)
Light or darkModedata-theme="dark"

When the designer and the developer use the same names, the hand-over gets much easier. How to name those variables in layers, primitive and semantic, is the subject of Design Tokens: Primitive and Semantic Tokens.

Common mistakes

  • A new component for every look. Nine separate buttons drift apart. One component with variant properties stays in step.
  • Hand-typed colours. They ignore the mode. Bind every fill and stroke to a variable.
  • Hex values in components.css. The same mistake in code: background: #fff never changes in dark mode. Use var(--color-surface).

Quick recap

IdeaOne line
ComponentBuild once, reuse; edit the main and every instance follows
VariantMany looks from one master: style, size, state
VariableA named value with one value per mode
Mode switchEvery bound layer repaints; nothing is recoloured by hand

These are the foundations. AI can generate this code for you, but now you know what to ask for and how to check it. The project files and sample prompts are in the StudyEasy AI Community, free to join.

Keep going in React · 33 of 59

Previous
Reference-Driven Design: Extract a DESIGN.md From a Site You Admire and Build From It
Next post
Figma MCP Server: Build a React Component From a Frame, Then Write It Back
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

  • A component is a master you reuse
  • Variants: many looks from one master
  • Badge and card
  • Variables: a value for every mode
  • Light to dark, step by step
  • A colour typed by hand ignores the mode
  • The same set in HTML and CSS
  • Figma and code, side by side
  • Common mistakes
  • Quick 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.