---
title: "Select · Base UI — StyleX Blocks"
description: "Custom listbox-style select with trigger, indicator, and item slots in outline and subtle styles."
url: "https://stylexblocks.com/components/base-ui/select/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Select

Custom listbox-style select with trigger, indicator, and item slots in outline and subtle styles.

- Behavior engine: Base UI
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/select.md), [UI SDK](https://stylexblocks.com/components/ui-sdk/select.md)
- Category: Form
- Variants: outline, subtle
- Sizes: xs, sm, md, lg
- Used in blocks: [Language Select](https://stylexblocks.com/block/base-ui/language-select.md)
- HTML page: https://stylexblocks.com/components/base-ui/select/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style base-ui
```

Then add the item as source you own:

```sh
npx stylexblocks add select
```

Equivalent: `npx shadcn add @stylexblocks/select`. Registry item JSON: https://stylexblocks.com/r/base-ui/select.json

## Usage

```tsx
import { Select } from "#components/ui/base-ui/select.tsx";

const frameworks = ["Astro", "Next.js", "Remix", "Vite"];

export function Example() {
  return (
    // variant/size resolve once on Root; every part inherits them via
    // context — Icon and ItemIndicator ship default icons
    <Select.Root defaultValue="Next.js" variant="outline" size="md">
      <Select.Label>Framework</Select.Label>
      <Select.Control>
        <Select.Trigger>
          <Select.Value />
        </Select.Trigger>
        <Select.IndicatorGroup>
          <Select.Icon />
        </Select.IndicatorGroup>
      </Select.Control>
      {/* Positioner portals the popup and positions it under the trigger */}
      <Select.Positioner>
        <Select.Popup>
          {frameworks.map((item) => (
            <Select.Item key={item} value={item}>
              <Select.ItemText>{item}</Select.ItemText>
              <Select.ItemIndicator />
            </Select.Item>
          ))}
        </Select.Popup>
      </Select.Positioner>
    </Select.Root>
  );
}
```

## Source

`components/ui/base-ui/select.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { Select as BaseSelect, type SelectRootProps } from "@base-ui/react/select";
import { createSlotRecipeContext } from "#lib/base-ui/create-slot-recipe-context.tsx";
import {
  defineSlotRecipe,
  resolveSlotStyles,
  type SlotRecipeVariants,
  type StyleOverrideProps,
} from "#lib/recipe-props.ts";
import { semanticShadows } from "@stylexblocks/ui/semantic-tokens/shadows.stylex.ts";
import { selectIndicatorIconVars, selectItemIconVars } from '@stylexblocks/ui/slot-recipes/select.stylex.ts'

import { colorPalette } from '@stylexblocks/ui/color-palette.stylex.ts'
import { cursor } from '@stylexblocks/ui/tokens/cursor.stylex.ts'
import { durations } from '@stylexblocks/ui/tokens/durations.stylex.ts'
import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.stylex.ts'
import { fontWeights } from '@stylexblocks/ui/tokens/font-weights.stylex.ts'
import { lineHeights } from '@stylexblocks/ui/tokens/line-heights.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.stylex.ts'
import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'
import { zIndices } from '@stylexblocks/ui/tokens/z-indices.stylex.ts'


const selectRoot = stylex.create({
  base: {
    display: 'flex',
    flexDirection: 'column',
    gap: spacing._1_5,
    width: sizes.full,
  },
})

const selectRootSizes = stylex.create({
  xs: {
    '--select-trigger-height': sizes.controlXs,
    '--select-trigger-padding-x': spacing._2,
  },
  sm: {
    '--select-trigger-height': sizes.controlSm,
    '--select-trigger-padding-x': spacing._2_5,
  },
  md: {
    '--select-trigger-height': sizes.controlMd,
    '--select-trigger-padding-x': spacing._3,
  },
  lg: {
    '--select-trigger-height': sizes.controlLg,
    '--select-trigger-padding-x': spacing._4,
  },
})

const selectTrigger = stylex.create({
  base: {
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'space-between',
    width: sizes.full,
    minHeight: 'var(--select-trigger-height)',
    paddingInline: 'var(--select-trigger-padding-x)',
    userSelect: 'none',
    textAlign: 'start',
    outlineWidth: {
      default: null,
      ':focus-visible': 'var(--focus-ring-width, 0)',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '0px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
    focusRingWidth: 0,
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.5,
    },
    cursor: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 'not-allowed',
    },
    borderColor: {
      default: null,
      ':is([data-invalid], [aria-invalid="true"])': semanticColors.borderError,
      ':hover': {
        default: semanticColors.borderEmphasized,
        ':focus-visible': 'var(--focus-ring-color)',
      },
    },
  },
})

const selectTriggerSizes = stylex.create({
  xs: {
    borderRadius: semanticRadii.control,
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
    gap: spacing._1,
  },
  sm: {
    borderRadius: semanticRadii.control,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    gap: spacing._1,
  },
  md: {
    borderRadius: semanticRadii.control,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    gap: spacing._2,
  },
  lg: {
    borderRadius: semanticRadii.control,
    fontSize: fontSizes.md,
    lineHeight: lineHeights.md,
    paddingBlock: spacing._3,
    gap: spacing._2,
  },
})

const selectTriggerVariants = stylex.create({
  outline: {
    backgroundColor: semanticColors.bg,
    borderWidth: '1px',
    borderStyle: 'solid',
    borderColor: {
      default: semanticColors.border,
      ':is([data-invalid], [aria-invalid="true"])': semanticColors.borderError,
      ':hover': {
        default: semanticColors.borderEmphasized,
        ':focus-visible': 'var(--focus-ring-color)',
      },
    },
  },
  subtle: {
    borderWidth: '1px',
    borderStyle: 'solid',
    borderColor: {
      default: 'transparent',
      ':is([data-invalid], [aria-invalid="true"])': semanticColors.borderError,
      ':hover': {
        default: semanticColors.borderEmphasized,
        ':focus-visible': 'var(--focus-ring-color)',
      },
    },
    backgroundColor: semanticColors.bgMuted,
  },
})

const selectIndicatorGroup = stylex.create({
  base: {
    display: 'flex',
    alignItems: 'center',
    gap: spacing._1,
    position: 'absolute',
    right: 0,
    top: 0,
    bottom: 0,
    paddingInline: 'var(--select-trigger-padding-x)',
    pointerEvents: 'none',
  },
})

const selectIndicator = stylex.create({
  base: {
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    [selectIndicatorIconVars.width]: sizes._3_5,
    [selectIndicatorIconVars.height]: sizes._3_5,
  },
})

const selectIndicatorSizes = stylex.create({
  xs: {
    [selectIndicatorIconVars.width]: sizes._3_5,
    [selectIndicatorIconVars.height]: sizes._3_5,
  },
  sm: {
    [selectIndicatorIconVars.width]: sizes._4,
    [selectIndicatorIconVars.height]: sizes._4,
  },
  md: {
    [selectIndicatorIconVars.width]: sizes._4,
    [selectIndicatorIconVars.height]: sizes._4,
  },
  lg: {
    [selectIndicatorIconVars.width]: sizes._5,
    [selectIndicatorIconVars.height]: sizes._5,
  },
})

const selectIndicatorIcon = stylex.create({
  base: {
    width: selectIndicatorIconVars.width,
    height: selectIndicatorIconVars.height,
  },
})

const selectContent = stylex.create({
  base: {
    outline: 'none',
    color: semanticColors.fg,
    maxHeight: 'var(--available-height)',
    '--menu-z-index': zIndices.layer3,
    zIndex: 'calc(var(--menu-z-index) + var(--layer-index, 0))',
    overflowY: 'auto',
    scrollbarWidth: 'thin',
    transformOrigin: 'var(--transform-origin)',
    animationName: {
      default: null,
      ':is([data-open], [data-state="open"])': 'fade-in, slide-from-top',
      ':is([data-closed], [data-state="closed"])': 'fade-out',
    },
    animationDuration: {
      default: null,
      ':is([data-open], [data-state="open"])': durations.fast,
      ':is([data-closed], [data-state="closed"])': durations.faster,
    },
  },
})

const selectContentSizes = stylex.create({
  xs: {
    padding: spacing._1,
    gap: spacing._1,
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
  },
  sm: {
    padding: spacing._1,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
  },
  md: {
    padding: spacing._1,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
  },
  lg: {
    padding: spacing._1_5,
    fontSize: fontSizes.md,
    lineHeight: lineHeights.md,
  },
})

const selectItem = stylex.create({
  base: {
    position: 'relative',
    userSelect: 'none',
    display: 'flex',
    alignItems: 'center',
    gap: spacing._2,
    cursor: cursor.option,
    justifyContent: 'space-between',
    flex: 1,
    textAlign: 'start',
    borderRadius: semanticRadii.control,
    pointerEvents: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 'none',
    },
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.5,
    },
    [selectItemIconVars.width]: sizes._4,
    [selectItemIconVars.height]: sizes._4,
  },
})

const selectItemSizes = stylex.create({
  xs: {
    paddingBlock: spacing._1,
    paddingInline: spacing._2,
  },
  sm: {
    paddingBlock: spacing._1,
    paddingInline: spacing._1_5,
  },
  md: {
    paddingBlock: spacing._1_5,
    paddingInline: spacing._2,
  },
  lg: {
    paddingBlock: spacing._2,
    paddingInline: spacing._3,
  },
})

const selectItemIcon = stylex.create({
  base: {
    width: selectItemIconVars.width,
    height: selectItemIconVars.height,
  },
})

const selectControl = stylex.create({
  base: {
    position: 'relative',
  },
})

const selectItemText = stylex.create({
  base: {
    flex: 1,
  },
})

const selectItemGroup = stylex.create({
  base: {
    marginTop: {
      default: null,
      ':first-child': 0,
    },
  },
})

const selectItemGroupSizes = stylex.create({
  sm: {
    marginTop: {
      default: spacing._1,
      ':first-child': 0,
    },
  },
  md: {
    marginTop: {
      default: spacing._1_5,
      ':first-child': 0,
    },
  },
  lg: {
    marginTop: {
      default: spacing._2,
      ':first-child': 0,
    },
  },
})

const selectItemGroupLabel = stylex.create({
  base: {
    paddingBlock: spacing._1,
    fontWeight: fontWeights.medium,
  },
})

const selectItemGroupLabelSizes = stylex.create({
  xs: {
    paddingBlock: spacing._1,
    paddingInline: spacing._2,
  },
  sm: {
    paddingBlock: spacing._1,
    paddingInline: spacing._1_5,
  },
  md: {
    paddingBlock: spacing._1_5,
    paddingInline: spacing._2,
  },
  lg: {
    paddingBlock: spacing._2,
    paddingInline: spacing._3,
  },
})

const selectLabel = stylex.create({
  base: {
    fontWeight: fontWeights.medium,
    userSelect: 'none',
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.5,
    },
    cursor: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 'not-allowed',
    },
  },
})

const selectValueText = stylex.create({
  base: {
    lineClamp: 1,
    maxWidth: '80%',
  },
})

const selectItemIndicator = stylex.create({
  base: {},
})

const selectItemIndicatorSizes = stylex.create({
  md: {
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
  },
})

export type SelectVariant = keyof typeof selectTriggerVariants

export type SelectSize = keyof typeof selectRootSizes

const selectRecipe = defineSlotRecipe({
  slots: {
    root: { styles: selectRoot, sizes: selectRootSizes },
    trigger: {
      styles: selectTrigger,
      sizes: selectTriggerSizes,
      variants: selectTriggerVariants,
    },
    indicatorGroup: { styles: selectIndicatorGroup },
    indicator: { styles: selectIndicator, sizes: selectIndicatorSizes },
    content: { styles: selectContent, sizes: selectContentSizes },
    item: { styles: selectItem, sizes: selectItemSizes },
    control: { styles: selectControl },
    itemText: { styles: selectItemText },
    itemGroup: { styles: selectItemGroup, sizes: selectItemGroupSizes },
    itemGroupLabel: { styles: selectItemGroupLabel, sizes: selectItemGroupLabelSizes },
    label: { styles: selectLabel },
    valueText: { styles: selectValueText },
    itemIndicator: { styles: selectItemIndicator, sizes: selectItemIndicatorSizes },
  },
  defaultVariants: { size: "md", variant: "outline" },
});

// chrome the generated recipe leaves to the composition layer: unstyled
// trigger button, popup panel surface, and item hover feedback
const chrome = stylex.create({
  btnReset: {
    appearance: "none",
    backgroundColor: "transparent",
    borderWidth: 0,
    borderStyle: "none",
    padding: 0,
    margin: 0,
    fontFamily: "inherit",
    fontSize: "inherit",
    color: "inherit",
    cursor: "pointer",
    textAlign: "inherit",
  },
  anchor: { position: "relative" },
  indicatorGroup: {
    position: "absolute",
    insetInlineEnd: 0,
    top: 0,
    bottom: 0,
    pointerEvents: "none",
  },
  panel: {
    display: "flex",
    flexDirection: "column",
    backgroundColor: semanticColors.bgPanel,
    borderRadius: semanticRadii.panel,
    boxShadow: semanticShadows.overlay,
    minWidth: "var(--anchor-width)",
  },
  itemHover: { ":hover": { backgroundColor: semanticColors.bgMuted } },
});

function ChevronDownIcon(props: React.ComponentProps<"svg">) {
  return (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" {...props}>
      <path d="m4 6 4 4 4-4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
    </svg>
  );
}

function CheckIcon(props: React.ComponentProps<"svg">) {
  return (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" {...props}>
      <path d="m3.5 8.5 3 3 6-7" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
    </svg>
  );
}

const { withProvider, withContext } = createSlotRecipeContext(selectRecipe);

type SelectVariants = SlotRecipeVariants<typeof selectRecipe>;
export type SelectVariantProps = Partial<SelectVariants>;

function SelectRootNode(
  props: SelectRootProps<unknown> & { className?: string; style?: React.CSSProperties },
) {
  const { className, style, children, ...rest } = props;
  return (
    <div className={className} style={style}>
      <BaseSelect.Root {...rest}>{children}</BaseSelect.Root>
    </div>
  );
}

const StyledRoot = withProvider(SelectRootNode, "root", "SelectRoot");

/**
 * Select — Base UI's select parts styled with the StyleX slot recipe.
 * `<Select.Root variant size>` renders the recipe's root layout element
 * around Base UI's context-only Root; every part inherits the variants
 * through context. Popup portals through `Select.Positioner`, and Icon /
 * ItemIndicator ship default chevron / check icons.
 */
function Root<Value, Multiple extends boolean | undefined = false>(
  props: SelectRootProps<Value, Multiple> &
    Partial<SelectVariants> &
    StyleOverrideProps & { className?: string },
) {
  return <StyledRoot {...(props as React.ComponentProps<typeof StyledRoot>)} />;
}
Root.displayName = "SelectRoot";

const StyledIcon = withContext(BaseSelect.Icon, "indicator", "SelectIcon");

function Icon(
  props: Omit<React.ComponentProps<typeof BaseSelect.Icon>, "style"> & StyleOverrideProps,
) {
  const { children, ...rest } = props;
  return (
    <StyledIcon {...rest}>
      {children ?? <ChevronDownIcon {...stylex.props(selectIndicatorIcon.base)} />}
    </StyledIcon>
  );
}
Icon.displayName = "SelectIcon";

const StyledItemIndicator = withContext(
  BaseSelect.ItemIndicator,
  (v) => [
    ...resolveSlotStyles(selectRecipe.slots.itemIndicator, v),
    selectItemIndicatorSizes.md,
  ],
  "SelectItemIndicator",
);

function ItemIndicator(
  props: Omit<React.ComponentProps<typeof BaseSelect.ItemIndicator>, "style"> & StyleOverrideProps,
) {
  const { children, ...rest } = props;
  return (
    <StyledItemIndicator {...rest}>
      {children ?? <CheckIcon {...stylex.props(selectItemIcon.base)} />}
    </StyledItemIndicator>
  );
}
ItemIndicator.displayName = "SelectItemIndicator";

function Positioner({
  children,
  ...rest
}: React.ComponentProps<typeof BaseSelect.Positioner>) {
  return (
    <BaseSelect.Portal>
      <BaseSelect.Positioner sideOffset={4} alignItemWithTrigger={false} {...rest}>
        {children}
      </BaseSelect.Positioner>
    </BaseSelect.Portal>
  );
}

export const Select = {
  Root,
  Label: withContext("span", "label", "SelectLabel"),
  Control: withContext(
    "div",
    (v) => [...resolveSlotStyles(selectRecipe.slots.control, v), chrome.anchor],
    "SelectControl",
  ),
  Trigger: withContext(
    BaseSelect.Trigger,
    (v) => [chrome.btnReset, ...resolveSlotStyles(selectRecipe.slots.trigger, v)],
    "SelectTrigger",
  ),
  Value: withContext(BaseSelect.Value, "valueText", "SelectValue"),
  IndicatorGroup: withContext(
    "div",
    (v) => [...resolveSlotStyles(selectRecipe.slots.indicatorGroup, v), chrome.indicatorGroup],
    "SelectIndicatorGroup",
  ),
  Icon,
  Positioner,
  Popup: withContext(
    BaseSelect.Popup,
    (v) => [...resolveSlotStyles(selectRecipe.slots.content, v), chrome.panel],
    "SelectPopup",
  ),
  Item: withContext(
    BaseSelect.Item,
    (v) => [...resolveSlotStyles(selectRecipe.slots.item, v), chrome.itemHover],
    "SelectItem",
  ),
  ItemText: withContext(BaseSelect.ItemText, "itemText", "SelectItemText"),
  ItemIndicator,
  Group: withContext(BaseSelect.Group, "itemGroup", "SelectGroup"),
  GroupLabel: withContext(BaseSelect.GroupLabel, "itemGroupLabel", "SelectGroupLabel"),
};
```
