Skip to content

Input Fields

Edit on GitHub
@volvo-cars/css v2.3.0@volvo-cars/react-forms v2.0.0

Our input fields follow HTML browser defaults, with variants available for different use cases like currency input, password input, and more.

image

  1. Label - Indicates what the user should enter. Can be rendered directly by the component or supplied separately.
  2. Input / Placeholder Texts - The text-entry or selection area (for text input, select menus, etc.).
  3. Cursor - When the input field is in focus, the cursor blinks to indicate that the user can type.
  4. Container - The overall wrapper with a visible stroke or outline. Its appearance changes based on the current state.
  5. Slot before (optional) - Typically holds non-interactive icons or short prefixes (e.g., currency symbol).
  6. Slot after (optional) - Typically used for interactive icons (e.g., toggles, clear buttons) or short suffixes.
  7. Form Message (optional) - Displays an additional hint text (often very technical or contextual) below the input.

We offer 2 variants of input fields. Top label and floating label. Input fields with top labels are recommended in most cases.

Showing examples of input fields with both floating labels and top labels

Showing examples of input fields with both floating labels and top labels.

Prefer input fields with top labels, as they provide the following benefits:

  • Improves scan-ability and readability of labels
  • Allows for more input types with prefixes (e.g. Currency) as well as suffixes
  • Enables designs with larger labels and descriptions in conversational forms or focused tasks
  • Reduces confusion between what’s a label and what’s placeholder text
  • Supports narrower input fields when appropriate (e.g., postal codes)
  • Allows making inputs and buttons the same height for placement side-by-side
  • Handles longer (translated) labels better, reducing bugs
  • Reduces the risk of browser- and browser-extension specific issues and bugs

Use floating label inputs sparingly, as they offer limited advantages compared to top labels. However, they can be helpful when:

  • Helps conserve vertical space in compact layouts
  • Fits better in narrow UI components such as sidebars or filter panels

By default, these inputs leverage native HTML attributes and behaviors wherever possible (e.g., browser autofill, date pickers, validation).

If you need custom multi-select dropdown, advanced search filters, or special behaviors, you can create a custom input variant.

There should always be an associated label that is programmatically tied to each input field. Screen readers rely on these labels to announce the field’s purpose.

Avoid placeholders unless absolutely necessary. They often reduce accessibility (screen readers or visually impaired users may miss them), and they disappear once the user starts typing.

Currency inputs handle monetary values by displaying the currency symbol or code as a prefix or suffix.

image

Allows users to select a date from the native calendar dropdown. Use this when users need to see the calendar context.

image

Allows users to select a date and time from the native calendar dropdown. Use this when it’s important to capture both date and time.

image

Email input should be used whenever the user needs to enter an email address. While it appears identical to a text input, it triggers email-specific keyboard layouts on mobile devices.

image

Password input should be used when a user needs to enter a password. It provides functionality to show/hide the password.

image

Tel input should be used when users need to enter a phone number. While it appears identical to a Text input, it triggers numeric keyboard layouts on mobile devices.

image

Select allows users to choose one option from a predefined list containing three or more choices. For fewer options, consider using radio buttons instead.

image

Text area provides a multi-line text input field that expands vertically to accommodate longer content.

image

A standard text input field designed for single-line text entry.

image

The Unit input allows users to enter measurements like distance, with the appropriate localized unit displayed as a suffix.

image

Use URL input when users need to enter a web address. While it appears identical to a Text input, it provides URL-specific validation.

image

Custom inputs are designed for variants not included in the library. Use the slot as a placeholder to build your own input type.

image

The normal, non-focused state where the input is enabled and available to interact with.

image

The container’s outline changes color as the cursor hovers over the input area.

image

When clicked or tapped, the outline becomes thicker to highlight that the component is currently being interacted with.

image

The active state looks similar to the focus state and is essentially equivalent. It activates specifically during interaction.

image

The input is grayed out and cannot be interacted with. Used when the system or logic prevents a user from editing the field.

image

The input field as presented in light mode contexts

The input field as presented in light mode contexts.

The input field as presented in dark mode contexts

The input field as presented in dark mode contexts.

Each input field has a minimum height of 48px. All input fields must have a clearly connected label, ensuring that the combined touch target meets accessibility requirements.

image

The default text-based inputs have a fixed height, whereas text areas have a minimum height that can expand.

image

Interactive elements in the right slot (e.g., show/hide password) are based on our existing icon button patterns.

image

It is important to maintain consistent vertical spacing between each input field. A general recommendation is to use 24px spacing between fields.

image

Example with top label using 24px spacer

image

Example with floating label using 24px spacer

image

Example with heading, top label and button

When input fields are placed on the same line, they should have a logical relationship, with 16px spacing between them.

image

Default labels have an 8px spacing between itself and the actual input field. Hint/error messages similarly have 8px spacing below the input.

image

In most circumstances, always opt to arrange your forms vertically as this makes it significantly easier to scan and complete.

image

Do - It is highly recommended to always stack form input fields vertically as this makes the form easier to scan.

image

Don’t - It is generally recommended to avoid breaking forms into several columns as it has a significant impact on usability.

image

Do - However, there’s one main exception to this rule and that is when there’s a very clear logical grouping.

Example of an input field linked to a slider

Example of an input field linked to a slider.

Example of a date input using native date picker

Example of a date input. Date input uses native date picker.

Example of a masked input field

Example of a masked input field.

Don’t mix input fields with standard labels and floating labels in the same layout.

image

If most fields in a form are required, mark optional fields instead of marking all required fields. This reduces visual noise.

Displaying optional fields and one required field

Displaying optional fields and one required field.

Displaying required field and one optional field

Displaying required field and one optional field.

To reduce user stress and frustration, implement lazy validation. Instead of showing immediate warnings, validate fields when the user moves away or submits.

Consider which mobile keyboard type is most appropriate for your input field. You can control this using the inputMode attribute.

image

Input fields should match the width of their containing form. On mobile devices, inputs should span the full width of the viewport.

While desktop forms can be more flexible in width, all inputs within the form should maintain consistent widths for visual alignment.

image