Label

GitHubnpm
Renders an accessible label associated with controls.
<script setup lang="ts">
import { Label } from 'akar';
import './styles.css';
</script>

<template>
  <div class="akar-demo akar-demo-Label">
    <div :style="{ display: 'flex', padding: '0 20px', flexWrap: 'wrap', gap: 15, alignItems: 'center' }">
      <Label
        class="LabelRoot"
        for="firstName"
      > First name </Label>
      <input
        id="firstName"
        class="Input"
        type="text"
        value="Pedro Duarte"
      >
    </div>
  </div>
</template>

Features

  • Text selection is prevented when double clicking label.
  • Supports nested controls.

Installation

Install the component from your command line.

pnpm add akar

Anatomy

Import the component.

<script setup>
import { Label } from 'akar';
</script>

<template>
  <Label />
</template>

API Reference

Root

Contains the content for the label.

PropDefaultType
as
"label"
AsTag | Component

The element or component this component should render as. Can be overwritten by asChild.

asChild
boolean

Change the default rendered element for the one passed as a child, merging their props and behavior.

Read our Composition guide for more details.

for
string

The id of the element the label is associated with.

Label.vue source

Accessibility

This component is based on the native label element, it will automatically apply the correct labelling when wrapping controls or using the for attribute. For your own custom controls to work correctly, ensure they use native elements such as button or input as a base.