---
title: Native Select for Astro
description: "Styled native HTML select controls for Astro forms."
seo:
    title: Native Select for Astro | Shadcn & Tailwind CSS
related:
    - /components/select
    - /components/combobox
sidebar:
    label: "Native Select"
---

```astro
---
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select"
---

<NativeSelect class="w-full max-w-xs">
  <NativeSelectOption value="">Select status</NativeSelectOption>
  <NativeSelectOption value="todo">Todo</NativeSelectOption>
  <NativeSelectOption value="in-progress">In Progress</NativeSelectOption>
  <NativeSelectOption value="done">Done</NativeSelectOption>
  <NativeSelectOption value="cancelled">Cancelled</NativeSelectOption>
</NativeSelect>
```

## Installation

### Command

```sh
bunx --bun shadcn@latest add @gnostic/native-select
```

### Manual

Complete the [Installation guide](/docs/installation) first. Then copy the component files below.

No extra packages are required.

#### src/components/ui/native-select/index.ts

```ts
export { default as NativeSelect } from "./native-select.astro"
export { default as NativeSelectOption } from "./native-select-option.astro"
export { default as NativeSelectOptGroup } from "./native-select-optgroup.astro"
```

#### src/components/ui/native-select/native-select-optgroup.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"optgroup">

const { class: className, ...props } = Astro.props

// Canvas and CanvasText are inherited by the OS, otherwise optgroup would often not get applied by the browser.
---

<optgroup
  data-slot="native-select-optgroup"
  class={cn("bg-[Canvas] text-[CanvasText]", className)}
  {...props}
>
  <slot />
</optgroup>
```

#### src/components/ui/native-select/native-select-option.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"option">

const { class: className, ...props } = Astro.props

// Canvas and CanvasText are inherited by the OS, otherwise option would often not get applied by the browser.
---

<option
  data-slot="native-select-option"
  class={cn("bg-[Canvas] text-[CanvasText]", className)}
  {...props}
>
  <slot />
</option>
```

#### src/components/ui/native-select/native-select.astro

```astro
---
import type { HTMLAttributes } from "astro/types"
import ChevronDownIcon from "@lucide/astro/icons/chevron-down"

import { cn } from "cn"

type Props = Omit<HTMLAttributes<"select">, "size"> & {
  size?: "sm" | "default"
}

const { class: className, size = "default", ...props } = Astro.props
---

<div
  class={cn(
    "group/native-select relative w-fit has-[select:disabled]:opacity-50",
    className,
  )}
  data-slot="native-select-wrapper"
  data-size={size}
>
  <select
    data-slot="native-select"
    data-size={size}
    class="border-input placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 dark:hover:bg-input/50 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 h-9 w-full min-w-0 appearance-none rounded-md border bg-transparent py-1 pr-8 pl-2.5 text-sm shadow-xs transition-[color,box-shadow] outline-none select-none focus-visible:ring-3 disabled:pointer-events-none disabled:cursor-not-allowed aria-invalid:ring-3 data-[size=sm]:h-8"
    {...props}
  >
    <slot />
  </select>
  <ChevronDownIcon
    class="text-muted-foreground pointer-events-none absolute top-1/2 right-2.5 size-4 -translate-y-1/2 select-none"
    aria-hidden="true"
    data-slot="native-select-icon"
  />
</div>
```

Component classes use the preset configured during project setup. Select the same preset in the docs before copying Manual source. To change installed component classes, edit or reinstall their source. See [Theming](/docs/theming) for details.


## Usage

```ts
import {
    NativeSelect,
    NativeSelectOptGroup,
    NativeSelectOption,
} from "@/components/ui/native-select"
```

```astro
<NativeSelect>
  <NativeSelectOption value="">Select a fruit</NativeSelectOption>
  <NativeSelectOption value="apple">Apple</NativeSelectOption>
  <NativeSelectOption value="banana">Banana</NativeSelectOption>
  <NativeSelectOption value="blueberry">Blueberry</NativeSelectOption>
  <NativeSelectOption value="grapes" disabled> Grapes </NativeSelectOption>
  <NativeSelectOption value="pineapple">Pineapple</NativeSelectOption>
</NativeSelect>
```

## Composition

Use options directly under `NativeSelect` for a simple list:

```text
NativeSelect
├── NativeSelectOption
├── NativeSelectOption
├── NativeSelectOption
└── NativeSelectOption
```

Use `NativeSelectOptGroup` to organize options into categories:

```text
NativeSelect
├── NativeSelectOptGroup
│   ├── NativeSelectOption
│   └── NativeSelectOption
└── NativeSelectOptGroup
    ├── NativeSelectOption
    └── NativeSelectOption
```

## Examples

### With Groups

Organize options using `NativeSelectOptGroup` for better categorization.

```astro
---
import {
  NativeSelect,
  NativeSelectOptGroup,
  NativeSelectOption,
} from "@/components/ui/native-select"
---

<NativeSelect class="w-full max-w-xs">
  <NativeSelectOption value="">Select department</NativeSelectOption>
  <NativeSelectOptGroup label="Engineering">
    <NativeSelectOption value="frontend">Frontend</NativeSelectOption>
    <NativeSelectOption value="backend">Backend</NativeSelectOption>
    <NativeSelectOption value="devops">DevOps</NativeSelectOption>
  </NativeSelectOptGroup>
  <NativeSelectOptGroup label="Sales">
    <NativeSelectOption value="sales-rep">Sales Rep</NativeSelectOption>
    <NativeSelectOption value="account-manager">
      Account Manager
    </NativeSelectOption>
    <NativeSelectOption value="sales-director">
      Sales Director
    </NativeSelectOption>
  </NativeSelectOptGroup>
  <NativeSelectOptGroup label="Operations">
    <NativeSelectOption value="support">Customer Support</NativeSelectOption>
    <NativeSelectOption value="product-manager">
      Product Manager
    </NativeSelectOption>
    <NativeSelectOption value="ops-manager">
      Operations Manager
    </NativeSelectOption>
  </NativeSelectOptGroup>
</NativeSelect>
```

### Disabled State

Disable individual options or the entire select component.

```astro
---
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select"
---

<NativeSelect disabled class="w-full max-w-xs">
  <NativeSelectOption value="">Select priority</NativeSelectOption>
  <NativeSelectOption value="low">Low</NativeSelectOption>
  <NativeSelectOption value="medium">Medium</NativeSelectOption>
  <NativeSelectOption value="high">High</NativeSelectOption>
  <NativeSelectOption value="critical">Critical</NativeSelectOption>
</NativeSelect>
```

### Invalid State

Show validation errors with the `aria-invalid` attribute and error styling.

```astro
---
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select"
---

<NativeSelect aria-invalid="true" class="w-full max-w-xs">
  <NativeSelectOption value="">Select role</NativeSelectOption>
  <NativeSelectOption value="admin">Admin</NativeSelectOption>
  <NativeSelectOption value="editor">Editor</NativeSelectOption>
  <NativeSelectOption value="viewer">Viewer</NativeSelectOption>
  <NativeSelectOption value="guest">Guest</NativeSelectOption>
</NativeSelect>
```

## Accessibility

- The component maintains all native HTML select accessibility features.
- Screen readers can navigate through options using arrow keys.
- The chevron icon is marked as `aria-hidden="true"` to avoid duplication.
- Use `aria-label` or `aria-labelledby` for additional context when needed.

```astro
<NativeSelect aria-label="Choose your preferred language">
  <NativeSelectOption value="en">English</NativeSelectOption>
  <NativeSelectOption value="es">Spanish</NativeSelectOption>
  <NativeSelectOption value="fr">French</NativeSelectOption>
</NativeSelect>
```

## API Reference

Read the [installed source](/r/native-select.json) for the complete prop types.

## When to use Native Select

Use NativeSelect when a standard browser selection control fits the task. Put native option and optgroup elements inside it, then set name, ID, and a linked label.

## Keyboard and behavior

The browser owns keyboard navigation, touch pickers, form submission, and disabled behavior. These details can differ across platforms. Keep option labels clear without depending on custom icons or markup.

## Theme and layout

The size prop changes the component’s visual size. Native option popup colors and spacing are not fully controlled by the page theme. Test the closed control and the open picker on target platforms.
