---
title: "Select · Ark UI — StyleX Blocks"
description: "Custom listbox-style select with trigger, indicator, and item slots in outline and subtle styles."
url: "https://stylexblocks.com/components/ark-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: Ark UI
- Also available for: [Base UI](https://stylexblocks.com/components/base-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/ark-ui/language-select.md)
- HTML page: https://stylexblocks.com/components/ark-ui/select/

## Install

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

```sh
npx stylexblocks init
```

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/ark-ui/select.json

## Usage

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

const frameworks = createListCollection({
  items: ["Astro", "Next.js", "Remix", "Vite"],
});

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

## Source

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

```tsx
import * as stylex from "@stylexjs/stylex";
import { Select as ArkSelect, type CollectionItem } from "@ark-ui/react/select";
import { Portal } from "@ark-ui/react/portal";
import { createSlotRecipeContext } from "#lib/ark-ui/create-slot-recipe-context.tsx";
import {
  defineSlotRecipe,
  resolveSlotStyles,
  type SlotRecipeVariants,
  type StyleOverrideProps,
  type WithStyleOverrides,
} 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(--reference-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>;

const StyledRoot = withProvider(ArkSelect.Root, "root", "SelectRoot");

function Root<T extends CollectionItem>(
  props: WithStyleOverrides<ArkSelect.RootProps<T>> & Partial<SelectVariants>,
) {
  return <StyledRoot {...(props as React.ComponentProps<typeof StyledRoot>)} />;
}
Root.displayName = "SelectRoot";

const StyledIndicator = withContext(ArkSelect.Indicator, "indicator", "SelectIndicator");

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

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

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

function Positioner({ children, ...rest }: ArkSelect.PositionerProps) {
  return (
    <Portal>
      <ArkSelect.Positioner {...rest}>{children}</ArkSelect.Positioner>
    </Portal>
  );
}

/**
 * Select — Ark UI's select machine parts styled with the StyleX slot recipe.
 * `<Select.Root variant size>` resolves the recipe once; every part inherits
 * it through context. Content portals through `Select.Positioner`, and
 * Indicator / ItemIndicator ship default chevron / check icons.
 */
export const Select = {
  Root,
  Label: withContext(ArkSelect.Label, "label", "SelectLabel"),
  Control: withContext(
    ArkSelect.Control,
    (v) => [...resolveSlotStyles(selectRecipe.slots.control, v), chrome.anchor],
    "SelectControl",
  ),
  Trigger: withContext(
    ArkSelect.Trigger,
    (v) => [chrome.btnReset, ...resolveSlotStyles(selectRecipe.slots.trigger, v)],
    "SelectTrigger",
  ),
  ValueText: withContext(ArkSelect.ValueText, "valueText", "SelectValueText"),
  IndicatorGroup: withContext(
    "div",
    (v) => [...resolveSlotStyles(selectRecipe.slots.indicatorGroup, v), chrome.indicatorGroup],
    "SelectIndicatorGroup",
  ),
  Indicator,
  Positioner,
  Content: withContext(
    ArkSelect.Content,
    (v) => [...resolveSlotStyles(selectRecipe.slots.content, v), chrome.panel],
    "SelectContent",
  ),
  Item: withContext(
    ArkSelect.Item,
    (v) => [...resolveSlotStyles(selectRecipe.slots.item, v), chrome.itemHover],
    "SelectItem",
  ),
  ItemText: withContext(ArkSelect.ItemText, "itemText", "SelectItemText"),
  ItemIndicator,
  ItemGroup: withContext(ArkSelect.ItemGroup, "itemGroup", "SelectItemGroup"),
  ItemGroupLabel: withContext(
    ArkSelect.ItemGroupLabel,
    "itemGroupLabel",
    "SelectItemGroupLabel",
  ),
  HiddenSelect: ArkSelect.HiddenSelect,
  Context: ArkSelect.Context,
};

export { createListCollection } from "@ark-ui/react/select";
```
