shadcn.io is an independent project built on shadcn/ui
On this page9 sections
A select is a button that opens a fixed list of options and, once someone picks one, shows its label in place of the prompt. Reach for it when the list is short enough to scan and a typed-in value would be wrong: a time zone, a role, a sort order.
If people know the name and would rather type it, a Combobox filters as they go. On a phone, or anywhere the browser's own menu will do, use a Native Select.
Installation
Anatomy

Usage
<script lang="ts">
import { createListCollection } from "@/lib/collection"
import {
Select, SelectContent, SelectGroup, SelectItem, SelectTrigger,
SelectValue,
} from "@/components/ui/select"
const items = [
{ label: "Apple", value: "apple" },
{ label: "Banana", value: "banana" },
{ label: "Blueberry", value: "blueberry" },
]
const collection = createListCollection({ items })
</script>
<Select collection={collection}><SelectTrigger aria-label="Fruit" class="w-48"><SelectValue placeholder="Select a fruit" /></SelectTrigger><SelectContent><SelectGroup>{#each collection.items as item (item.value)}<SelectItem item={item}>{item.label}</SelectItem>{/each}</SelectGroup></SelectContent></Select>Accessibility
The trigger is a button with role="combobox" that reports aria-expanded, and the open list is a role="listbox" whose options take focus one at a time as you move through them. Choosing one or pressing Escape sends focus back to the trigger. Naming the field is up to you: inside a Field, its label names the trigger on its own, and without one, give SelectTrigger an aria-label, as the demos here do. UI SDK warns in development when the trigger has no name.
- Space
- When focus is on the trigger, opens the list on the selected item, or on the first one. In the open list, selects the focused item and, in a single select, closes the list.
- Enter
- When focus is on the trigger, opens the list on the selected item, or on the first one. In the open list, selects the focused item and, in a single select, closes the list.
- Arrow Down
- When focus is on the trigger, opens the list on the selected item, or on the first one. In the open list, moves focus to the next item, and from the last one back to the first.
- Arrow Up
- When focus is on the trigger, opens the list on the selected item, or on the first one. In the open list, moves focus to the previous item, and from the first one to the last.
- Home
- When focus is on the trigger, opens the list on the first item. In the open list, moves focus to the first item, as PageUp does.
- End
- When focus is on the trigger, opens the list on the last item. In the open list, moves focus to the last item, as PageDown does.
- Alt+Arrow Up
- In the open list of a single select, selects the focused item and closes the list. In a multiple select, only closes it.
- EscEscape
- Closes the list and returns focus to the trigger.
- Tab
- Closes the list and moves focus on from the trigger.
- A-Z
- When focus is on the trigger of a single select, selects the next item whose label starts with the typed letters, without opening the list. In the open list, moves focus to that item.
Demos
Align item
A switch sits above a fruit select that starts on Banana. This list opens next to the trigger rather than over it, and the switch moves it from below to above by setting placement in positioning on Select to top-start, which the wrapper turns into UI SDK's side and align. Open it above when the field sits near the bottom of a dialog or a page.
Groups
Fruits and vegetables sit in two groups, each under its own heading, with a SelectSeparator between them. The headings come from the heading prop on SelectGroup. Group the options when people scan by category, such as roles by department. With a handful of peers, a heading only repeats the field's label.
Scrollable
Twenty-seven time zones in five regional groups, far more than fit, so the list scrolls inside a height capped to the room left on screen. Use this when people pick by reading the names. When they already know the zone and would type it, a Combobox gets them there faster.
Disabled
The whole select is disabled with disabled on Select, so the trigger dims, keeps its "Select a fruit" prompt and drops out of the tab order. Use it when the field waits on an earlier answer, or when this user can't change it. To rule out one option instead, set disabled to true on its entry in the collection.
Invalid
A Fruit field in its error state, with "Please select a fruit." in red under the trigger. invalid on Field reaches the trigger as aria-invalid, which turns its border red and tells screen readers the value is wrong. Show this after a submit that left a required choice empty.
RTL
Arabic fruit names under the prompt "اختر فاكهة", inside a DirectionProvider with direction set to rtl, which sets dir on an element around the select. The trigger turns around, and the open list keeps that direction where it's portaled. For a page that reads right to left throughout, set dir on the <html> element and wrap the app in the provider from Direction.
FAQ
How do I control a Select's value in Svelte?
Hold the value in state, pass it as value and update it in onValueChange, which receives the new value first and the details second. In a single select the value is the chosen item's value, or null, and with multiple it's an array. The trigger finds the label among the items itself, so it shows Banana for banana with no lookup of your own.
Once the value lives in your state, a URL parameter or a saved preference can set it, and a Reset button can clear it.
How do I show a placeholder in a Select, and clear the choice again?
Set placeholder on SelectValue, as the demos do, or on Select, and it shows while nothing is selected. To clear the choice from code, set the value to null and the prompt comes back. To let people clear it themselves, set showClear on SelectTrigger, which puts a clear button beside the trigger once something is chosen.
Why does my Select show the value instead of the label?
It shouldn't: the wrapper hands the collection's entries to UI SDK as its items, so the trigger shows the chosen entry's label, even before the list has ever opened. If your data names that field something else, pass itemToString to createListCollection, and itemToValue for the value. A SelectItem can render more than that, such as an icon or a second line of detail, and the trigger still shows only the label.
Can a Select let people pick more than one option?
Yes. Add multiple to Select, and the value becomes an array. The list stays open between picks, SelectValue joins the labels with commas, and the form gets one hidden input per value under the same name.
The trigger keeps to one line, so when people often pick more than two or three, a Combobox that shows each choice as a chip reads better.
How do I make the Select list open below the trigger?
It already does: the list opens below the trigger, lined up with its start edge, 4 pixels away and at the same width, and flips above it when there's no room underneath. To move it, set positioning on Select, whose placement and gutter the wrapper turns into UI SDK's side, align and sideOffset, or pass those to SelectContent directly, where they win.
The Align item demo switches placement to top-start to open the list above the trigger.
How do I submit a Select with a form?
Set name on Select, and UI SDK renders a hidden input that carries the value, or one per value with multiple. Add required and the browser refuses to submit the form while nothing is chosen. Set form to the form's id when the select sits outside the <form> it belongs to.
The form receives the item's value, not its label, so give each item the one your server expects.
How do I show a Select as invalid?
Set invalid on the Field around it, and UI SDK gives the trigger aria-invalid, which both the red border and screen readers read, while the field turns its label red. A FieldError inside that Field only appears while it's invalid, so it can sit in the markup all along, as in the Invalid demo.
Should I use a Select, a Combobox or a Native Select?
Use a Select when people choose from a list they can scan in a moment and shouldn't type their own value: a status, a role, a sort order. It looks the same in every browser and can hold groups and icons.
Switch to a Combobox once the list is long enough that people would rather type to filter it, such as countries or users. A Native Select is the browser's own <select>: it can't be styled inside, but on a phone it opens the system picker people already know.
API Reference
Select
emptyItems?SelectItems<NoInfer<ItemValue<ValueOf<T, ItemList>>>>
Items shown instead of items while the search field is empty, like recent choices.
- Type
SelectItems<NoInfer<ItemValue<ValueOf<T, ItemList>>>>
items?ItemList & SelectItems<NoInfer<ItemValue<ValueOf<T, ItemList>>>>
The items as data: strings, { value, label } objects, groups and
separators, in a readonly array too. Without value or defaultValue,
they give the value its type.
- Type
ItemList & SelectItems<NoInfer<ItemValue<ValueOf<T, ItemList>>>>
SelectGroup
<div> data-slot="select-group"
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
SelectValue
<span> data-slot="select-value"
getMoreLabel?(count: number) → string
The words for the labels past maxLabels.
- Default
(count) => `${count} more`- Parameters
count– number- Returns
string
maxLabels?number
With multiple, how many labels show before the rest are counted, as in "Apple, Banana and 2 more", joined the way the page's language joins lists, or in English with the default getMoreLabel.
placeholder?string
What shows while nothing is selected. Overrides the select's placeholder.
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
data-placeholder?string
Present while nothing is selected, so the placeholder shows.
SelectTrigger
<button> data-slot="select-trigger"
controller?SelectController<any, any>
Connects a trigger outside the select to the select with this controller.
- Type
SelectController<any, any>
disabled?boolean
Stops the trigger from opening the list. A native button can't be focused or pressed.
- Default
false
size?"sm" | "default"
The size.
- Type
"sm" | "default"- Default
"default"
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
data-closed?string
Present while the list is closed, including while it animates out.
data-disabled?string
Present when the select or the trigger is disabled.
data-open?string
Present while the list is open.
data-placeholder?string
Present while nothing is selected, so the placeholder shows.
data-readonly?string
Present when the select is read-only.
data-required?string
Present when the select is required.
SelectContent
<div> data-slot="select-content"
align?Align
How the popup lines up with the anchor along that side. start and end follow the reading direction. How the list lines up with the trigger along that side. UI SDK's default: start.
- Default
"center"
alignItemWithTrigger?boolean
Whether the list overlaps the trigger so the selected item sits on it, like a native select on macOS. Falls back to opening below when there isn't room, and for touch. UI SDK's default: false.
- Default
true
alignOffset?number
Shift along the anchor, in pixels. Shift along the trigger, in pixels.
- Default
0
anchor?string | Anchor | null
Positions the popup against this instead of its trigger: an element, a CSS selector, a point like { x, y }, or anything with getBoundingClientRect(). It's read on every check, so it can move. A controller's open({ anchor }) wins for that open.
- Type
string | Anchor | null
arrowPadding?number
Space to keep between the arrow and the popup's corners, in pixels.
- Default
6
collisionPadding?number
Space to keep from the viewport edges, in pixels.
- Default
8
container?DocumentFragment | Element | null
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
- Type
DocumentFragment | Element | null
keepMounted?boolean
Whether the list stays in the page, hidden, while closed. Its content keeps its state between opens.
- Default
false
side?Side
Which side of the anchor the popup opens on. Flips to the other side when there isn't room. Which side of the trigger the list opens on.
- Default
"bottom"
sideOffset?number
Gap between the anchor and the popup, in pixels. Gap between the trigger and the list, in pixels.
- Default
4
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
data-align"start" | "center" | "end"
How the list lines up with the trigger.
- Type
"start" | "center" | "end"
data-align-trigger?string
Mirrors alignItemWithTrigger.
data-closed?string
Present while the list is closed, including while it animates out.
data-ending-style?string
Present while the list animates out. Style the state you animate to.
data-has-icons?string
Present while any item inside holds an icon part, so items without one can line up.
data-modality"keyboard" | "pointer"
Whether the keyboard or a pointer is in use, for focus styles.
- Type
"keyboard" | "pointer"
data-open?string
Present while the list is open.
data-presentation"popover" | "sheet"
How the list presents this time it's open.
- Type
"popover" | "sheet"
data-side"top" | "right" | "bottom" | "left"
Where the list ended up, after flipping away from edges.
- Type
"top" | "right" | "bottom" | "left"
data-starting-style?string
Present for the first frame. Style the state you animate from.
--anchor-heightstring
Height of the anchor.
--anchor-widthstring
The anchor's width.
--arrow-offsetstring
Where the anchor's center falls along the popup's edge, kept arrowPadding from the corners. Position a ::before arrow with it.
--available-heightstring
The height left between the anchor and the viewport's edge.
--available-widthstring
Space beside the popup, up to the viewport edge. Not inherited either.
--drawer-dimstring
While it presents as a sheet: how dim the page behind is, from 0 to 1. The backdrop's opacity follows it.
--drawer-expandstring
While it presents as a sheet: 0 at the second-largest snap point and below, 1 at the largest. With one snap point, the whole travel.
--drawer-progressstring
While it presents as a sheet: how far open the sheet is, from 0 closed to 1 at its largest snap point. Never past 1.
--drawer-stackstring
While it presents as a sheet: how many sheets opened from inside this one are open above it, rising smoothly as each one opens. Push it back with it.
--sheet-backdropstring
Set it yourself: the color the page dims to while it presents as a sheet. Black at 0.2 by default.
--transform-originstring
Where the content scales from, on its trigger's side.
SelectScrollUpButton
SelectScrollDownButton
SelectLabel
<div> data-slot="select-group-label"
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
SelectItem
<div> data-slot="select-item"
valueT
What the value becomes when the item is chosen. A string, or any value with itemToValue.
disabled?boolean
Keeps the item from being chosen. The keyboard and the pointer skip it. Sets data-disabled and aria-disabled.
index?number
The item's position among all items, for virtualized lists that render only some. Sets aria-posinset and aria-setsize.
label?string
The text the trigger shows and typing finds, when the content isn't plain text. Not the accessible name: use aria-label for that.
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
data-disabled?string
Present when the item can't be chosen.
data-has-icon?string
Present on an item while it holds an icon part.
data-highlighted?string
Present on the item with keyboard focus or under the pointer, or highlighted while focus stays in the search field.
data-selected?string
Present on selected items, and on the check inside them.
SelectSeparator
<div> data-slot="select-separator"
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.











