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>Examples
Wrapping a checkbox
<div class="grid gap-3">
<x-markas.label required class="flex items-center gap-2"><input type="checkbox" name="terms" required class="size-4 accent-primary" />I accept the terms of service</x-markas.label>
<x-markas.label optional class="flex items-center gap-2"><input type="checkbox" name="newsletter" class="size-4 accent-primary" />Send me the monthly newsletter</x-markas.label>
</div>Radio options
<fieldset class="min-w-0">
<legend class="mb-3 text-sm font-medium text-ink">Delivery speed</legend>
<div class="grid gap-3">
<x-markas.label class="flex items-center gap-2 font-normal"><input type="radio" name="speed" value="standard" checked class="size-4 accent-primary" />Standard, 3 to 5 days</x-markas.label>
<x-markas.label class="flex items-center gap-2 font-normal"><input type="radio" name="speed" value="express" class="size-4 accent-primary" />Express, next business day</x-markas.label>
<x-markas.label class="flex items-center gap-2 font-normal"><input type="radio" name="speed" value="pickup" class="size-4 accent-primary" />Pick up in store</x-markas.label>
</div>
</fieldset>Selectable cards
<div class="grid gap-3">
<x-markas.label class="flex items-start gap-3 rounded-lg border border-line bg-surface p-4 has-checked:border-primary has-checked:bg-primary-soft"><input type="checkbox" name="backups" checked class="mt-0.5 size-4 shrink-0 accent-primary" /><span class="grid gap-0.5"><span>Daily backups</span><span class="font-normal text-muted">Keep 30 days of snapshots for every project.</span></span></x-markas.label>
<x-markas.label class="flex items-start gap-3 rounded-lg border border-line bg-surface p-4 has-checked:border-primary has-checked:bg-primary-soft"><input type="checkbox" name="audit_log" class="mt-0.5 size-4 shrink-0 accent-primary" /><span class="grid gap-0.5"><span>Audit log</span><span class="font-normal text-muted">Record every sign-in and permission change.</span></span></x-markas.label>
</div>Installation
npx markasui@latest add labelpnpm dlx markasui@latest add labelyarn dlx markasui@latest add labelbunx --bun markasui@latest add label- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
resources/views/components/markas/label.blade.php.
resources/views/components/markas/label.blade.php
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/Label.tsx.
src/components/markas/Label.tsx
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/Label.vue.
src/components/markas/Label.vue
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/lib/components/markas/Label.svelte.
src/lib/components/markas/Label.svelte
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/Label.astro.
src/components/markas/Label.astro
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/app/markas/label.component.ts.
src/app/markas/label.component.ts
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
classgo 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 bothrequiredandoptionalare set,requiredwins. - Translate the built-in text with
requiredLabel(default “required”) andoptionalLabel(default “Optional”).
Props
| Name | Type | Default | Description |
|---|---|---|---|
for / htmlFor | string | - | 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="...">). |
required | boolean | false | Shows a red asterisk (hidden from screen readers) and a screen reader only text from requiredLabel. Takes priority over optional. |
optional | boolean | false | Shows muted text from optionalLabel after the label text. |
requiredLabel | string | required | Screen reader text announced for required fields. |
optionalLabel | string | Optional | Visible 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.
- ButtonButton with primary, secondary, ghost, and danger variants.
- CheckboxNative checkbox with an optional label and description, custom styled without JavaScript.
- ComboboxText input with a filtered suggestion list in a popover, following the WAI-ARIA Combobox pattern with list autocomplete.
- InputText field with a label, hint, and error message wired up through ARIA.
- Input OTPOne-time code input split into single-digit boxes, with auto advance, paste support, and one hidden field for form submit.
- Radio GroupGroup of native radios inside a fieldset and legend for picking one of several options.