← Home v1.3.0

Docs / Components / Select & dropdown

Select & dropdown

Style native selects and textareas, or turn any <select> into a searchable dropdown with sub-labels and option groups. About 3 KB of JavaScript, keyboard accessible, no dependencies.

Select & textarea

Add data-ace-select and ace-select.js to a normal <select> and it gets the AceCSS dropdown: a rounded panel, a soft brand tint on the highlighted item, and the current value in bold brand colour. The real <select> stays underneath, so name, required, change events and form submission still work. Arrow keys, Home/End, Enter, Escape and type-ahead all work. Without the script, you get a styled native select. The textarea starts at 80px tall and can be resized vertically.

Choose a pick-up location.

<script src="ace-select.js" defer></script>

<label class="ace-label" for="cat">Category</label>
<select id="cat" name="category" class="ace-select" data-ace-select>
  <option value="">Choose a category…</option>   <!-- empty value = placeholder -->
  <option value="suv">SUV</option>
  <optgroup label="Commercial">
    <option value="van">Van</option>
  </optgroup>
</select>

<!-- Long lists: data-search filters as you type; data-sublabel adds a second line -->
<select id="car" name="vehicle" class="ace-select" data-ace-select data-search>
  <option value="">Search cars…</option>
  <option value="1" data-sublabel="01-234-AB · Diesel · Auto">Volkswagen Golf 8</option>
</select>

// Changed the options or value from code? Re-paint the control:
selectEl.value = 'suv'; selectEl.aceSelect.refresh()
// Markup added after page load (Vue / React / HTMX):
AceSelect.init(container)

<textarea id="notes" class="ace-textarea" rows="4"></textarea>

Use it

One stylesheet and one script from the CDN, pinned to v1.3.0:

<link rel="stylesheet" href="https://acecss.dev/v1.3.0/ace.min.css"
      integrity="sha384-zHAwOqjifsc0D+iUvzD1a4W0R2g0BOK9AqQJZGakUEp/Tm5IUcP07R9xkY0q/stj" crossorigin="anonymous">
<script src="https://acecss.dev/v1.3.0/ace-select.min.js" defer
        integrity="sha384-9tcWJ02N3Y9Q7gIqgr3CKRk+yH/lWuBSTDmUS6aAQLjUsSJkDcJrkErHCtfYOTkX" crossorigin="anonymous"></script>

Or from npm:

npm i @acecss/core

import '@acecss/core'
import '@acecss/core/select'

Bundlers, Tailwind, every script in one file and self-hosting: Install.

More components