---
title: Examples
slug: wip/bzkj-examples
createdAt: 2023-07-20T14:45:03.180Z
---

# Examples

## Basic Usage

A simple, yet accessible Select is provided with a descriptive label and a collection of options.

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/jOvGOmw/721e1b9a818c6b6c590036dbd3274589?default-tab=html%2Cresult&#x26;amp;theme-id=39623&#x26;amp;editable=true&#x22; height=&#x22;421px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

## Preselect option

Options can be pre-selected by either setting the `value` of the Select or the `selected` attribute for the selected Option.

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/PoXxQOV/af69b6d3caf8d10e7394893e6b522d54?default-tab=html%2Cresult&#x26;amp;theme-id=39623&#x26;amp;editable=true&#x22; height=&#x22;519px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

## Grouped Options

The Select does support grouping options to improve the structure of a larger set of choices for users.

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/Exewjmm/4314de5d678ea5ccc5c93508baeae705?default-tab=html%2Cresult&#x26;amp;theme-id=39623&#x26;amp;editable=true&#x22; height=&#x22;519px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

## Prefixed Options

Options accept prefixed content which can take any form, from other Web Components to any other visual elements that help users to distinguish a group of options more clearly.

:::hint{type="info"}
**☝️ Watch out**

The prefix is a decorative element only and should not contain any meaningful information necessary to understand or distinguish an option. Hence the content of a prefix isn't accessible to assistive technologies.
:::

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/eYPrrxx/40699d7e6ecd6ae4a6961fdc8ccf9486?default-tab=html%2Cresult&#x26;amp;theme-id=39623&#x26;amp;editable=true&#x22; height=&#x22;704px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

## Meta Information

Each option in the select can provide additional information as meta information to support users with their choices.

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/XWLLjZK/dbe2b8eafb16b68632cf1560a3e21bc1?default-tab=html%2Cresult&#x26;amp;theme-id=39623&#x26;amp;editable=true&#x22; height=&#x22;704px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

## Help Text & Placeholder

The help text and placeholder serve the purpose of guiding a user's input by providing additional information.

A help text provides more context as to why and how the data that is requested is relevant. It can either be passed as an attribute for simple string-based content or via a slot for rich formatted content.

A placeholder allows a Select to be initialized without an option being preselected while it automatically selects the first option provided when not specified otherwise.

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/qBMPBXv/6aa6a3e90ba6d75ac8983da5d6bfd19f?default-tab=html%2Cresult&#x26;amp;theme-id=39623&#x26;amp;editable=true&#x22; height=&#x22;459px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

## Required and Optional

Adding a required or optional label helps users to be guided while filling out a form. Usually, only Selects that are an exception to the majority of other form fields in a form are marked as required or optional. For example, Selects are marked as "Required" when the majority of the fields in the same form are optional and vice versa.

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/MWqEWVV/c362ee76273649a6622d8694c8e904c1?default-tab=html%2Cresult&#x26;amp;theme-id=39623&#x26;amp;editable=true&#x22; height=&#x22;575px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

## States

The Select and its Options do support a wide range of different states.

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/eYLGYKj/c5e26928da19bc7727c34f074b8bd894?default-tab=html%2Cresult&#x26;amp;theme-id=39623&#x26;amp;editable=true&#x22; height=&#x22;650px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

## Clearable

Marking a Select as clearable allows users to empty its value with a single click. 

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/oNPEmWj/db24c8b33dc7b263fe8650a17dafea66?default-tab=html%2Cresult&#x26;amp;theme-id=39623&#x26;amp;editable=true&#x22; height=&#x22;348px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

## Multiple

The `multiple` attribute enables the selection of multiple options. Options can be preselected by assigning an array of selected values to the Select's `value` property or by marking the selected Options with the `selected` attribute.

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/mdgLQOL/f97a85baba2d0bc3308c51b73764a59b?default-tab=html%2Cresult&#x26;amp;theme-id=39623&#x26;amp;editable=true&#x22; height=&#x22;348px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

## Searchable

The `searchable` attribute enables a search functionality, enabling users to quickly filter down the set of options.

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/YzbEVqK/ddc9baed0033091fa0e88b3494df6975?default-tab=html%2Cresult&#x26;amp;theme-id=39623&#x26;amp;editable=true&#x22; height=&#x22;410px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

## Validation

A Select's validity can either be determined automatically when used inside a form or can be controlled from outside based on custom rules and application business logic.

### Inside a form

Selects seamlessly integrate into a form's validation workflows and validate when a form is submitted. When no custom validation message is provided, the Select falls back to the browser's native validation message.

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/mdGBdoE/ef05127393e279f78ff6250b905c5a55?default-tab=html%2Cresult&#x26;amp;theme-id=39623&#x26;amp;editable=true&#x22; height=&#x22;453px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

### Inside an application

Selects can be individually flagged as invalid based on custom rules or other business logic of an application. When flagged as invalid, a Select expects a descriptive validation message to be set alongside.

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/ExewxzJ/b53bd544bb4023c696369375349a45b7?default-tab=html%2Cresult&#x26;amp;theme-id=39623&#x26;amp;editable=true&#x22; height=&#x22;473px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

## Listening to Events

The Select supports the most commonly used events.

:::hint{type="info"}
**💡 Did you know?**

Some native events like `change` are blocked by the Shadow DOM boundary of the web component standard. Hence some of them are proxied through custom events.

Find out more: [Form Input Events & API](https://cosmos.redbull.design/wip/form-input-events-and-api)
:::

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/oNPGgNX/528ac99b66b53e79834bbe1adcc774b2?default-tab=html%2Cresult&#x26;amp;theme-id=39623&#x26;amp;editable=true&#x22; height=&#x22;571px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

