npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@spectrum-web-components/field-label

v1.12.1

Published

An `<sp-field-label>` provides accessible labelling for form elements. Use the `for` attribute to outline the `id` of an element in the same DOM tree to which it should associate itself. Field labels give context to information that a user needs to input

Readme

Overview

An <sp-field-label> provides accessible labelling for form elements. Use the for attribute to outline the id of an element in the same DOM tree to which it should associate itself. Field labels give context to information that a user needs to input and are commonly used in forms to provide users with clear guidance about what information is required.

Usage

See it on NPM! How big is this package in your project? Try it on Stackblitz

yarn add @spectrum-web-components/field-label

Import the side effectful registration of <sp-field-label> via:

import '@spectrum-web-components/field-label/sp-field-label.js';

When looking to leverage the FieldLabel base class as a type and/or for extension purposes, do so via:

import { FieldLabel } from '@spectrum-web-components/field-label';

Anatomy

Field labels can be associated with form elements by using the for attribute, which should reference the id of the related input element.

<sp-field-label for="product-name">Product name</sp-field-label>
<sp-textfield id="product-name" placeholder="Enter product name"></sp-textfield>

Field labels can also be used to label a group of related inputs:

<sp-field-label for="account-type">Account type</sp-field-label>
<sp-radio-group id="account-type">
  <sp-radio value="admin">Admin</sp-radio>
  <sp-radio value="member" checked>Member</sp-radio>
  <sp-radio value="guest">Guest</sp-radio>
</sp-radio-group>

Options

Sizes

<sp-field-label for="lifestory-0" size="s">Life Story (Small)</sp-field-label>
<sp-textfield
  placeholder="Enter your life story"
  id="lifestory-0"
  size="s"
></sp-textfield>
<sp-field-label for="lifestory-1" size="m">Life Story (Medium)</sp-field-label>
<sp-textfield
  placeholder="Enter your life story"
  id="lifestory-1"
  size="m"
></sp-textfield>
<sp-field-label for="lifestory-2" size="l">Life Story (Large)</sp-field-label>
<sp-textfield
  placeholder="Enter your life story"
  id="lifestory-2"
  size="l"
></sp-textfield>
<sp-field-label for="lifestory-3" size="xl">
  Life Story (Extra Large)
</sp-field-label>
<sp-textfield
  placeholder="Enter your life story"
  id="lifestory-3"
  size="xl"
></sp-textfield>

Label Position

Field labels can be positioned either on top of an input (default) or to the side of an input. The top position is recommended for most cases as it works better with long text, localization, and responsive layouts.

Using the side-aligned attribute will display the <sp-field-label> element inline with surrounding elements and the start and end values outline the alignment of the label text in the width specified.

<sp-field-label for="country-top">Country</sp-field-label>
<sp-textfield placeholder="Enter your country" id="country-top"></sp-textfield>

Use side-aligned="start" to display the <sp-field-label> inline and to align the label text to the "start" of the flow of text:

<sp-field-label for="lifestory-1" side-aligned="start" style="width: 120px">
  Life Story
</sp-field-label>
<sp-textfield
  placeholder="Enter your life story"
  id="lifestory-1"
></sp-textfield>
<br />
<br />
<sp-field-label
  for="birth-place-1"
  side-aligned="start"
  required
  style="width: 120px"
>
  Birthplace
</sp-field-label>
<sp-picker id="birth-place-1">
  <span slot="label">Choose a location:</span>
  <sp-menu-item>Istanbul</sp-menu-item>
  <sp-menu-item>London</sp-menu-item>
  <sp-menu-item>Maputo</sp-menu-item>
  <sp-menu-item>Melbourne</sp-menu-item>
  <sp-menu-item>New York</sp-menu-item>
  <sp-menu-item>San Francisco</sp-menu-item>
  <sp-menu-item>Santiago</sp-menu-item>
  <sp-menu-item>Tokyo</sp-menu-item>
</sp-picker>

Use side-aligned="end" to display the <sp-field-label> inline and to align the label text to the "end" of the flow of text:

<sp-field-label
  for="lifestory-2"
  side-aligned="end"
  required
  style="width: 120px"
>
  Life Story
</sp-field-label>
<sp-textfield
  placeholder="Enter your life story"
  id="lifestory-2"
></sp-textfield>
<br />
<br />
<sp-field-label for="birth-place-2" side-aligned="end" style="width: 120px">
  Birthplace
</sp-field-label>
<sp-picker id="birth-place-2">
  <span slot="label">Choose a location:</span>
  <sp-menu-item>Istanbul</sp-menu-item>
  <sp-menu-item>London</sp-menu-item>
  <sp-menu-item>Maputo</sp-menu-item>
  <sp-menu-item>Melbourne</sp-menu-item>
  <sp-menu-item>New York</sp-menu-item>
  <sp-menu-item>San Francisco</sp-menu-item>
  <sp-menu-item>Santiago</sp-menu-item>
  <sp-menu-item>Tokyo</sp-menu-item>
</sp-picker>

Necessity Indicator

Field labels can indicate whether an input is required or optional. By default, required fields are marked with an asterisk icon.

<sp-field-label for="name-required" required>Full name</sp-field-label>
<sp-textfield
  placeholder="Enter your full name"
  id="name-required"
  required
></sp-textfield>
<sp-field-label for="description-optional">
  Profile description (optional)
</sp-field-label>
<sp-textfield
  placeholder="Enter a description"
  id="description-optional"
></sp-textfield>

States

Disabled

When the associated input field is disabled, the field label should also be disabled.

<sp-field-label for="disabled-field" disabled>Country</sp-field-label>
<sp-textfield
  placeholder="Enter your country"
  id="disabled-field"
  disabled
></sp-textfield>

Behaviors

Text Overflow

When a field label is too long for the available horizontal space, it wraps to form another line.

<sp-field-label for="seminar-field" style="max-width: 200px">
  What you're hoping to learn from the seminar and any specific topics you'd
  like covered
</sp-field-label>
<sp-textfield
  placeholder="Enter your expectations"
  id="seminar-field"
></sp-textfield>

Accessibility

Always include a label

Every input should have a label. An input without a label is ambiguous and not accessible. In rare cases where context is sufficient and an accessibility expert has reviewed the design, the label could be visually hidden but should still include an aria-label in HTML.

Ensure proper association

The for attribute of the field label should match the id attribute of the associated input element to ensure proper association for screen readers and other assistive technologies.

Keep labels concise

Use a short, descriptive label (1-3 words) for the information that users need to provide. Supplementary information or requirements should be shown in help text below the field, not in the label.

Use sentence case

Following Adobe's UX writing style, field labels should be written in sentence case unless they contain words that are branded terms.

Don't add a colon at the end of a field label

The design of the component already communicates the relationship between the label and the input field, so a colon is unnecessary.

Mark only required or only optional fields, not both

In a single form, mark only the required fields or only the optional fields, depending on whichever is less frequent in the entire form. This reduces visual noise and makes the form easier to understand.