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

TwTagInput

TwTagInput is a Blazor tag input for lists of free-form tags. Add tags with Enter or a comma, paste a whole list and get suggestions as you type.

Last updated 6 November 2026

Please be aware this component is new, may have bugs and/or be subject to change. Please report any bugs at https://github.com/twblazor/twblazor/issues.

Basic usage

Bind the tags with @bind-Value to an IReadOnlyList<string>. Type a tag and press Enter or type a comma to add it. Each tag is a removable TwChip: click its remove button, or press Backspace in the empty field to remove the last tag. Surrounding spaces are trimmed and empty tags are ignored.
  • Blazor
  • C#

Value: Blazor, C#

RAZOR
<TwTagInput Label="Skills" Placeholder="Add a skill" @bind-Value="skills" />
<p class="mt-2 text-sm text-gray-600 dark:text-gray-400">Value: <strong>@string.Join(", ", skills)</strong></p>
CSHARP
@code {
    private IReadOnlyList<string> skills = ["Blazor", "C#"];
}

Separators and paste

Separators are the characters that add a tag when typed, a comma by default. Pasted text is split on them and on line breaks, so a whole list can be pasted at once. Here a space, a comma and a semicolon all separate tags. Pass an empty list to add tags with Enter only, so a tag can contain commas.

Separate keywords with a space, a comma or a semicolon, or paste a list.

RAZOR
<TwTagInput Label="Keywords" Separators="@keywordSeparators" HelperText="Separate keywords with a space, a comma or a semicolon, or paste a list." @bind-Value="keywords" />
CSHARP
@code {
    private readonly char[] keywordSeparators = [' ', ',', ';'];
    private IReadOnlyList<string> keywords = [];
}

Suggestions

Pass Suggestions to list matching tags as the user types. The arrow keys move through them and Enter adds the highlighted one, or click one. Tags already added are left out, and any other text can still be added. For a server-side search, set SearchFunc instead, with DebounceInterval to wait for a pause in typing.
  • Blazor
RAZOR
<TwTagInput Label="Frameworks" Placeholder="Search frameworks" Suggestions="@frameworks" MaxSuggestions="6" @bind-Value="chosenFrameworks" />
CSHARP
@code {
    private readonly string[] frameworks = ["Angular", "ASP.NET Core", "Blazor", "Django", "Express", "Laravel", "Next.js", "Nuxt", "Rails", "React", "Spring", "Svelte", "Vue"];
    private IReadOnlyList<string> chosenFrameworks = ["Blazor"];
}

Limits and duplicates

MaxTags caps how many tags the field holds and MaxTagLength how long each one can be. Duplicates are rejected, ignoring case, unless AllowDuplicates is set. A tag that cannot be added stays in the field, the reason is shown under it and announced, and OnTagRejected is invoked with the tag and a TagRejectionReason.
  • bug

Up to 3 labels of at most 12 characters.

Last rejected: none

RAZOR
<TwTagInput Label="Labels" MaxTags="3" MaxTagLength="12" HelperText="Up to 3 labels of at most 12 characters." OnTagRejected="@OnLabelRejected" @bind-Value="labels" />
<p class="mt-2 text-sm text-gray-600 dark:text-gray-400">Last rejected: <strong>@lastRejection</strong></p>
CSHARP
@code {
    private IReadOnlyList<string> labels = ["bug"];
    private string lastRejection = "none";
    
    private void OnLabelRejected(TagRejectedEventArgs rejection) => lastRejection = $"{rejection.Tag} ({rejection.Reason})";
}

Validation

TagValidator checks each tag before it is added: return an error message to reject it, or null to accept it. Inside an EditForm or a TwForm the field reports every change, so validation attributes on the bound list, such as [MinLength], run for it and their message is shown under the field.
RAZOR
<EditForm Model="@invite" class="flex flex-col gap-4">
    <DataAnnotationsValidator />
    <TwTagInput Label="Invite by email" Required Separators="@emailSeparators" TagValidator="@ValidateEmail" @bind-Value="invite.Emails" />
    <div>
        <TwButton Type="submit" Variant="ButtonVariant.Filled" Color="Color.Primary" Label="Send invites" />
    </div>
</EditForm>
CSHARP
@code {
    private readonly char[] emailSeparators = [',', ';', ' '];
    private readonly InviteModel invite = new();
    
    private static string? ValidateEmail(string tag) =>
        new EmailAddressAttribute().IsValid(tag) ? null : $"{tag} is not an email address";
    
    private sealed class InviteModel
    {
        [MinLength(1, ErrorMessage = "Add at least one email address")]
        public IReadOnlyList<string> Emails { get; set; } = [];
    }
}

Add on blur

Set AddOnBlur to add the typed text as a tag when focus leaves the field, so a tag the user typed but did not confirm is not lost.
  • Flour
RAZOR
<TwTagInput Label="Ingredients" AddOnBlur @bind-Value="ingredients" />
CSHARP
@code {
    private IReadOnlyList<string> ingredients = ["Flour"];
}

Clearable

Clearable shows a button at the end of the field that removes every tag. Like the text field's clear button it is not a Tab stop, since keyboard users can remove tags with Backspace.
  • Ada
  • Grace
  • Alan
RAZOR
<TwTagInput Label="Recipients" Clearable @bind-Value="recipients" />
CSHARP
@code {
    private IReadOnlyList<string> recipients = ["Ada", "Grace", "Alan"];
}

Variants, dense and chip style

Variant and Dense work as they do on TwTextfield, so a tag input lines up with the other inputs; a dense field uses smaller tags. ChipColor and ChipVariant style the tags.
  • Design
  • Code
  • Design
  • Code
  • Design
  • Code
RAZOR
<div class="grid gap-4 sm:grid-cols-3">
    <TwTagInput Label="Default" Variant="InputVariant.Default" @bind-Value="variantTags" />
    <TwTagInput Label="Outlined" Variant="InputVariant.Outlined" ChipVariant="ButtonVariant.Filled" @bind-Value="variantTags" />
    <TwTagInput Label="Filled, dense" Variant="InputVariant.Filled" Dense ChipColor="Color.Success" @bind-Value="variantTags" />
</div>
CSHARP
@code {
    private IReadOnlyList<string> variantTags = ["Design", "Code"];
}

Disabled and readonly

Disabled dims the field, and its tags can neither be added nor removed. ReadOnly keeps the tags readable, but hides their remove buttons and blocks typing.
  • Archived
  • Internal
  • Archived
  • Internal
RAZOR
<div class="grid gap-4 sm:grid-cols-2">
    <TwTagInput Label="Disabled" Value="@fixedTags" Disabled />
    <TwTagInput Label="Readonly" Value="@fixedTags" ReadOnly />
</div>
CSHARP
@code {
    private readonly IReadOnlyList<string> fixedTags = ["Archived", "Internal"];
}

Accessibility

The tags are a list named after the field's Label, placed before the text field, and each remove button is named after its tag, such as "Remove Blazor". Tab stops only on the text field: the arrow keys move between the tags, and Delete or Backspace removes the focused one, so a long list of tags does not fill the Tab order. Every tag added or removed is announced through a live region, in the language of the app. HelperText and any error message are linked to the text field with aria-describedby. In a right to left layout the arrow keys follow the reading direction.

Keyboard navigation

Each tag is a chip in a list before the text field. The arrow keys move between the tags, so Tab stops only on the text field, and the remove buttons are not Tab stops. Additions and removals are announced to screen readers.
Key What it does
Tab or Shift+ plus Tab Moves focus into or out of the field.
Enter or , Adds the typed text as a tag. With a suggestion highlighted, adds the suggestion instead.
Backspace In the empty text field: removes the last tag.
Arrow Left or Arrow Right In the empty text field: moves to the last tag. On a tag: moves to the previous or next tag, or back to the text field after the last. Reversed in a right to left layout.
Home or End On a tag: moves to the first tag, or to the text field.
Delete or Backspace On a tag: removes it and moves to the tag beside it.
Arrow Down or Arrow Up Opens the suggestions and highlights the first or last one, or moves through them.
Escape Closes the suggestions. Focus stays in the field.

Theme configuration

Styling is controlled by TwBlazorTheme.Components (a TwTagInputTheme), 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.
Property Type Controls
Field string
Size string
DenseSize string
ChipsPadding string
TagList string
Input string
EndContent string
ClearButton string
HelperText string

Full reference: TwTagInputTheme on the API docs.

On this page

  • Basic usage
  • Separators and paste
  • Suggestions
  • Limits and duplicates
  • Validation
  • Add on blur
  • Clearable
  • Variants, dense and chip style
  • Disabled and readonly
  • Accessibility
  • 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