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/transformer-directives.md
1---2name: transformer-directives3description: CSS directives @apply, @screen, theme(), and icon()4---56# Transformer Directives78Enables `@apply`, `@screen`, `theme()`, and `icon()` directives in CSS.910## Installation1112```ts13import { defineConfig, transformerDirectives } from 'unocss'1415export default defineConfig({16transformers: [17transformerDirectives(),18],19})20```2122## @apply2324Apply utility classes in CSS:2526```css27.custom-btn {28@apply py-2 px-4 font-semibold rounded-lg;29}3031/* With variants - use quotes */32.custom-btn {33@apply 'hover:bg-blue-600 focus:ring-2';34}35```3637### CSS Custom Property Alternative3839For vanilla CSS compatibility:4041```css42.custom-div {43--at-apply: text-center my-0 font-medium;44}45```4647Supported aliases: `--at-apply`, `--uno-apply`, `--uno`4849Configure aliases:5051```ts52transformerDirectives({53applyVariable: ['--at-apply', '--uno-apply', '--uno'],54// or disable: applyVariable: false55})56```5758## @screen5960Create breakpoint media queries:6162```css63.grid {64display: grid;65grid-template-columns: repeat(2, 1fr);66}6768@screen sm {69.grid {70grid-template-columns: repeat(3, 1fr);71}72}7374@screen lg {75.grid {76grid-template-columns: repeat(4, 1fr);77}78}79```8081### Breakpoint Variants8283```css84/* Less than breakpoint */85@screen lt-sm {86.item { display: none; }87}8889/* At specific breakpoint only */90@screen at-md {91.item { width: 50%; }92}93```9495## theme()9697Access theme values in CSS:9899```css100.btn-blue {101background-color: theme('colors.blue.500');102padding: theme('spacing.4');103border-radius: theme('borderRadius.lg');104}105```106107Dot notation paths into your theme config.108109## icon()110111Convert icon utility to SVG (requires preset-icons):112113```css114.icon-sun {115background-image: icon('i-carbon-sun');116}117118/* With custom color */119.icon-moon {120background-image: icon('i-carbon-moon', '#fff');121}122123/* Using theme color */124.icon-alert {125background-image: icon('i-carbon-warning', 'theme("colors.red.500")');126}127```128129## Complete Example130131```css132.card {133@apply rounded-lg shadow-md p-4;134background-color: theme('colors.white');135}136137.card-header {138@apply 'font-bold text-lg border-b';139padding-bottom: theme('spacing.2');140}141142@screen md {143.card {144@apply flex gap-4;145}146}147148.card-icon {149background-image: icon('i-carbon-document');150@apply w-6 h-6;151}152```153154<!--155Source references:156- https://unocss.dev/transformers/directives157-->158