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-shortcuts.md
1---2name: unocss-shortcuts3description: Combine multiple utility rules into single shorthand classes4---56# UnoCSS Shortcuts78Shortcuts combine multiple rules into a single shorthand, inspired by Windi CSS.910## Static Shortcuts1112Define as an object mapping shortcut names to utility combinations:1314```ts15shortcuts: {16// Multiple utilities combined17'btn': 'py-2 px-4 font-semibold rounded-lg shadow-md',18'btn-green': 'text-white bg-green-500 hover:bg-green-700',19// Single utility alias20'red': 'text-red-100',21}22```2324Usage:25```html26<button class="btn btn-green">Click me</button>27```2829## Dynamic Shortcuts3031Use RegExp matcher with function, similar to dynamic rules:3233```ts34shortcuts: [35// Static shortcuts can be in array too36{37btn: 'py-2 px-4 font-semibold rounded-lg shadow-md',38},39// Dynamic shortcut40[/^btn-(.*)$/, ([, c]) => `bg-${c}-400 text-${c}-100 py-2 px-4 rounded-lg`],41]42```4344Now `btn-green` and `btn-red` generate:4546```css47.btn-green {48padding: 0.5rem 1rem;49--un-bg-opacity: 1;50background-color: rgb(74 222 128 / var(--un-bg-opacity));51border-radius: 0.5rem;52--un-text-opacity: 1;53color: rgb(220 252 231 / var(--un-text-opacity));54}55```5657## Accessing Theme in Shortcuts5859Dynamic shortcuts receive context with theme access:6061```ts62shortcuts: [63[/^badge-(.*)$/, ([, c], { theme }) => {64if (Object.keys(theme.colors).includes(c))65return `bg-${c}4:10 text-${c}5 rounded`66}],67]68```6970## Shortcuts Layer7172Shortcuts are output to the `shortcuts` layer by default. Configure with:7374```ts75shortcutsLayer: 'my-shortcuts-layer'76```7778## Key Points7980- Later shortcuts have higher priority81- Shortcuts can reference other shortcuts82- Dynamic shortcuts work like dynamic rules83- Shortcuts are expanded at build time, not runtime84- All variants work with shortcuts (`hover:btn`, `dark:btn`, etc.)8586<!--87Source references:88- https://unocss.dev/config/shortcuts89-->90