.agents/skills/unocss/references/core-theme.md
UnoCSS supports theming similar to Tailwind CSS / Windi CSS. The theme property is deep-merged with the default theme.
theme: {
colors: {
veryCool: '#0000ff', // class="text-very-cool"
brand: {
primary: 'hsl(var(--hue, 217) 78% 51%)', // class="bg-brand-primary"
DEFAULT: '#942192' // class="bg-brand"
},
},
}
Access theme values in dynamic rules:
rules: [
[/^text-(.*)$/, ([, c], { theme }) => {
if (theme.colors[c])
return { color: theme.colors[c] }
}],
]
variants: [
{
name: 'variant-name',
match(matcher, { theme }) {
// Access theme.breakpoints, theme.colors, etc.
},
},
]
shortcuts: [
[/^badge-(.*)$/, ([, c], { theme }) => {
if (Object.keys(theme.colors).includes(c))
return `bg-${c}4:10 text-${c}5 rounded`
}],
]
Warning: Custom breakpoints object overrides the default, not merges.
theme: {
breakpoints: {
sm: '320px',
md: '640px',
},
}
Only sm: and md: variants will be available.
Use extendTheme to merge with defaults:
extendTheme: (theme) => {
return {
...theme,
breakpoints: {
...theme.breakpoints,
sm: '320px',
md: '640px',
},
}
}
Note: verticalBreakpoints works the same for vertical layout.
Breakpoints are sorted by size. Use consistent units to avoid errors:
theme: {
breakpoints: {
sm: '320px',
// Don't mix units - convert rem to px
// md: '40rem', // Bad
md: `${40 * 16}px`, // Good
lg: '960px',
},
}
extendTheme lets you modify the merged theme object:
extendTheme: (theme) => {
theme.colors.veryCool = '#0000ff'
theme.colors.brand = {
primary: 'hsl(var(--hue, 217) 78% 51%)',
}
}
Return a new object to completely replace:
extendTheme: (theme) => {
return {
...theme,
colors: {
...theme.colors,
veryCool: '#0000ff',
},
}
}
| preset-wind3 | preset-wind4 |
|---|---|
fontFamily | font |
fontSize | text.fontSize |
lineHeight | text.lineHeight or leading |
letterSpacing | text.letterSpacing or tracking |
borderRadius | radius |
easing | ease |
breakpoints | breakpoint |
boxShadow | shadow |
transitionProperty | property |
colors - Color palettebreakpoints - Responsive breakpointsfontFamily - Font stacksfontSize - Text sizesspacing - Spacing scaleborderRadius - Border radius valuesboxShadow - Shadow definitionsanimation - Animation keyframes and timing