Color selector

Color selector to enable selection of a desired color

Overview

  • Available since: Washington DC
  • A11Y: Not compliant

Color selector allows users to pick a color through a color palette, dropper, slider, or by entering a valid color value.

Loading playground

When to use

Use color selector when you need users to choose a color for a UI element.

When not to use

Don't use color selector if the choice of color is not relevant to the task. If color selection isn't essential, consider simpler options or presets.


Anatomy

Learn about the individual parts of color selector.

Color selector without tabs

  1. Color name section (optional): Displays the color name information
  2. Form label: Text that identifies what the user should enter in a text input field; a label must be present for accessibility, either as the component's label element or external to the component
  3. Required indicator: Field decorator that indicates if a field is required
  4. Information icon (optional): Opens a popover on click and shows the field helper text
  5. Input url (custom): Space for user input and placeholder text
  6. Edit icon (optional): Enables user to edit the text in the input area
  7. Color selection: Contains the saturation-brightness area, color monocle, hue slider, preview swatch, and color variable reference
  8. Divider line: A line that separates the footer buttons from the color selector content
  9. Footer buttons: “Cancel” discards any choices made; “Apply” confirms any color changes to the color swatch
  10. Delete button: Removes the selected color from the library
  11. Trigger: Initiates opening and closing of the color selector

Color selection

  1. Color monocle: Circle that indicates the selected color
  2. Saturation-brightness area: Displays the range of saturation and brightness of the hue selected
  3. Hue slider: Slider that impacts what color will display in the preview swatch and the saturation-brightness area
  4. Preview swatch: Showcases the color selected in the color monocle, which also matches the color variable reference in the input below
  5. Input: Input field with a dropdown for HEX, RGB, or HSL values

Custom colors tab

  1. Header: Title for your “Custom” tab
  2. Color monocle: Circle that indicates the selected color
  3. Saturation-brightness area: Displays the range of saturation and brightness of the hue selected
  4. Hue slider: Slider that impacts what color displays in the preview swatch and the saturation-brightness area
  5. Preview swatch: Showcases the color selected in the color monocle, which also matches the color variable reference in the input below
  6. Input: Input field with a dropdown for HEX, RGB, or HSL values
  7. Accessibility tools (optional): Shows user the contrast ratio of the selected color against a configurable color
  8. Footer buttons: “Cancel” disregards any choices made; “Apply” confirms any color changes to the color swatch that launched the color selector

My colors tab - grid view

  1. Tabs: Separates “My Colors” and “Custom” content in pop-up modal
  2. Search: Text field to search globally for colors in the theme
  3. Stateful buttons: Toggle between grid view and list view
  4. Swatch group label: Label used to name a group of color swatches
  5. Selected color swatch: Color swatch with a check-mark to indicate it is selected
  6. Color swatch: Square element that displays color
  7. Color section header: Header that displays additional information about the color swatch groups
  8. Accessibility tools (optional): Displays contrast ratio of the selected color against another configurable color; shows or hides colors that have insufficient contrast
  9. Footer buttons: “Cancel” disregards any choices made, “Apply” confirms any color changes to the color swatch that launched the color selector

My colors tab - list view

  1. Tabs: Enables user to separate content in pop-up modal
  2. Search: Text field to search globally for colors in the theme
  3. Stateful buttons: Enables user to switch between grid view and list view
  4. Swatch group label: Label used to name a group of color swatches
  5. Swatch name: Friendly name for the color swatch
  6. Swatch color variable: HEX, HSL or RGB value
  7. Color swatch: Square element that displays color
  8. Selected color swatch: Color swatch with a check-mark to indicate it is selected
  9. Accessibility tools (optional): Displays contrast ratio of the selected color against another configurable color; shows or hides colors that have insufficient contrast
  10. Footer buttons: “Cancel” disregards any choices made, “Apply” confirms any color changes to the color swatch that launched the color selector

Usage

This component can be used to select colors and to display information for a selected color swatch, with the ability to switch between a selector view, grid view, and palette view. You can access custom colors in addition to HEX, RGB, and HSL values.

Configurations

Learn how to customize color selector by configuring the available properties.

Trigger type

You can choose either a button trigger or select trigger for your color selector.

Color selector panel position

Using an array, you can define possible positions that the color selector panel can appear, relative to the trigger.

Tabs

You can assign a name to the tabs that will show in grid and list view. The default used is “My Colors,” and “Custom.”

Initial color

You can assign the initial color to display when the selector is opened.

Colors

You can provide an array of color objects to display in the “My Colors” tab, and assign them names.

You can configure the footer to include user actions such as “Cancel” and “Apply.”

Accessible color selector

You can enable accessibility options for color selector to configure the contrast check type and the comparison color.

Contrast check type

You can set the text contrast or the graphics contrast to determine the minimum visual contrast ratio for accessible design. Visit the links below for more information on text and non-text contrast standards.


Text contrast accessibility standards

Non-text contrast accessibility standards

Comparison color

Configure this property to set the comparison color. When the user selects a color, it will be compared to the comparison color to find the contrast ratio.


UI text guidelines

These are some recommendations for using text within color selector:

  • The field helper text should provide additional context to the form label
  • Use a tooltip on the Edit icon to show the verb that will happen when the person selects it

Behavior

Learn how color selector behaves when the display changes or a user interacts with the component.

Color swatch states (grid view)

Color selector swatches in grid view have the following states: default, hover, press/focus, and selected.

State Example
Default now-color-selector
Hover now-color-selector
Press/focus now-color-selector
Selected now-color-selector

Color swatch states (list view)

Color selector swatches in list view have the following states: default, hover, press/focus, and selected.

State Example
Default now-color-selector
Hover now-color-selector
Press/focus now-color-selector
Selected now-color-selector

Monocle states

The color selector monocle has following states: default and active.

State Example
Default now-color-selector
Active now-color-selector

Hue slider states

The color selector hue slider has following states: default and active.

State Example
Default now-color-selector
Active now-color-selector

Responsive behaviors

Learn how color selector responds to changes in a container or display.

Autofill color variable digits

If a user enters shorthand variables, the rest of the color’s digits will autofill. For example, #09C will be automatically corrected to #0099CC.

Horizontal stage picker with keyboard tab key order from left to right starting with left stage scrolling arrow button and continuing through each stage and then its action icon button

Scrolling

The scroll bar is hidden by default, it will appear once the user hovers over the scroll bar area.

Interactions

Learn how color selector responds when a user interacts with it.

Select a color using the dropdown

The user can select a color by entering a HEX, RGB, or HSL variable into the dropdown below the hue slider. If variables are removed, it will automatically display the last accepted value. The user can also switch between using HEX, RGB, or HSL values by selecting the dropdown and choosing a different color variable type.

Horizontal stage picker with keyboard tab key order from left to right starting with left stage scrolling arrow button and continuing through each stage and then its action icon button

Change a color with the monocle

When the color monocle is active, the user can move it to change the color displayed in the saturation-brightness area.

Horizontal stage picker with keyboard tab key order from left to right starting with left stage scrolling arrow button and continuing through each stage and then its action icon button

Change a color name

The user can select the pencil icon next to the current color name to open an input field where a new name may be entered.

Horizontal stage picker with keyboard tab key order from left to right starting with left stage scrolling arrow button and continuing through each stage and then its action icon button

Search for colors

The user can search for colors in the “My Colors” tab using theming variable names, friendly names, hexcode, RGB, and HSL values.

Horizontal stage picker with keyboard tab key order from left to right starting with left stage scrolling arrow button and continuing through each stage and then its action icon button

Hide inaccessible colors

If accessibility tools are enabled, users can hide colors that have insufficient contrast. By default, “hide inaccessible choices” toggle is off, and the color selector displays all colors. When the user toggles it on, color selector hides colors that have insufficient contrast with its comparison color. This is only available in the “my colors” tab.

Horizontal stage picker with keyboard tab key order from left to right starting with left stage scrolling arrow button and continuing through each stage and then its action icon button

Usability

Color selector complies with all internationalization and accessibility requirements.

Internationalization

When this component is used in a platform configured for a right-to-left (RTL) language, the text and elements move to the opposite side.

Horizontal stage picker with keyboard tab key order from left to right starting with left stage scrolling arrow button and continuing through each stage and then its action icon button

Accessibility

Learn how to access the actionable elements of color seletor through keyboard interactions and screen readers.

Selector view tab order

Horizontal stage picker with keyboard tab key order from left to right starting with left stage scrolling arrow button and continuing through each stage and then its action icon button

Custom color view

Horizontal stage picker with keyboard tab key order from left to right starting with left stage scrolling arrow button and continuing through each stage and then its action icon button

Keyboard interactions

You can access the actionable elements of color selector with these keyboard keys:

  • Tab: Moves focus to the next actionable element
  • Shift + Tab: Moves focus to the previous actionable element

When focus is on the color monocle:

  • Arrow keys: Moves the monocle around to change the color in the saturation-brightness area

Screen readers

When you apply ARIA labels to a component, screen readers announce the controls and content of color selector in the prescribed tab order.