Skip to content
MarkasUI
Type to search

    Guide

    MarkasUI

    Form

    Feedback

    Overlay

    Navigation

    Data

    Sections

    Animations

    Backgrounds

    Buttons

    Templates

    Pages

    Label

    Form label with consistent styling and optional required or optional markers that screen readers announce correctly.

    <div class="grid gap-3">
        <x-markas.label required>Full name</x-markas.label>
        <x-markas.label optional>Company</x-markas.label>
        <x-markas.label>Email</x-markas.label>
    </div>
    import { Label } from "@/components/markas/Label";
    
    export default function LabelExample() {
      return (
        <div className="grid gap-3">
          <Label required>Full name</Label>
          <Label optional>Company</Label>
          <Label>Email</Label>
        </div>
      );
    }
    <script setup lang="ts">
    import Label from "@/components/markas/Label.vue";
    </script>
    
    <template>
      <div class="grid gap-3">
        <Label required>Full name</Label>
        <Label optional>Company</Label>
        <Label>Email</Label>
      </div>
    </template>
    <script lang="ts">
      import Label from "$lib/components/markas/Label.svelte";
    </script>
    
    <div class="grid gap-3">
      <Label required>Full name</Label>
      <Label optional>Company</Label>
      <Label>Email</Label>
    </div>
    ---
    import Label from "@/components/markas/Label.astro";
    ---
    
    <div class="grid gap-3">
      <Label required>Full name</Label>
      <Label optional>Company</Label>
      <Label>Email</Label>
    </div>
    import { Component } from "@angular/core";
    import { Label } from "./markas/label.component";
    
    @Component({
      selector: "markas-example",
      imports: [Label],
      template: `
        <div class="grid gap-3">
          <label markas-label required>Full name</label>
          <label markas-label optional>Company</label>
          <label markas-label>Email</label>
        </div>
      `,
    })
    export default class LabelExample {}

    Examples

    Wrapping a checkbox

    Radio options

    Delivery speed
    Delivery speed
    Delivery speed
    Delivery speed
    Delivery speed

    Selectable cards

    Installation

    npx markasui@latest add label

    Usage

    <x-markas.label for="full_name" required>Full name</x-markas.label>
    <input id="full_name" name="full_name" required />
    
    <x-markas.label for="company" optional>Company</x-markas.label>
    <input id="company" name="company" />
    import { Label } from "@/components/markas/Label";
    
    <Label htmlFor="full_name" required>Full name</Label>
    <input id="full_name" name="full_name" required />
    
    <Label htmlFor="company" optional>Company</Label>
    <input id="company" name="company" />
    <script setup lang="ts">
    import Label from "@/components/markas/Label.vue";
    </script>
    
    <template>
      <Label for="full_name" required>Full name</Label>
      <input id="full_name" name="full_name" required />
    
      <Label for="company" optional>Company</Label>
      <input id="company" name="company" />
    </template>
    <script lang="ts">
      import Label from "$lib/components/markas/Label.svelte";
    </script>
    
    <Label for="full_name" required>Full name</Label>
    <input id="full_name" name="full_name" required />
    
    <Label for="company" optional>Company</Label>
    <input id="company" name="company" />
    ---
    import Label from "@/components/markas/Label.astro";
    ---
    
    <Label for="full_name" required>Full name</Label>
    <input id="full_name" name="full_name" required />
    
    <Label for="company" optional>Company</Label>
    <input id="company" name="company" />
    import { Component } from "@angular/core";
    import { Label } from "./markas/label.component";
    
    @Component({
      selector: "app-profile-form",
      imports: [Label],
      template: `
        <label markas-label for="full_name" required>Full name</label>
        <input id="full_name" name="full_name" required />
    
        <label markas-label for="company" optional>Company</label>
        <input id="company" name="company" />
      `,
    })
    export class ProfileForm {}

    In Angular, Label is an attribute on a native <label>, so for, id, and class stay on that element.

    • Label needs no JavaScript. Extra attributes and class go to the <label> element, and your classes come last.
    • You can also wrap a checkbox or radio inside the label instead of using for: <Label class="flex items-center gap-2"><input type="checkbox" />Remember me</Label>.
    • The asterisk is hidden from screen readers. They hear “Full name required” instead, from requiredLabel. When both required and optional are set, required wins.
    • Translate the built-in text with requiredLabel (default “required”) and optionalLabel (default “Optional”).

    Props

    NameTypeDefaultDescription
    for / htmlForstring-Id of the form control this label names. React uses htmlFor. In Angular, Label is an attribute on a native label (<label markas-label for="...">).
    requiredbooleanfalseShows a red asterisk (hidden from screen readers) and a screen reader only text from requiredLabel. Takes priority over optional.
    optionalbooleanfalseShows muted text from optionalLabel after the label text.
    requiredLabelstringrequiredScreen reader text announced for required fields.
    optionalLabelstringOptionalVisible text shown for optional fields.

    Accessibility

    • Renders a native label element, so clicking it focuses or toggles the linked control.
    • The asterisk is aria-hidden; the required state is announced through screen reader only text instead.
    • The optional text is part of the label, so it is included in the accessible name of the control.

    Related components

    More form components with the same classes in every framework.