Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Configure and use UnoCSS atomic CSS engine with presets like Wind (Tailwind-compatible), Icons, and Attributify.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/core-theme.md
1---2name: unocss-theme3description: Theming system for colors, breakpoints, and design tokens4---56# UnoCSS Theme78UnoCSS supports theming similar to Tailwind CSS / Windi CSS. The `theme` property is deep-merged with the default theme.910## Basic Usage1112```ts13theme: {14colors: {15veryCool: '#0000ff', // class="text-very-cool"16brand: {17primary: 'hsl(var(--hue, 217) 78% 51%)', // class="bg-brand-primary"18DEFAULT: '#942192' // class="bg-brand"19},20},21}22```2324## Using Theme in Rules2526Access theme values in dynamic rules:2728```ts29rules: [30[/^text-(.*)$/, ([, c], { theme }) => {31if (theme.colors[c])32return { color: theme.colors[c] }33}],34]35```3637## Using Theme in Variants3839```ts40variants: [41{42name: 'variant-name',43match(matcher, { theme }) {44// Access theme.breakpoints, theme.colors, etc.45},46},47]48```4950## Using Theme in Shortcuts5152```ts53shortcuts: [54[/^badge-(.*)$/, ([, c], { theme }) => {55if (Object.keys(theme.colors).includes(c))56return `bg-${c}4:10 text-${c}5 rounded`57}],58]59```6061## Breakpoints6263**Warning:** Custom `breakpoints` object **overrides** the default, not merges.6465```ts66theme: {67breakpoints: {68sm: '320px',69md: '640px',70},71}72```7374Only `sm:` and `md:` variants will be available.7576### Inherit Default Breakpoints7778Use `extendTheme` to merge with defaults:7980```ts81extendTheme: (theme) => {82return {83...theme,84breakpoints: {85...theme.breakpoints,86sm: '320px',87md: '640px',88},89}90}91```9293**Note:** `verticalBreakpoints` works the same for vertical layout.9495### Breakpoint Sorting9697Breakpoints are sorted by size. Use consistent units to avoid errors:9899```ts100theme: {101breakpoints: {102sm: '320px',103// Don't mix units - convert rem to px104// md: '40rem', // Bad105md: `${40 * 16}px`, // Good106lg: '960px',107},108}109```110111## ExtendTheme112113`extendTheme` lets you modify the merged theme object:114115### Mutate Theme116117```ts118extendTheme: (theme) => {119theme.colors.veryCool = '#0000ff'120theme.colors.brand = {121primary: 'hsl(var(--hue, 217) 78% 51%)',122}123}124```125126### Replace Theme127128Return a new object to completely replace:129130```ts131extendTheme: (theme) => {132return {133...theme,134colors: {135...theme.colors,136veryCool: '#0000ff',137},138}139}140```141142## Theme Differences in Presets143144### preset-wind3 vs preset-wind4145146| preset-wind3 | preset-wind4 |147|--------------|--------------|148| `fontFamily` | `font` |149| `fontSize` | `text.fontSize` |150| `lineHeight` | `text.lineHeight` or `leading` |151| `letterSpacing` | `text.letterSpacing` or `tracking` |152| `borderRadius` | `radius` |153| `easing` | `ease` |154| `breakpoints` | `breakpoint` |155| `boxShadow` | `shadow` |156| `transitionProperty` | `property` |157158## Common Theme Keys159160- `colors` - Color palette161- `breakpoints` - Responsive breakpoints162- `fontFamily` - Font stacks163- `fontSize` - Text sizes164- `spacing` - Spacing scale165- `borderRadius` - Border radius values166- `boxShadow` - Shadow definitions167- `animation` - Animation keyframes and timing168169<!--170Source references:171- https://unocss.dev/config/theme172-->173