Components
Form labels commonly used with inputs.
Version: | 4.0.3 •View source•Changelog•Report issue | |
---|---|---|
Install: | yarn add @thumbtack/thumbprint-scss |
When using a <label>
, it’s important to ensure that the <label>
is linked to a form element. You can do this by:
for
attribute to the <label>
that matches the id
of an associated form element.label
. (You’ll have to add the tp-label
class to an element within the <label>
and not on the <label>
itself.)If done correctly, clicking on the label text should switch the browser’s focus to the form element.
<label class="tp-label" for="input-2781013281341440">Email address</label><inputtype="text"class="tp-text-input"id="input-2781013281341440"placeholder="example@example.com"/>
Labels can appear visually disabled. It’s important to also disable the associated form element.
<label class="tp-label tp-label--disabled" for="input-22291815954776064">Email address</label><inputtype="text"class="tp-text-input"disabledid="input-22291815954776064"placeholder="example@example.com"/>
You can change the label color to red when the associated form element has invalid data.
Validation errors must be also include text that explains the error. This helps guide the user and is crucial for users with visual impairments.
<label class="tp-label tp-label--bad-news" for="input-1301239354621952">Email address</label><inputtype="text"class="tp-text-input tp-text-input--bad-news"id="input-1301239354621952"value="example@exampl"/><div class="tp-form-note tp-form-note--bad-news">The email address you entered is incorrect.</div>