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/preset-attributify.md
1---2name: preset-attributify3description: Group utilities in HTML attributes instead of class4---56# Preset Attributify78Group utilities in HTML attributes for better readability.910## Installation1112```ts13import { defineConfig, presetAttributify, presetWind3 } from 'unocss'1415export default defineConfig({16presets: [17presetWind3(),18presetAttributify(),19],20})21```2223## Basic Usage2425Instead of long class strings:2627```html28<button class="bg-blue-400 hover:bg-blue-500 text-sm text-white font-mono font-light py-2 px-4 rounded border-2 border-blue-200">29Button30</button>31```3233Group by prefix in attributes:3435```html36<button37bg="blue-400 hover:blue-500"38text="sm white"39font="mono light"40p="y-2 x-4"41border="2 rounded blue-200"42>43Button44</button>45```4647## Prefix Self-Referencing4849For utilities matching their prefix (`flex`, `grid`, `border`), use `~`:5051```html52<!-- Before -->53<button class="border border-red">Button</button>5455<!-- After -->56<button border="~ red">Button</button>57```5859## Valueless Attributify6061Use utilities as boolean attributes:6263```html64<div m-2 rounded text-teal-400 />65```6667## Handling Property Conflicts6869When attribute names conflict with HTML properties:7071```html72<!-- Use un- prefix -->73<a un-text="red">Text color to red</a>74```7576### Enforce Prefix7778```ts79presetAttributify({80prefix: 'un-',81prefixedOnly: true,82})83```8485## Options8687```ts88presetAttributify({89strict: false, // Only generate CSS for attributify90prefix: 'un-', // Attribute prefix91prefixedOnly: false, // Require prefix for all92nonValuedAttribute: true, // Support valueless attributes93ignoreAttributes: [], // Attributes to ignore94trueToNonValued: false, // Treat value="true" as valueless95})96```9798## TypeScript Support99100### Vue 3101102```ts103// html.d.ts104declare module '@vue/runtime-dom' {105interface HTMLAttributes { [key: string]: any }106}107declare module '@vue/runtime-core' {108interface AllowedComponentProps { [key: string]: any }109}110export {}111```112113### React114115```ts116import type { AttributifyAttributes } from '@unocss/preset-attributify'117118declare module 'react' {119interface HTMLAttributes<T> extends AttributifyAttributes {}120}121```122123## JSX Support124125For JSX where `<div foo>` becomes `<div foo={true}>`:126127```ts128import { transformerAttributifyJsx } from 'unocss'129130export default defineConfig({131transformers: [132transformerAttributifyJsx(),133],134})135```136137**Important:** Only use attributify if `uno.config.*` shows `presetAttributify()` is enabled.138139<!--140Source references:141- https://unocss.dev/presets/attributify142-->143