Skip to content

Label

A form label. Inside a Field it points at the control and takes the field’s required and disabled.

<Field class="flex flex-col gap-1" required>
<Label>Email</Label>
<Input type="email" bind:value />
</Field>

On its own, associate it with for:

<Label for="email" required>Email</Label>
<Input id="email" bind:value />
<Label
  required={false}
  disabled={false}
/>
  • A real <label>, so clicking it focuses the control it points at.
  • Inside a Field it finds the control, mirrors required and disabled, and names a RadioGroup through aria-labelledby.
  • The required asterisk is a snippet, so it can be any mark you like.

Outside a field, point it at the control with for.

Code
Standalone.svelte
<script lang="ts">
import { Input, Label } from "@viamrobotics/prime-ui";
</script>
<div class="not-content flex max-w-xs flex-col gap-1">
<Label for="standalone-email" required>Email</Label>
<Input id="standalone-email" type="email" required placeholder="you@viam.com" />
</div>

Pass an indicator snippet to replace the asterisk. It renders only while the label is required.

Code
CustomIndicator.svelte
<script lang="ts">
import { Field, Input, Label } from "@viamrobotics/prime-ui";
</script>
<Field class="not-content flex max-w-xs flex-col gap-1" required>
<Label>
Email
{#snippet indicator()}
<span class="text-xs text-subtle-2">(required)</span>
{/snippet}
</Label>
<Input type="email" placeholder="you@viam.com" />
</Field>

States

In a field

class lands on the <label>, an inline flex row with a small gap between the text and the indicator. The asterisk is aria-hidden, so it never reaches the accessible name. Put required on the control too.

PropTypeDefaultDescription
requiredbooleanShow a required asterisk. Defaults to the enclosing field's required.
disabledbooleanDim the label and show a not-allowed cursor. Defaults to the enclosing field's disabled.
indicatorSnippetReplaces the required asterisk. Rendered only when required.

Plus everything in HTMLLabelAttributes, spread onto the element.