2.0.0
Labels describe form elements and indicate whether they’re required or optional.
See Forms for guidance on composing full forms.
Use to describe a form input.
<label class="mds-form__label"> First Name </label>
Use to indicate an input is required.
<label class="mds-form__label"> First Name <abbr class="mds-form__label-required-indicator" title="This field is required." aria-hidden="true">*</abbr>
<span class="mds-form__label-required-indicator-label">Required Field.</span>
</label>
Use to indicate an input is optional.
<label class="mds-form__label"> First Name<span class="mds-form__label-optional"> (Optional) </span>
</label>
Sizing affects text size. The default size is medium, and you can use a modifier class to make the label smaller (mds-form__label--small
) or larger (mds-form__label--large
).
<label class="mds-form__label mds-form__label--small"> First Name <abbr class="mds-form__label-required-indicator" title="This field is required." aria-hidden="true">*</abbr>
<span class="mds-form__label-required-indicator-label">Required Field.</span>
</label>
label
with each form element. See the Forms composition section for examples.placeholder
text in place of a label
.for
attribute on each label
with a value matching the id
attribute on the corresponding input
, textarea
or select
.mds-form__field-group
container.<div class="mds-form__field-group">
<label class="mds-form__label" for="first-name">First Name</label>
<input class="mds-form__input" type="text" id="first-name" placeholder="First Name" />
</div>
Class |
Applies to |
Outcome |
---|---|---|
|
|
Applies small styles to the label text. |
|
|
Applies large styles to the label text. |