Skip to content

Soracom

Design System
Home Design System Ux Patterns Required fields

Required fields

Marking required fields in forms

Overview 

When implementing a form that has required and optional fields, care should be taken to ensure a consistent and predictable experience.

Always
  1. Mark all required fields
  2. Ensure there is a description at the top of the form
  3. Place the required indicator at the end of the field label
  4. Use the correct ARIA attributes
Never
  1. Mark optional fields
  2. Use the placeholder text to indicate a field is required

Exceptions 

In certain circumstances it’s ok to not mark required fields, these include:

  • Sign in forms
  • Single field forms (such as a confirmation checkbox in a notice)

Implementation 

Required fields should be indicated using the following 3 methods:

1. At the top of the form ensure there is a message indicating there are required fields:

<p class="ds-text --small">
  Fields marked with an asterisk (<abbr class="--required" title="required">*</abbr>) are required.
</p>

2. The label text must have the required indicator <abbr class="--required" title="required">*</abbr> at the end:

<label for="required-1" class="ds-text --label">
  Label content <abbr class="--required" title="required">*</abbr>
</label>

3. Each required field must have the required and aria-required="true" attributes:

<div class="ds-input">
  <input id="required-1" type="text" required aria-required="true"/>
</div>

Examples 

Example using div container
<p class="ds-text --small">Fields marked with an asterisk (<abbr class="--required" title="required">*</abbr>) are required.</p>
<div class="ds-field">
  <label for="required-1" class="ds-text --label">Label content <abbr class="--required" title="required">*</abbr></label>
  <div class="ds-input">
    <input id="required-1" type="text" required aria-required="true"/>
  </div>
</div>
XS Mobile 320px Mobile 420px Tablet 680px Desktop 960px
<p class="ds-text --small">Fields marked with an asterisk (<abbr class="--required" title="required">*</abbr>) are required.</p>
<div class="ds-field">
  <label for="required-1" class="ds-text --label">Label content <abbr class="--required" title="required">*</abbr></label>
  <div class="ds-input">
    <input id="required-1" type="text" required aria-required="true"/>
  </div>
</div>
Example using label container
<p class="ds-text --small">Fields marked with an asterisk (<abbr class="--required" title="required">*</abbr>) are required.</p>
<label class="ds-field">
  <p class="ds-text --label">Text content <abbr class="--required" title="required">*</abbr></p>
  <div class="ds-input">
    <input type="text" required aria-required="true"/>
  </div>
</label>
XS Mobile 320px Mobile 420px Tablet 680px Desktop 960px
<p class="ds-text --small">Fields marked with an asterisk (<abbr class="--required" title="required">*</abbr>) are required.</p>
<label class="ds-field">
  <p class="ds-text --label">Text content <abbr class="--required" title="required">*</abbr></p>
  <div class="ds-input">
    <input type="text" required aria-required="true"/>
  </div>
</label>

References