Extract a design system from any website into Tailwind design tokens
Measure the type, colors, spacing and radius of a site you like with one console script, turn the numbers into Tailwind v4 @theme tokens, and make Claude Code stick to them.

The short version
- Run one console script on a page you like. It counts the fonts, sizes, colors, spacing and radii. Keep the values that repeat.
- Round the values into a short scale, name each token by its job, and write them as Tailwind v4 @theme variables with --color-*: initial.
- Take the measurements, not the content. Keep your own copy, logo and images, and tell Claude in CLAUDE.md to use only your tokens.
On this page
You found a site that looks right. It feels calm and expensive. You ask Claude Code to make yours “like that”. What you get shares maybe the headline size and nothing else.
The look you like isn’t one screenshot. It’s a small set of values used again and again: two or three font sizes, a few grays, one radius, a spacing step. That set is the design system. You can learn from it without copying anything.

Example: Echo, a designed Astro template on Aymu.
This tutorial turns a page you like into Tailwind CSS v4 tokens in four steps:
- Count the values the page really uses.
- Round them into a short scale.
- Write the scale as
@themetokens named by role. - Tell Claude to use those tokens and nothing else.
If you only need to match one section, the shorter method in Claude design prompts: give a reference, not adjectives is enough. This post is for when you want a whole site to feel the same everywhere.
Take the system, not the site
First, the line you shouldn’t cross. Measurements like “body text is 16px with 1.6 line height” or “cards have a 16px radius” are choices that many sites share. Copy, logos, illustrations, photos and a page layout people would recognize belong to the people who made them.

So the rule for this whole process is: take numbers, leave content. Your tokens come from the reference. Your words, images, brand color and page structure stay yours. You want a site as tidy as the one you like, not a site people mistake for it.
Step 1: count what the page uses
Dev tools show you the styles of one element at a time. That’s fine for a heading. But a design system is about repeats: which size shows up 200 times and which shows up once. A short script can count that for you.
Open the page in a Chromium browser like Chrome or Edge (that’s where we tested it). Open dev tools (F12, or Cmd+Option+I on a Mac), go to the Console tab and paste this:
(() => {
// Converts any CSS color (rgb, lab, oklch...) to hex by painting one pixel.
const ctx = document.createElement('canvas').getContext('2d', { willReadFrequently: true });
const hex = (color) => {
ctx.clearRect(0, 0, 1, 1);
ctx.fillStyle = color;
ctx.fillRect(0, 0, 1, 1);
const [r, g, b, a] = ctx.getImageData(0, 0, 1, 1).data;
const h = '#' + [r, g, b].map((n) => n.toString(16).padStart(2, '0')).join('');
return a === 255 ? h : `${h} at ${Math.round((a / 255) * 100)}%`;
};
const tally = {};
const add = (group, value) => {
if (!value || ['none', 'normal', '0px', 'rgba(0, 0, 0, 0)'].includes(value)) return;
tally[group] ??= {};
tally[group][value] = (tally[group][value] ?? 0) + 1;
};
for (const el of document.querySelectorAll('body *')) {
if (el.closest('pre, code, svg')) continue; // code samples and icons are not the design system
if (el.offsetWidth === 0 && el.offsetHeight === 0) continue; // hidden
const s = getComputedStyle(el);
const hasText = [...el.childNodes].some((n) => n.nodeType === 3 && n.textContent.trim());
if (hasText) {
add('font family', s.fontFamily.split(',')[0]);
add('size / line height / weight', `${s.fontSize} / ${s.lineHeight} / ${s.fontWeight}`);
add('letter spacing', s.letterSpacing);
add('text color', hex(s.color));
}
if (s.backgroundColor !== 'rgba(0, 0, 0, 0)') add('background', hex(s.backgroundColor));
add('radius', s.borderTopLeftRadius);
add('padding (vertical)', s.paddingTop);
add('padding (horizontal)', s.paddingLeft);
add('gap', s.rowGap);
add('max width', s.maxWidth);
}
const report = Object.entries(tally)
.map(([group, values]) => {
const rows = Object.entries(values).sort((a, b) => b[1] - a[1]).slice(0, 10);
return `${group}\n` + rows.map(([v, n]) => ` ${String(n).padStart(5)} ${v}`).join('\n');
})
.join('\n\n');
console.log(report);
return report;
})();
It goes through every visible element and reads its computed style (the final value after all CSS is applied). Then it prints the ten most common values in each group, with a count:
size / line height / weight
208 14px / 24px / 400
77 14px / 28px / 400
29 12px / 20px / 400
...
Some browsers ask you to type a phrase before they let you paste into the console. Read the script first, then do what the warning asks. Never paste code you haven’t read into a console, this one included.
Or let Claude run it
If your Claude Code setup has a browser tool connected (a browser extension or a browser MCP server), Claude can do it for you:
Open <reference URL> in your browser tool. Run the script in
design/tally.js in the page console and give me the full report.
Then scroll to the bottom of the page and run it again, in case
sections load late. Do not copy any text or images from the page.
Save the script as design/tally.js in your project first, so the agent runs exactly what you read.
What the numbers will look like
We tested the script in a Chromium-based browser on a public documentation page. Know these few things before you read your own report:
- Colors. Browsers report many modern colors as
lab(...)oroklab(...), not hex. That’s why the script paints each color onto a one-pixel canvas and reads it back as hex. See-through fills show up as#ffffff at 5%. - Pill shapes. A fully rounded button reports a huge radius, such as
1.67772e+07px. Read that as “pill”. - Odd decimals. Values like
8.4pxor11.2pxusually come from padding set inemunits. Note them, then round. - Font names. The family can be an internal nickname, not the public font name. Check the Network tab (filter by Font) to see which files load.
- Dark mode. If your browser or OS is in dark mode, many sites show their dark colors. If the site has both, run the script once in each mode.
Run it on two or three pages of the same site, like the home page, a content page and a pricing page. Values that repeat across pages are the system. Values that show up once are exceptions.
Step 2: round into a scale
Raw counts are messy. Turn them into a short list, one group at a time.
Type. Keep four to six size and line-height pairs: a display size, one or two heading sizes, body, small and
caption. If you see 15px once and 16px four hundred times, body is 16px.
Color. Sort the colors by job, not shade: the page background, the card or panel background, a darker background for controls, main text, secondary text, and the one accent. Aim for fewer than ten color tokens. Twelve grays are often three grays plus rounding differences.
Spacing. Tailwind v4 builds its spacing classes from one base value, --spacing, which is 0.25rem (4px) by
default. p-4 compiles to calc(var(--spacing) * 4), which is 16px. Round every measured padding and gap to the
nearest 4px step, and you usually need no custom spacing tokens at all.
Radius. One radius for controls, one for cards or panels, and “pill” if the site uses it. Three values is enough.
Widths. The main content width and a reading width for long text.
How to choose a website color palette (with Tailwind tokens) goes deeper on picking colors. Here you’re only writing down what the reference already chose.
Step 3: write the tokens
Now write the scale as Tailwind v4 theme variables. Name every token by its job, never by its value. surface still
makes sense when you change the color. gray-50 doesn’t.

Here’s a shorter version of the theme on our own site, src/styles/global.css, as a worked example:
@import 'tailwindcss';
:root {
/* Surfaces */
--c-canvas: #fafafa;
--c-surface: #ffffff;
--c-sunken: #f2f2f2;
/* Text */
--c-ink: #0a0a0a;
--c-ink-muted: #5c5c5c;
}
@theme {
--color-*: initial;
--font-sans: 'Geist Variable', ui-sans-serif, system-ui, sans-serif;
--text-h1: clamp(1.875rem, 1.5rem + 1.3vw, 2.5rem);
--text-h1--line-height: 1.1;
--text-h1--letter-spacing: -0.025em;
--text-body: 1rem;
--text-body--line-height: 1.6;
--text-small: 0.875rem;
--text-small--line-height: 1.5;
--radius-xl: 1rem;
--radius-2xl: 1.25rem;
--container-page: 80rem;
}
@theme inline {
--color-canvas: var(--c-canvas);
--color-surface: var(--c-surface);
--color-sunken: var(--c-sunken);
--color-ink: var(--c-ink);
--color-ink-muted: var(--c-ink-muted);
}
Four details in that block matter most:
--color-*: initialremoves Tailwind’s whole default color palette. After that line,bg-purple-500doesn’t exist, so neither you nor Claude can use it. Onlybg-canvas,text-inkand the other named colors work. The Tailwind docs on theme variables describe the sameinitialtrick for any namespace, and--*: initialfor the whole default theme.--text-h1--line-heightties a line height and letter spacing to a font size, sotext-h1sets all three at once. One class per kind of text means fewer chances to mix values.--container-pageturns your measured content width intomax-w-page, so a section width is a name, not a number. Pick a new name, not an existing one. Tailwind already shipsmax-w-prose(65ch), and in our own build a--container-prosetoken didn’t change it. The built CSS still saysmax-width: 65ch.@theme inlineis there because these colors point at other variables (--c-*). The Tailwind docs sayinlinemakes the class use that value directly, sobg-surfacecompiles tobackground-color: var(--c-surface). That matters when the other variable can change, as ours does for dark colors.
If you only have one color scheme, you don’t need the :root plus @theme inline split. Put the hex values straight
into @theme as --color-canvas: #fafafa; and so on.
The worked example has no shadows. Our own site uses none, and no borders on cards and panels either. Your reference might use both. Write down what it does, decide what you keep, and write bans for the rest, the way CLAUDE.md best practices: design rules Claude Code actually follows shows.
Step 4: tell Claude to stay inside the tokens
Tokens only help if the agent uses them. Add a short section to the CLAUDE.md in your project root:
## Design tokens
All tokens live in `src/styles/theme.css` under `@theme`. Use only these.
- Colors: `canvas` (page), `surface` (cards), `sunken` (controls),
`ink` (main text), `ink-muted` (secondary text), `accent` (primary
action only). The default Tailwind palette is removed on purpose.
- Type: `text-h1`, `text-h2`, `text-body`, `text-small`, `text-caption`.
Each sets its own line height. Do not add `leading-*` to them.
- Radius: `rounded-xl` for controls, `rounded-2xl` for cards and panels.
- Spacing: the default 4px scale only (`p-4`, `gap-6`, `py-24`).
- Widths: `max-w-page` for sections, `max-w-prose` (65ch) for long text.
- No arbitrary values such as `p-[37px]` or `text-[#7c3aed]`. If a value
is missing, ask me before adding a token.
The last line matters most. When Claude can’t find a value, you want a question, not a new color.
Then ask Claude to apply the tokens to your existing pages:
Read the Design tokens section of CLAUDE.md and src/styles/theme.css.
Go through src/components and src/pages. Replace every raw color, font
size, radius and arbitrary value with the matching token. If no token
fits, list it in a table (file, line, value, closest token) and do not
change it. Do not change copy, images or layout.
Leaving copy and layout alone keeps the diff easy to read. You’re changing values, nothing else.
Check that it held
Arbitrary values are where your design drifts away from the tokens. This grep lists every something-[value] class in your components:
grep -rnoE "\b[a-z-]+-\[[^]]+\]" src/components src/pages --include='*.astro'
Treat the output as a list to review, not a failure. Some arbitrary values are fine, like a
transition-[color,background-color] list or a w-[calc(100%-2rem)] that no token could hold. Question the colors,
font sizes and paddings, because those should be tokens.
Then look at the result next to your reference, at phone width and laptop width. If a section still feels off, you probably rounded a value too far. It’s most often the line height or the gap between a heading and its text. Fix the token, not the component, and every section that uses it changes together.
What you have now
You have a theme file with every value named by its job and the default palette removed. You have a CLAUDE.md
section that keeps Claude inside it, and a grep that shows where values slip out. Your site now runs on a system you
picked on purpose, measured from a site you trust, with none of its content.
Next, write the tokens into a fuller spec. The DESIGN.md post shows how to add structure, states and responsive rules on top of the tokens, so new sections come out right the first time.
Share this post
Ask an AI about this post
Written byMuhammad SumonDeveloper and UI/UX designer

