Label

Name an input, mark it as required, and connect the label to its field.

Live preview
Interact with the component to see results here.
View code
HTML
<div style="display:grid;gap:16px;width:100%">
  <sy-label
    value="Email"
    requiredposition="right"
    valueposition="left"
    width="100px"
    required
    for="field"
  ></sy-label>
  <sy-input
    placeholder="name@example.com"
    required
    id="field"
    aria-label="Email"
  ></sy-input>
</div>

Usage guide

#

Keep an always-visible explanation of the expected value beside the field.

  1. Connect to an input

    Set for to the input element's id. Clicking the Label focuses the connected input.

  2. Arrange to fit the form

    Use valuePosition and width for placement and width, and requiredPosition for the required marker.

Examples

#

Connect a field

Click the label to focus its associated input.

View code
HTML
<div style="display:grid;gap:16px;width:100%">
  <sy-label value="Project name" for="project"></sy-label>
  <sy-input placeholder="New project" id="project"></sy-input>
</div>

Mark required fields

Configure both the label indicator and the input's validation.

View code
HTML
<div style="display:grid;gap:16px;width:100%">
  <sy-label
    value="Name"
    required
    requiredposition="left"
    for="name"
  ></sy-label>
  <sy-input required id="name"></sy-input>
</div>

API reference

#

Hover over a name or focus it with the keyboard to see the code. On touch screens, tap the name.

<sy-label>

Properties

Attribute / PropertyTypeDefaultDescription
booleanfalseStyle the label as disabled. Also set disabled on the associated input.
booleanfalseAdd a required marker. Set required on the input component for actual validation.
'left' | 'right''right'Place the required marker on the left or right of the label.
string''id of the associated input element.
string''Current value or item identifier.
'left' | 'right' | 'center''left'Text alignment within the label area.
string''Label area width, as a CSS length.

Slots

SlotDescription
Component body or child items.