Label

A control's name, shown beside it. In the look of the app's style.

FormsExperimental

Usage

import { Component, ViewEncapsulation } from '@angular/core';import { ScCheckbox, ScField, ScLabel } from '@semantic-components/ui';
@Component({  selector: 'app-label-usage-demo',  imports: [ScCheckbox, ScLabel, ScField],  template: `    <div scField orientation="horizontal">      <input scCheckbox />      <label scLabel>Accept terms and conditions</label>    </div>  `,  host: { class: 'flex w-full justify-center' },  encapsulation: ViewEncapsulation.None,})export class LabelUsageDemo {}

Anatomy

A directive on your label; its text is yours. In a field it names the field's control by itself. It can also hold a field as its child (a horizontal scField with its control, title and description): a choice card, the whole card picks — bordered, tinted when checked.

import { ScField, ScFieldContentWrapper, ScFieldDescription, ScFieldTitle, ScLabel, ScLabelText } from '@semantic-components/ui';
<!-- Beside its control, or in a field --><label scLabel>…</label>
<!-- A field as its child: a choice card, the whole card clicks --><label scLabel>  <div scField orientation="horizontal">    <div scFieldContentWrapper>      <div scFieldTitle>…</div>      <p scFieldDescription>…</p>    </div>    <input scCheckbox />  </div></label>
<!-- Its text inside another label (a switch field’s) --><label …>  <p scLabelText>…</p></label>

Accessibility

  • A real label: a press on it focuses or toggles its control. In a field it is linked (for); around a control, by wrapping it.
  • A field's group of controls (radios, checkboxes) is named by its label's id (<field id>-label), not by for.
  • Text inside another label (a switch's): scLabelText, so there is never a label in a label.

Examples

In a field

import { Component, ViewEncapsulation } from '@angular/core';import { ScField, ScInput, ScLabel } from '@semantic-components/ui';
/** In a scField: it names the field’s control, with no id to write. */@Component({  selector: 'app-field-label-demo',  imports: [ScField, ScInput, ScLabel],  template: `    <div scField class="w-full max-w-sm">      <label scLabel>Email</label>

With a description

We’ll never share your email with anyone.

import { Component, ViewEncapsulation } from '@angular/core';import {  ScField,  ScFieldDescription,  ScInput,  ScLabel,} from '@semantic-components/ui';
/** A field’s label and its description: the description is read with the control. */@Component({

Choice card

import { Component, ViewEncapsulation } from '@angular/core';import {  ScCheckbox,  ScField,  ScFieldContentWrapper,  ScFieldDescription,  ScFieldTitle,  ScLabel,} from '@semantic-components/ui';

Label text

import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScField, ScLabelText, ScSwitch } from '@semantic-components/ui';
/** Text inside another label (a switch’s): scLabelText, a label’s look without a second label. */@Component({  selector: 'app-label-text-label-demo',  imports: [ScLabelText, ScSwitch, ScField],  template: `    <div class="space-y-4">      <label scField orientation="horizontal">

RTL

import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import { ScCheckbox, ScField, ScLabel } from '@semantic-components/ui';
/** In a right-to-left page: the box at the right, the text after it. */@Component({  selector: 'app-rtl-label-demo',  imports: [Dir, ScCheckbox, ScLabel, ScField],  template: `    <div dir="rtl" lang="ar">

API reference

Each part takes class, merged over the style (cn: a later class wins).

PartSelectorDescription
ScLabellabel[scLabel] A label in the style's look; in a field (or around one: a choice card) the field's look too. for, id: from the field when it is in one.
ScLabelText[scLabelText] A label's text inside another label (a switch's, a choice's).