Skip to content

Label

Neo-brutalist label component for form fields, with variant support.

Demo

Preview

尺寸

必填

Installation

pnpm dlx brutx-vue@latest add label

Usage

vue
<script setup>
import { Label, Input } from 'brutx-ui-vue'
</script>

<template>
    <div class="space-y-2">
        <Label for="email">Email</Label>
        <Input id="email" type="email" placeholder="you@example.com" />
    </div>
</template>

Required Indicator

When the required prop is set, a red * asterisk is automatically rendered at the end of the label (marked as aria-hidden), and the root element gets aria-required="true" to help accessibility tools identify required fields.

vue
<script setup>
import { Label, Input } from 'brutx-ui-vue'
</script>

<template>
    <div class="space-y-2">
        <Label for="username" required>Username</Label>
        <Input id="username" placeholder="Enter your username" />
    </div>
</template>

Variants

VariantDescription
defaultStandard foreground text
errorDestructive (red) text
successSuccess (green) text
mutedMuted foreground text

Sizes

SizeFont SizeLine Height
smtext-xsleading-none
defaulttext-smleading-none
lgtext-baseleading-none
vue
<script setup>
import { Label } from 'brutx-ui-vue'
</script>

<template>
    <div class="flex flex-wrap items-center gap-4">
        <Label size="sm">Small Label</Label>
        <Label size="default">Default Label</Label>
        <Label size="lg">Large Label</Label>
    </div>
</template>

Props

PropTypeDefaultDescription
variant'default' | 'error' | 'success' | 'muted''default'Label variant style
size'sm' | 'default' | 'lg''default'Label size
requiredbooleanfalseWhether to show the required indicator
forstringID of the associated form control
classstringCustom CSS class name

Slots

SlotScopeDescription
defaultLabel content

Accessibility

The Label component renders as an HTML <label> element. When using the for attribute, it associates with the matching form control, improving accessibility and click-to-focus behavior.

  • When required is true, the component automatically adds the aria-required="true" attribute
  • The required indicator * is marked as aria-hidden="true" to avoid duplicate announcements by screen readers
  • The component supports peer-disabled state, displaying a disabled style when the associated form control is disabled

Brute force builds.