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

TwTextfield

TwTextfield is a Blazor text input component. Bind Value, use Multiline for a textarea, add a clear button with Clearable, and validate with Validator.

Last updated 23 October 2026

Textfield

Bind Value to a labeled text input with a placeholder.
RAZOR
<div class="md:flex-col flex-row flex gap-2">
    <TwTextfield Label="Forename" @bind-Value="Forename" Placeholder="Please enter your forename" AriaLabel="Forename textfield"  />
    <TwTextfield Label="Surname" @bind-Value="Surname" Placeholder="Please enter your surname" AriaLabel="Surname textfield" />
</div>

Disabled textfield

Use the Disabled property to prevent interaction with the textfield.
RAZOR
<TwTextfield Label="Forename" @bind-Value="Forename" Placeholder="Please enter your forename" AriaLabel="Forename textfield" Disabled />

Readonly textfield

Use the ReadOnly property to display a value that can't be edited.
RAZOR
<TwTextfield Label="Account ID" @bind-Value="AccountId" Placeholder="Account ID" AriaLabel="Account ID textfield" ReadOnly />

Outlined variant

Set Variant="InputVariant.Outlined" for an outlined textfield style.
RAZOR
<div class="md:flex-col flex-row flex gap-2">
    <TwTextfield Label="Forename" @bind-Value="Forename" Placeholder="Please enter your forename" AriaLabel="Forename textfield" Variant="InputVariant.Outlined" />
    <TwTextfield Label="Surname" @bind-Value="Surname" Placeholder="Please enter your surname" AriaLabel="Surname textfield" Variant="InputVariant.Outlined" />
</div>

Filled variant

Set Variant="InputVariant.Filled" for a filled textfield style.
RAZOR
<div class="md:flex-col flex-row flex gap-2">
    <TwTextfield Label="Forename" @bind-Value="Forename" Placeholder="Please enter your forename" AriaLabel="Forename textfield" Variant="InputVariant.Filled" />
    <TwTextfield Label="Surname" @bind-Value="Surname" Placeholder="Please enter your surname" AriaLabel="Surname textfield" Variant="InputVariant.Filled" />
</div>

Different input types

Use InputType to render native input types such as email and password.
RAZOR
<div class="md:flex-col flex-row flex gap-2">
    <TwTextfield Label="Email" @bind-Value="Email" Placeholder="Enter your email address" AriaLabel="Email textfield" InputType="email" />
    <TwTextfield Label="Password" @bind-Value="Password" Placeholder="Enter password" AriaLabel="Password textfield" InputType="password" />
</div>

Invalid textfield

Set Invalid and ErrorMessage to mark the textfield as failing validation. The message is rendered below the input and associated with it via aria-describedby so assistive technology announces it alongside the field.

Please enter a valid email address.

RAZOR
<TwTextfield Label="Email" @bind-Value="InvalidEmail" Placeholder="Enter your email address" AriaLabel="Email textfield" Invalid ErrorMessage="Please enter a valid email address." />

Dense textfield

Set Dense for a more compact input with a smaller height and text size. Every single-line input shares the same dense height, so they line up when used side by side.
RAZOR
<TwTextfield Label="Forename" @bind-Value="Forename" Placeholder="Please enter your forename" AriaLabel="Dense forename textfield" Dense />

Clearable textfield

Set Clearable to show an X button at the end of the field. It is disabled while the field is empty. Pressing it empties the field, runs Validator, invokes OnClear and moves focus back into the field. The button is not a Tab stop, since keyboard users can clear the text themselves, and it is hidden while the field is disabled or read-only.

Cleared 0 times.

RAZOR
<div class="md:flex-col flex-row flex gap-2">
    <TwTextfield Label="Search" @bind-Value="SearchTerm" Placeholder="Search orders" Clearable OnClear="@(() => clearCount++)" />
    <TwTextfield Label="Reference" @bind-Value="Reference" Clearable Variant="InputVariant.Outlined" />
</div>
<p class="mt-2 text-sm text-gray-600 dark:text-gray-400">Cleared <strong>@clearCount</strong> times.</p>
CSHARP
@code {
    public string SearchTerm { get; set; } = "Order 1042";
    public string Reference { get; set; } = "REF-7781";
    
    private int clearCount;
}

Start and end content

Use StartContent and EndContent to draw content over the start or end of a single-line field, such as an icon or a unit. The field's padding is not widened for it, so add padding through Class so the text does not run underneath. Hide decorative content from screen readers with aria-hidden="true".
RAZOR
<TwTextfield Label="Website" @bind-Value="Website" Placeholder="example.co.uk" Class="ps-9" Clearable>
    <StartContent>
        <TwIcon Icon="Icon.Globe" aria-hidden="true" />
    </StartContent>
</TwTextfield>

Validation on change

Pass a Validator function to have the textfield validate itself whenever its value changes. Return null (or an empty string) when the value is valid, or an error message to automatically mark the field Invalid and display the returned message - no need to manage Invalid or ErrorMessage yourself.
RAZOR
<TwTextfield Label="Username" @bind-Value="Username" Placeholder="Enter a username" AriaLabel="Username textfield" Validator="ValidateUsername" />
CSHARP
@code {
    public string Username { get; set; } = string.Empty;
    
    private static Task<string?> ValidateUsername(string value)
    {
        if (string.IsNullOrWhiteSpace(value))
        {
            return Task.FromResult<string?>("Username is required.");
        }
    
        if (value.Length < 3)
        {
            return Task.FromResult<string?>("Username must be at least 3 characters.");
        }
    
        return Task.FromResult<string?>(null);
    }
}

Asynchronous validation

Validator returns a Task<string?>, so it can perform asynchronous work such as an API call without blocking the UI. This example simulates checking username availability against a server.
RAZOR
<TwTextfield Label="New Username" @bind-Value="NewUsername" Placeholder="Enter a username" AriaLabel="New username textfield" Validator="ValidateUsernameAvailabilityAsync" />
CSHARP
@code {
    public string NewUsername { get; set; } = string.Empty;
    
    private readonly HashSet<string> _takenUsernames = new(StringComparer.OrdinalIgnoreCase) { "admin", "root", "john" };
    
    private async Task<string?> ValidateUsernameAvailabilityAsync(string value)
    {
        if (string.IsNullOrWhiteSpace(value))
        {
            return "Username is required.";
        }
    
        // Simulate a network call to check availability against a server.
        await Task.Delay(300);
    
        return _takenUsernames.Contains(value) ? $"'{value}' is already taken." : null;
    }
}

Multiline textfield

Set Multiline to render a <textarea> for longer text such as comments or descriptions. It shows three lines by default and can be resized vertically by dragging its corner.
RAZOR
<TwTextfield Label="Comments" @bind-Value="Comments" Placeholder="Tell us what you think" Multiline />

Multiline rows

Use Rows to set how many lines of text are visible before the field scrolls.
RAZOR
<div class="md:flex-col flex-row flex gap-2">
    <TwTextfield Label="Summary" @bind-Value="Summary" Placeholder="A one or two line summary" Multiline Rows="2" />
    <TwTextfield Label="Description" @bind-Value="IssueDescription" Placeholder="Describe the issue in detail" Multiline Rows="6" />
</div>

Auto-growing multiline

Set AutoGrow to have the field grow taller as the user types instead of scrolling. Rows sets the starting height and MaxRows caps how tall it can grow, after which it scrolls. Browsers without support for the CSS field-sizing property keep the Rows height and scroll.
RAZOR
<TwTextfield Label="Message" @bind-Value="Message" Placeholder="Start typing and the field grows with you" Multiline AutoGrow Rows="2" MaxRows="8" BindEvent="oninput" />

Multiline variants

Multiline fields support every Variant, so they match the single-line fields beside them.
RAZOR
<div class="flex flex-col gap-4">
    <TwTextfield Label="Default" @bind-Value="DefaultNotes" Placeholder="Notes" Multiline Variant="InputVariant.Default" />
    <TwTextfield Label="Outlined" @bind-Value="OutlinedNotes" Placeholder="Notes" Multiline Variant="InputVariant.Outlined" />
    <TwTextfield Label="Filled" @bind-Value="FilledNotes" Placeholder="Notes" Multiline Variant="InputVariant.Filled" />
</div>

Dense multiline

Combine Multiline with Dense for tighter padding and a smaller text size.
RAZOR
<TwTextfield Label="Notes" @bind-Value="DenseNotes" Placeholder="Add a short note" Multiline Dense Rows="2" />

Multiline character limit

Pass maxlength through Attributes to limit how much can be typed, and bind on oninput to show a live count below the field.

0 / 160

RAZOR
<TwTextfield Label="Bio" @bind-Value="Bio" Placeholder="A few words about yourself" Multiline Rows="4" BindEvent="oninput" Attributes="@_bioAttributes" />
<p class="mt-1 text-xs text-end">@Bio.Length / @bioMaxLength</p>
CSHARP
@code {
    private const int bioMaxLength = 160;
    
    public string Bio { get; set; } = string.Empty;
    
    private readonly Dictionary<string, object> _bioAttributes = new() { ["maxlength"] = bioMaxLength };
}

Multiline validation

Validator, Required, Disabled and ReadOnly work the same way on a multiline field. The error message is linked to the textarea with aria-describedby.
RAZOR
<div class="flex flex-col gap-4">
    <TwTextfield Label="Feedback" @bind-Value="Feedback" Placeholder="At least 20 characters" Multiline Required Validator="ValidateFeedback" />
    <TwTextfield Label="Terms" @bind-Value="Terms" Multiline Rows="2" ReadOnly />
    <TwTextfield Label="Archived notes" @bind-Value="ArchivedNotes" Multiline Rows="2" Disabled />
</div>
CSHARP
@code {
    public string Feedback { get; set; } = string.Empty;
    public string Terms { get; set; } = "By continuing you agree to the terms of service.\nThese terms can't be changed here.";
    public string ArchivedNotes { get; set; } = "Archived on 1 March 2026.";
    
    private static Task<string?> ValidateFeedback(string value)
    {
        if (string.IsNullOrWhiteSpace(value))
        {
            return Task.FromResult<string?>("Feedback is required.");
        }
    
        return Task.FromResult<string?>(value.Trim().Length < 20 ? "Feedback must be at least 20 characters." : null);
    }
}

Keyboard navigation

A text field is a native input, so every text editing key works as usual. An error message is announced when it appears. The clear button of a clearable field is not a Tab stop, because the text can be cleared from the keyboard.
Key What it does
Tab or Shift+ plus Tab Moves focus into or out of the field, including a multiline field.
Enter Commits the value, when the field binds on change. In a multiline field, inserts a new line instead.
Arrow Up or Arrow Down or Arrow Left or Arrow Right Moves the caret through the text, line by line in a multiline field.
Home or End Moves the caret to the start or end of the line.
Pg.Up or Pg.Down In a multiline field: moves the caret up or down by a visible page of text.

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

  • Textfield
  • Disabled textfield
  • Readonly textfield
  • Outlined variant
  • Filled variant
  • Different input types
  • Invalid textfield
  • Dense textfield
  • Clearable textfield
  • Start and end content
  • Validation on change
  • Asynchronous validation
  • Multiline textfield
  • Multiline rows
  • Auto-growing multiline
  • Multiline variants
  • Dense multiline
  • Multiline character limit
  • Multiline validation
  • 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