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
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 SelectDemo = () => (
<Select items={items} placeholder="Select a fruit">
<SelectTrigger aria-label="Fruit" className="w-48">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectGroup>
{items.map((item) => (
<SelectItem key={item.value} value={item.value}>
{item.label}
</SelectItem>
))}
</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. Switched on, the open list puts Banana right over the trigger, so the current choice stays under the pointer, and switched off, the list drops below the trigger like a dropdown. The demo toggles alignItemWithTrigger on SelectContent. Turn alignment off when the open list shouldn't cover the label above the field.
Groups
Fruits and vegetables sit in two groups, each under its own heading, with a SelectSeparator between them. Each heading is a SelectLabel at the top of its 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, add disabled to that SelectItem.
Invalid
A Fruit field in its error state, with "Please select a fruit." in red under the trigger. data-invalid on Field colors the label, and aria-invalid on SelectTrigger turns the 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 div whose dir is rtl. UI SDK renders the open list in place and has it follow the direction the trigger inherits, so both run right to left. 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 React?
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.
items on Select takes a read-only array too, such as one written as const, and with no value or defaultValue the items' values give the value its type, so onValueChange receives one of them rather than any string.
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 Select, as the demos here do with "Select a fruit", and it shows while nothing is selected, unless a placeholder on SelectValue overrides it. To clear the choice from code, set the value to null and the prompt comes back. This file has no part that clears it, so put a Clear button next to the field when people need one.
Why does my Select show the value instead of the label?
It shouldn't: UI SDK takes each item's text as its label, and the trigger shows the chosen one's, even before the list has ever opened, since it reads the items it hasn't shown yet. When an item holds more than its name, such as a second line of detail, give that SelectItem a label with only the words the trigger should show.
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?
Set alignItemWithTrigger to false on SelectContent. By default UI SDK places the selected item over the trigger, the way a macOS menu opens, so the list covers the field. With it off, the list opens below, and side and sideOffset decide where.
A touch always opens the list below, whatever the prop says. The Align item demo switches between the two.
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?
Add aria-invalid to SelectTrigger, which both the red border and screen readers read, and data-invalid to the Field around it, which turns the label red. Put the reason in a FieldError under the select, as the Invalid demo does, because a red outline alone doesn't say what's wrong.
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?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?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?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?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?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?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?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?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?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?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?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?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?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string
Merged with the part's classes.











