21st-design-sync
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese21st Design Sync — publish your project's design as a theme
21st Design Sync — 将你的项目设计发布为主题
Take the design a project already ships (its light + dark CSS variables) and
publish it to the public 21st.dev theme library so anyone can preview,
bookmark, and apply it. Under the hood this is one CLI call:
.
21st publish-theme <file.css> --name "…"提取项目已有的设计(其亮色+暗色CSS变量),并将其发布到公共21st.dev主题库,以便任何人都可以预览、收藏和应用。底层实现仅需一条CLI命令:。
21st publish-theme <file.css> --name "…"Pre-flight (always)
前置检查(必做)
- Auth needs a real API key. is a management endpoint: it accepts a
publish-themekey only, not a21st_sk_…session token. Get one at https://21st.dev/mcp (or https://21st.dev/settings/api-keys) and pass it via21st loginor the--api-key 21st_sk_…/TWENTYFIRST_TOKENenv var. If the user has no key, point them there — don't try to mint one.API_KEY_21ST - The CLI is the unified (bin
@21st-dev/cli). Use21stif it isn't installed.npx @21st-dev/cli - Publishing is public and outward-facing. A published theme is immediately
in the community library (there is no unlisted/private option for themes). Confirm with the user before publishing.
is_public
- 认证需要有效的API密钥。是管理端点:它仅接受
publish-theme格式的密钥,不支持21st_sk_…会话令牌。可前往**https://21st.dev/mcp**(或**https://21st.dev/settings/api-keys**)获取密钥,并通过`--api-key 21st_sk_…21st loginTWENTYFIRST_TOKEN参数或API_KEY_21ST`环境变量传入。如果用户没有密钥,引导他们前往上述地址获取,不要尝试生成密钥。/ - CLI工具是统一的(二进制命令为
@21st-dev/cli)。如果未安装,可使用21st。npx @21st-dev/cli - 发布操作是公开对外的。已发布的主题会立即在社区库中设为状态(主题没有未列出/私有选项)。发布前请与用户确认。
is_public
Step 1 — Find the project's design tokens
步骤1 — 找到项目的设计标记
Locate the file that defines the shadcn/Tailwind theme variables. Check, in order:
- ,
app/globals.csssrc/app/globals.css - ,
src/index.css,styles/globals.cssapp/styles/globals.css
You're looking for a block of CSS custom properties
(, , , , ,
, , , , , , the
/ tokens, ) and a matching
block. Values may be , , hex, or raw channels — keep them
exactly as the project wrote them.
:root { … }--background--foreground--card--primary--secondary--muted--accent--destructive--border--input--ring--chart-*--sidebar-*--radius.dark { … }hsl(...)oklch(...)Tailwind v4 projects usually keep the same / blocks plus an
mapping; you only need the and token values,
not the mapping.
:root.dark@theme inline:root.dark@theme定位定义shadcn/Tailwind主题变量的文件,按以下顺序查找:
- 、
app/globals.csssrc/app/globals.css - 、
src/index.css、styles/globals.cssapp/styles/globals.css
你需要找的是包含CSS自定义属性(、、、、、、、、、、、/标记、)的代码块,以及对应的代码块。值可以是、、十六进制或原始通道值——完全保留项目中的原始写法即可。
--background--foreground--card--primary--secondary--muted--accent--destructive--border--input--ring--chart-*--sidebar-*--radius:root { … }.dark { … }hsl(...)oklch(...)Tailwind v4项目通常保留相同的/代码块,外加映射;你只需要和中的标记值,不需要映射。
:root.dark@theme inline:root.dark@themeStep 2 — Assemble a valid theme CSS file
步骤2 — 生成有效的主题CSS文件
The publish endpoint parses pairs out of a block
and a block, and requires both to be non-empty. So the file
you publish must contain both.
--name: value;:root { … }.dark { … }- Copy the project's and
:rootblocks into a standalone file (e.g..dark). Nothing else is required.project-theme.css - If the project has only a light and no
:root(or an empty one), generate a dark variant before publishing — don't ship a theme with an empty dark mode. Reuse the.dark/add-dark-modeapproach: invert lightness while preserving hue/chroma so the dark set stays on-brand. Keep the same token names.oklch-skill - Keep the token names shadcn-standard so the theme previews correctly on the card and applies cleanly for others.
Minimal shape:
css
:root {
--background: 0 0% 100%;
--foreground: 240 10% 4%;
--primary: 240 6% 10%;
/* …the rest of the project's light tokens… */
--radius: 0.5rem;
}
.dark {
--background: 240 10% 4%;
--foreground: 0 0% 98%;
--primary: 0 0% 98%;
/* …the rest of the project's dark tokens… */
}发布端点会从和代码块中解析对,并且要求两个代码块都非空。因此,你要发布的文件必须同时包含这两个代码块。
:root { … }.dark { … }--name: value;- 将项目的和
:root代码块复制到一个独立文件中(例如.dark)。不需要其他内容。project-theme.css - 如果项目只有亮色代码块,没有
:root代码块(或为空),请在发布前生成暗色变体——不要发布暗色模式为空的主题。使用.dark/add-dark-mode方法:反转亮度同时保留色调/色度,使暗色集保持品牌风格。保留相同的标记名称。oklch-skill - 保持标记名称符合shadcn标准,以便主题在卡片上正确预览,并能被其他人顺利应用。
最小结构示例:
css
:root {
--background: 0 0% 100%;
--foreground: 240 10% 4%;
--primary: 240 6% 10%;
/* …项目其余的亮色标记… */
--radius: 0.5rem;
}
.dark {
--background: 240 10% 4%;
--foreground: 0 0% 98%;
--primary: 0 0% 98%;
/* …项目其余的暗色标记… */
}Step 3 — Name & tag it
步骤3 — 命名与添加标签
- Name (required, ≤ 50 chars): infer from the project — the product/brand
name from , the repo, or the site title. Ask the user if it's ambiguous.
package.json - Tags (optional): a few descriptors that match how people browse themes,
e.g. ,
dark,minimal,neutral,vibrant. Pass comma-separated.saas
- 名称(必填,≤50字符):从项目中推断——可以是中的产品/品牌名称、仓库名称或网站标题。如果不确定,请询问用户。
package.json - 标签(可选):几个符合主题浏览习惯的描述符,例如、
dark、minimal、neutral、vibrant。使用逗号分隔。saas
Step 4 — Publish
步骤4 — 发布
bash
21st publish-theme ./project-theme.css \
--name "Acme" \
--tags dark,minimal \
--api-key 21st_sk_… # or set TWENTYFIRST_TOKENThe command prints the live theme URL ().
Share it with the user.
https://21st.dev/community/themes/<slug>bash
21st publish-theme ./project-theme.css \
--name "Acme" \
--tags dark,minimal \
--api-key 21st_sk_… # 或设置TWENTYFIRST_TOKEN环境变量命令会输出主题的在线URL()。将该URL分享给用户。
https://21st.dev/community/themes/<slug>Updating vs re-publishing
更新与重新发布的区别
- Each creates a NEW theme (there's no upsert-by-slug like components have). Running it twice = two themes in the library.
publish-theme - To change name/tags/visibility on an existing theme, edit it in place:
.
21st edit <theme-id> --type theme [--name "…"] [--tags a,b] - To change the colors, publish a fresh file and remove the old one:
(soft-unpublish, reversible).
21st delete <theme-id> --type theme --yes
- 每次执行都会创建一个新主题(不像组件那样支持按slug更新)。执行两次会在库中生成两个主题。
publish-theme - 要修改现有主题的名称/标签/可见性,直接在线编辑:。
21st edit <theme-id> --type theme [--name "…"] [--tags a,b] - 要修改颜色,请发布新文件并删除旧主题:(软删除,可恢复)。
21st delete <theme-id> --type theme --yes
When NOT to use this
不适用场景
- Syncing a component library to a Claude Design project → that's the
built-in skill, a different destination.
/design-sync - Publishing a component (not a color theme) → use .
21st-registry
- 将组件库同步到Claude Design项目→使用内置的功能,这是不同的目标场景。
/design-sync - 发布组件(而非颜色主题)→使用。
21st-registry