Skip to main content
twblazor
Home
  • Get started
  • Tailwind with Blazor
  • Why twblazor?
  • Theme
  • Class Merge
    • Configuring localization
    • RTL Provider
  • Breadcrumb
  • Card
  • Carousel
  • Collapse
  • Context Menu
  • Drawer
  • Footer
  • Menu
  • Navbar
  • On This Page
  • Separator
  • Sidebar
  • Stepper
  • Tabs
  • Tree List
  • Container
  • Flex
  • Grid
  • Text
  • Link
  • Button
  • Form
    • AutocompleteNew
    • Checkbox
    • Color Picker
    • Date Picker
    • Date Range Picker
    • Datetime Picker
    • Datetime Range Picker
    • File Upload
    • Input GroupNew
    • NumericNew
    • Masked InputNew
    • Radio Button
    • Range SliderNew
    • RatingNew
    • Select
    • Slider
    • Switch
    • Tag InputNew
    • Text EditorNew
    • Textfield
    • Time Picker
    • Time Range Picker
  • Toggle
  • Toggle Group
  • Alert
  • Avatar
  • Badge
  • Chip
  • Empty
  • Icon
  • Popover
  • Progress
  • Skeleton
  • Spinner
  • Tooltip
  • Data Table
  • SpreadsheetNew
  • Column Filter Editor
  • Pagination
  • Pick List
  • Barcode
  • QR Code
  • Calendar
  • Table
  • Attachment
  • Overview
    • Bar
    • Bullet
    • Column
    • Dot Plot
    • Dumbbell
    • Icon
    • Lollipop
    • Radial Bar
    • Range
    • Word Cloud
    • Area
    • Bump
    • Bump Area
    • Candlestick
    • Gantt
    • Horizon
    • Line
    • Slope
    • Small Multiples
    • Stream Graph
    • Funnel
    • Gauge
    • Marimekko
    • Nightingale
    • Pie
    • Treemap
    • Waffle
    • Waterfall
    • Circular Treemap
    • Convex Treemap
    • Dendrogram
    • Sunburst
    • Barcode
    • Beeswarm
    • Box Plot
    • Density Plot
    • Histogram
    • Radial Histogram
    • Ridgeline
    • Strip Plot
    • Violin Plot
    • Categorical Scatter
    • Contour
    • Hexagonal Binning
    • Quadrant
    • Scatter
    • Heatmap
    • Matrix
    • Parallel Coordinates
    • Radar
    • Arc Diagram
    • Chord Diagram
    • Flowchart
    • Network Diagram
    • Sankey
    • Euler Diagram
    • Venn Diagram
  • Bubble
  • Marker
  • Message
  • Dialog Service
  • Toast Service
API DocumentationAI Agents & Skills
Home Get Started

Forms

TwSelect

TwSelect is a Blazor select component for complex objects and numbers. Bind SelectedValue, or SelectedValues with Multiple, and set Placeholder and Required.

Last updated 19 October 2026

Basic select

Bind SelectedValue and use Variant to switch between default, filled and outlined styles.
RAZOR
<div class="w-full flex flex-row">
    <div class="flex-col lg:flex-row flex grow gap-4 mb-4">
        <TwSelect T="string"
                  Label="Country"
                  Values="@_countries"
                  Variant="InputVariant.Default"
                  @bind-SelectedValue="@selectedCountry"
                  Placeholder="Select a country..."
                  AriaLabel="Country select"
                  RootClass="flex-1"/>

        <TwSelect T="string"
                  Label="Country"
                  Values="@_countries"
                  Variant="InputVariant.Filled"
                  @bind-SelectedValue="@selectedCountry"
                  Placeholder="Select a city..."
                  AriaLabel="City select"
                  RootClass="flex-1" />

        <TwSelect T="string"
                  Label="Country"
                  Values="@_countries"
                  Variant="InputVariant.Outlined"
                  @bind-SelectedValue="@selectedCountry"
                  Placeholder="Select a city..."
                  AriaLabel="City select"
                  RootClass="flex-1" />
    </div>
</div>

@if (!string.IsNullOrEmpty(selectedCountry))
{
    <p class="text-sm text-gray-600 dark:text-gray-400 pb-4">Selected Country: <strong>@selectedCountry</strong></p>
}
CSHARP
@code {
    private string selectedCountry = string.Empty;
    private readonly string[] _countries = ["USA", "Canada", "UK", "Germany", "France", "Japan", "Australia"];
}

Desktop and mobile behavior

On desktop, a single select opens an accessible listbox popover that you can drive with the arrow keys, Home, End, type-ahead and Enter. On iOS and Android it renders the browser's native <select> instead, so people get the platform's own picker. Set PreferNativePicker to true or false to override the detection.

Select with complex objects

Use PropertyName to display a specific property when binding to a list of complex objects.
RAZOR
<TwSelect T="Person"
          Label="Select Person"
          Values="@_people"
          @bind-SelectedValue="@selectedPerson"
          PropertyName="Name"
          Placeholder="Choose a person..."
          AriaLabel="Person select" />

@if (selectedPerson != null)
{
    <div class="mt-3 p-3 rounded border border-gray-200 dark:border-gray-600">
        <p class="text-sm text-gray-600 dark:text-gray-400">Name: <strong>@selectedPerson.Name</strong></p>
        <p class="text-sm text-gray-600 dark:text-gray-400">City: <strong>@selectedPerson.City</strong></p>
        <p class="text-sm text-gray-600 dark:text-gray-400">Age: <strong>@selectedPerson.Age</strong></p>
    </div>
}
CSHARP
@code {
    private Person? selectedPerson = null;
    
    private readonly Person[] _people =
    [
        new Person { Id = 1, Name = "John Doe", City = "London", Age = 30 },
        new Person { Id = 2, Name = "Jane Smith", City = "Toronto", Age = 25 },
        new Person { Id = 3, Name = "Bob Johnson", City = "Sydney", Age = 35 },
        new Person { Id = 4, Name = "Alice Williams", City = "Dublin", Age = 28 }
    ];
    
    private sealed class Person
    {
        public int Id { get; set; }
        public string Name { get; set; } = string.Empty;
        public string City { get; set; } = string.Empty;
        public int Age { get; set; }
    }
}

Clearable select

Set Clearable for a button at the end of the field that clears the selection: SelectedValue goes back to its default, such as null, and a Multiple select's SelectedValues becomes empty. OnClear runs afterwards. The button is shown in every mode, the native picker on iOS and Android included, and is disabled while nothing is selected. It is left out of the Tab order, so from the keyboard press Delete or Backspace on the field instead. A Required single select always keeps a value, so it shows no clear button.
C#SQL
RAZOR
<div class="flex flex-col lg:flex-row gap-4">
    <TwSelect T="string"
              Label="Country"
              Values="@_countries"
              Clearable
              @bind-SelectedValue="@clearableCountry"
              RootClass="flex-1" />

    <TwSelect T="string"
              Label="Skills"
              Values="@_skills"
              Multiple
              Clearable
              @bind-SelectedValues="@clearableSkills"
              RootClass="flex-1" />
</div>
CSHARP
@code {
    private string? clearableCountry = "Canada";
    private IEnumerable<string> clearableSkills = ["C#", "SQL"];
}

Item templates

Add an ItemTemplate to draw each option in the list your own way. The closed field, and the chips of a Multiple select, still show the option's display text from PropertyName.

The native picker falls back to the display text

On iOS and Android the select uses the browser's native picker (see Desktop and mobile behavior), and a native <option> can only hold text. There the template is not used: each option falls back to its display text from PropertyName, or ToString() when no property is named. The same happens when PreferNativePicker is true. Keep the display text meaningful on its own, so the select still reads well on a phone.
RAZOR
<TwSelect T="Person"
          Label="Select Person"
          Values="@_people"
          PropertyName="Name"
          @bind-SelectedValue="@templatedPerson">
    <ItemTemplate>
        <span class="flex flex-col">
            <span>@context.Name</span>
            <span class="text-xs text-gray-600 dark:text-gray-400">@context.City, age @context.Age</span>
        </span>
    </ItemTemplate>
</TwSelect>
CSHARP
@code {
    private Person? templatedPerson;
}

Required select

Set the Required property to mark the select as a required field. A select that is not required lists its Placeholder as the first option, and choosing it clears the selection, setting SelectedValue back to its default, such as null. A required select leaves the placeholder out, so a value always stays chosen.
RAZOR
<TwSelect T="string"
          Label="Favourite Color"
          Values="@_colors"
          @bind-SelectedValue="@selectedColor"
          Required
          AriaLabel="Color select" />

@if (!string.IsNullOrEmpty(selectedColor))
{
    <p class="mt-3 text-sm text-gray-600 dark:text-gray-400">Selected Color: <strong>@selectedColor</strong></p>
}

Disabled and readonly select

Use the Disabled and ReadOnly properties to restrict interaction with the select.
RAZOR
<div class="flex flex-col gap-3">
    <TwSelect T="string"
              Label="Disabled Select"
              Values="@_countries"
              @bind-SelectedValue="@selectedCountry"
              Placeholder="Cannot select..."
              Disabled
              AriaLabel="Disabled select" />

    <TwSelect T="string"
              Label="Readonly Select"
              Values="@_countries"
              SelectedValue="@_readonlyValue"
              Placeholder="Cannot change..."
              ReadOnly
              AriaLabel="Readonly select" />
</div>

Select with numbers

TwSelect works with numeric types as well as strings and objects.
RAZOR
<TwSelect T="int"
          Label="Quantity"
          Values="@_quantities"
          @bind-SelectedValue="@selectedQuantity"
          Placeholder="Select quantity..."
          AriaLabel="Quantity select" />

@if (selectedQuantity > 0)
{
    <p class="mt-3 text-sm text-gray-600 dark:text-gray-400">Selected Quantity: <strong>@selectedQuantity</strong></p>
    <p class="text-sm text-gray-600 dark:text-gray-400">Total Price: <strong>$@(selectedQuantity * 10)</strong></p>
}

Dense select

Set Dense for a more compact select with a smaller height and text size, matching the other dense inputs. Multi-select is not affected, as its height follows its selected chips.
RAZOR
<TwSelect T="string"
          Label="Country"
          Values="@_countries"
          Dense
          @bind-SelectedValue="@denseCountry"
          AriaLabel="Dense country select" />
CSHARP
@code {
    private string denseCountry = string.Empty;
}

Multi-select

Set Multiple and bind SelectedValues (instead of SelectedValue) to let more than one option be selected at once. On desktop it opens the same listbox as a single select, with a tick beside each chosen option, and picking an option leaves the list open. It falls back to a native <select multiple> on iOS and Android, so mobile/touch browsers still get their own platform multi-select UI rather than a bespoke one.
C#

Selected Skills: C#

RAZOR
<TwSelect T="string"
          Label="Skills"
          Values="@_skills"
          Multiple
          @bind-SelectedValues="@selectedSkills"
          AriaLabel="Skills select" />

@if (selectedSkills.Any())
{
    <p class="mt-3 text-sm text-gray-600 dark:text-gray-400">Selected Skills: <strong>@string.Join(", ", selectedSkills)</strong></p>
}

Keyboard navigation

The list opens below the field and focus moves into it. On a phone or tablet the browser's own picker is used.
Key What it does
Enter or Space or Arrow Down or Arrow Up Opens the list.
Arrow Up or Arrow Down Moves to the previous or next option.
Home or End Moves to the first or last option.
A to Z Moves to the next option starting with the typed letters.
Enter or Space Selects the focused option and closes the list. In a multiple select, adds or removes the option and keeps the list open.
Escape or Tab Closes the list without changing the value and returns focus to the field.
Delete or Backspace On a clearable select with the list closed: clears the selection.
Enter or Space On a selected item's remove button in a multiple select: removes that item and returns focus to the field.

Theme configuration

Styling is controlled by TwBlazorTheme.Components (a TwInputTheme), configured via the AddTwBlazor() options callback described on the Get Started page. Every property is a set of Tailwind classes, so changes are picked up by your own Tailwind build.

Inherited from TwTextfield - this component reuses that theme rather than defining its own.

Property Type Controls
DefaultInputVariant InputVariant
TextfieldBase string
SelectBase string
Size string
DenseSize string
MultilineSize string
MultilineDenseSize string
MultilineResize string
MultilineAutoGrow string
FieldWrapper string
FieldStartContent string
FieldEndContent string
ClearablePadding string
ClearButton string
ClearButtonIcon string
SelectOption string
SelectNativeBackground string
SelectDefaultPadding string
SelectReadOnlyBackground string
SelectMultiTriggerLayout string
SelectNativeMultiOverlay string
SelectMultiOpenButton string
SelectPanelPosition string
SelectPanelSurface string
SelectPanelItemText string
SelectCustomTrigger string
SelectCustomPlaceholder string
SelectCustomChevron string
SelectCustomChevronOpen string
SelectCustomListbox string
SelectCustomOption string
SelectCustomCheck string
SelectMultiTriggerBase string
SelectMultiChevron string
SelectMultiChipsPadding string
LabelBase string
InputLegendBase string
OutlinedBorder string
FilledBorder string
FocusBorder string
FocusVisibleBorder string
FocusWithinBorder string
FilledBackgroundColor string
ErrorMessage string

Full reference: TwInputTheme on the API docs.

On this page

  • Basic select
  • Desktop and mobile behavior
  • Select with complex objects
  • Clearable select
  • Item templates
  • Required select
  • Disabled and readonly select
  • Select with numbers
  • Dense select
  • Multi-select
  • Keyboard navigation
  • Theme configuration
twblazor

The Tailwind CSS component library for Blazor. Accessible, themeable and MIT licensed.

Discord (opens in a new tab) GitHub(opens in a new tab)

Get started

  • Install guide
  • Theming
  • Class merging
  • Localization

Guides

  • Tailwind CSS with Blazor
  • Why twblazor?
  • Right to left
  • AI agents and skills

Resources

  • API documentation (opens in a new tab)
  • llms.txt (opens in a new tab)
  • MIT License (opens in a new tab)

Community

  • Contributing (opens in a new tab)
  • Code of conduct (opens in a new tab)
  • Report an issue (opens in a new tab)

twblazor is and always will be free and open source.

An unhandled error has occurred. Reload