---
layout: layouts/component.njk
title: Select
description: Displays a list of options for the user to pick from—triggered by a button.
toc:
- label: Usage
id: usage
children:
- label: Default
id: usage-default
- label: Jinja or Nunjucks
id: usage-jinja
- label: Examples
id: examples
children:
- label: Scrollable
id: example-scrollable
- label: Disabled
id: example-disabled
- label: With icon
id: example-with-icon
---
{% from "macros/code_preview.njk" import code_preview %}
{% from "macros/code_block.njk" import code_block %}
{% from "components/select.njk" import select %}
{% set code_native %}
Apple
Banana
Blueberry
Grapes
Pineapple
{% endset %}
{{ code_preview("select-native", code_native) }}
{% set code_alpine %}
{% call select(
name="select-js",
trigger_attrs={"class": "w-[180px]"},
register_on=["alpine:init", "htmx:afterSwap"]
) %}
Fruits
Apple
Banana
Blueberry
Grapes
Pineapple
{% endcall %}
{% endset %}
{{ code_preview("select", code_alpine | prettyHtml) }}
If you use a <select> element, just add the select class to it or have a parent with the form class (read more about form ).
{{ code_block(code_native) }}
If you need to do more than what <select> allows (e.g. HTML options), you can use the code below which uses the Popover component. Make sure to include the hidden input with the name you want to use for that field.
HTML
{% set code_html %}
{% call select(
name="select-js",
trigger_attrs={"class": "w-[180px]"},
register_on=["alpine:init", "htmx:afterSwap"],
include_script=false
) %}
Fruits
Apple
Banana
Blueberry
Grapes
Pineapple
{% endcall %}
{% endset %}
{{ code_block(code_html | prettyHtml) }}
Javascript
{% set code_script %}{% include "components/select-script.njk" %}{% endset %}
{{ code_block(code_script | prettyHtml, "html") }}
If you use Jinja (or Nunjucks), you can use the select() macro directly.
{% set raw_code %}{% raw %}{% call select(name="select-js") %}
Fruits
Apple
Banana
Blueberry
Grapes
Pineapple
{% endcall %}{% endraw %}{% endset %}
{{ code_block(raw_code, "jinja") }}
{% set code %}
{% call select(
listbox_attrs={"class": "scrollbar overflow-y-auto max-h-64"},
register_on=["alpine:init", "htmx:afterSwap"]
) %}
{% for i in range(0, 99) %}
Item {{ i }}
{% endfor %}
{% endcall %}
{% endset %}
{{ code_preview("select-scrollable", code | prettyHtml) }}
{% set code %}
{% call select(
trigger_attrs={"disabled": "disabled"},
register_on=["alpine:init", "htmx:afterSwap"]
) %}
Disabled
{% endcall %}
{% endset %}
{{ code_preview("select-disabled", code | prettyHtml) }}
{% set code %}
{% call select(
trigger_attrs={'class': 'w-[180px]'},
register_on=["alpine:init", "htmx:afterSwap"]
) %}
{% lucide "chart-bar", {"class": "text-muted-foreground"} %}
Bar
{% lucide "chart-line", {"class": "text-muted-foreground"} %}
Line
{% lucide "chart-pie", {"class": "text-muted-foreground"} %}
Pie
{% endcall %}
{% endset %}
{{ code_preview("select-scrollable", code | prettyHtml) }}