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-layers.md
1---2name: unocss-layers-preflights3description: CSS layer ordering and raw CSS injection4---56# Layers and Preflights78Control CSS output order and inject global CSS.910## Layers1112Set layer on rules:1314```ts15rules: [16[/^m-(\d)$/, ([, d]) => ({ margin: `${d / 4}rem` }), { layer: 'utilities' }],17['btn', { padding: '4px' }], // default layer18]19```2021### Layer Ordering2223```ts24layers: {25'components': -1,26'default': 1,27'utilities': 2,28}29```3031### Import Layers Separately3233```ts34import 'uno:components.css'35import 'uno.css'36import './my-custom.css'37import 'uno:utilities.css'38```3940### CSS Cascade Layers4142```ts43outputToCssLayers: true4445// Or with custom names46outputToCssLayers: {47cssLayerName: (layer) => {48if (layer === 'default') return 'utilities'49if (layer === 'shortcuts') return 'utilities.shortcuts'50}51}52```5354## Layer Variants5556```html57<!-- UnoCSS layer -->58<p class="uno-layer-my-layer:text-xl">5960<!-- CSS @layer -->61<p class="layer-my-layer:text-xl">62```6364## Preflights6566Inject raw CSS globally:6768```ts69preflights: [70{71getCSS: ({ theme }) => `72* {73color: ${theme.colors.gray?.[700] ?? '#333'};74margin: 0;75}76`,77},78]79```8081With layer:8283```ts84preflights: [85{86layer: 'base',87getCSS: () => `html { font-family: system-ui; }`,88},89]90```9192## preset-wind4 Layers9394| Layer | Description | Order |95|-------|-------------|-------|96| `properties` | CSS @property rules | -200 |97| `theme` | Theme CSS variables | -150 |98| `base` | Reset styles | -100 |99100<!--101Source references:102- https://unocss.dev/config/layers103- https://unocss.dev/config/preflights104-->105