Select

Select creates better-styled select boxes that uses a browser’s native <select> element.


An easy way to make select boxes

You just need a name, a label, and a list of items.

Svelte
<Select
name="fav-fruit"
label="Pick your favourite fruit:"
items={['apple', 'banana', 'carrot']}
/>
It doesn’t get any easier than this! πŸ˜‰

Add custom labels easily

If you want to use custom labels, just pass an array of objects into items.

Svelte
<Select
name="fav-fruit"
label="Pick your favourite fruit:"
items={[
{ value: 'apple', label: '🍎 Apple' },
{ value: 'banana', label: '🍌 Banana' },
{ value: 'carrot', label: 'πŸ₯• Carrot' }
]}
/>

Create native multi-selects

Add multiple to get a native multi-select element. These can be styled with CSS to a certain extent. (Just not in Safari).

Svelte
<Select
multiple
name="fav-fruit"
label="Pick your favourite fruits:"
items={['apple', 'banana', 'carrot', 'pear']}
/>

Preselect any item

Just set selected to the value of the item you want to preselect. This works for both single and multi selects!

Svelte
<!-- Single Select -->
<Select
...
items={[
{ value: 'apple' },
{ value: 'banana', selected: true },
{ value: 'carrot' },
{ value: 'pear' },
]}
/>
Svelte
<!-- Multi Select -->
<Select
...
multiple
items={[
{ value: 'apple' },
{ value: 'banana', selected: true },
{ value: 'carrot', selected: true },
{ value: 'pear' },
]}
/>
Single Select
Multi Select

Readonly works too

Like all Checkboxes and Radios, we’ve added a readonly feature to Select that lets you disable and values to the server without allowing users to change them.

Svelte
<!-- Single Select -->
<Select
...
items={[
{ value: 'apple' },
{ value: 'banana', selected: true },
{ value: 'carrot' },
]}
readonly
/>
Svelte
<!-- Multi Select -->
<Select
...
multiple
items={[
{ value: 'apple' },
{ value: 'banana', selected: true },
{ value: 'carrot', selected: true },
{ value: 'pear' },
]}
readonly
/>
Single Select
Multi Select
Readonly doesn’t exist as a HTML 5 property. We made it possible by as many hidden inputs as necessary.

Easy styling

Native <select> and <option> elements are quite difficlt to style by default. We made it easier for you with a couple of CSS variables.

That said, styling options are still quite limited since not all browsers respect styles given to <option>.

This is editable. Give it a try

Select
Multi Select