--- name: preset-attributify description: Group utilities in HTML attributes instead of class --- # Preset Attributify Group utilities in HTML attributes for better readability. ## Installation ```ts import { defineConfig, presetAttributify, presetWind3 } from 'unocss' export default defineConfig({ presets: [ presetWind3(), presetAttributify(), ], }) ``` ## Basic Usage Instead of long class strings: ```html ``` Group by prefix in attributes: ```html ``` ## Prefix Self-Referencing For utilities matching their prefix (`flex`, `grid`, `border`), use `~`: ```html ``` ## Valueless Attributify Use utilities as boolean attributes: ```html
``` ## Handling Property Conflicts When attribute names conflict with HTML properties: ```html Text color to red ``` ### Enforce Prefix ```ts presetAttributify({ prefix: 'un-', prefixedOnly: true, }) ``` ## Options ```ts presetAttributify({ strict: false, // Only generate CSS for attributify prefix: 'un-', // Attribute prefix prefixedOnly: false, // Require prefix for all nonValuedAttribute: true, // Support valueless attributes ignoreAttributes: [], // Attributes to ignore trueToNonValued: false, // Treat value="true" as valueless }) ``` ## TypeScript Support ### Vue 3 ```ts // html.d.ts declare module '@vue/runtime-dom' { interface HTMLAttributes { [key: string]: any } } declare module '@vue/runtime-core' { interface AllowedComponentProps { [key: string]: any } } export {} ``` ### React ```ts import type { AttributifyAttributes } from '@unocss/preset-attributify' declare module 'react' { interface HTMLAttributes extends AttributifyAttributes {} } ``` ## JSX Support For JSX where `
` becomes `
`: ```ts import { transformerAttributifyJsx } from 'unocss' export default defineConfig({ transformers: [ transformerAttributifyJsx(), ], }) ``` **Important:** Only use attributify if `uno.config.*` shows `presetAttributify()` is enabled.