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

TwColorPicker

TwColorPicker is a Blazor colour picker component. Bind Value, choose an OutputFormat, and toggle ShowAlpha and ShowModeSwitch. Supports input variants.

Last updated 18 October 2026

Basic color picker

Bind Value to let users pick a color from a labeled color picker input.
RAZOR
<TwColorPicker Label="Choose Color" @bind-Value="selectedColor" />
CSHARP
@code {
    private string selectedColor { get; set; } = "#3b82f6";
}

With mode switch

Set ShowModeSwitch to let users toggle between color input modes (e.g. hex and RGB).
RAZOR
<TwColorPicker Label="Primary Color" @bind-Value="primaryColor" ShowModeSwitch />
CSHARP
@code {
    private string primaryColor { get; set; } = "#10b981";
}

With alpha channel

Set ShowAlpha to add an alpha channel slider for transparency.
RAZOR
<TwColorPicker Label="Overlay Color" @bind-Value="overlayColor" ShowAlpha ShowModeSwitch />
CSHARP
@code {
    private string overlayColor { get; set; } = "#f59e0bff";
}

Input variants

Use the Variant property to switch between default, outlined and filled input styles.
RAZOR
<div class="grid gap-4">
    <TwColorPicker Label="Primary Color" @bind-Value="primaryColor" Variant="InputVariant.Default" ShowModeSwitch />
    <TwColorPicker Label="Accent Color" @bind-Value="accentColor" Variant="InputVariant.Outlined" ShowModeSwitch />
    <TwColorPicker Label="Theme Color" @bind-Value="themeColor" Variant="InputVariant.Filled" />
</div>
CSHARP
@code {
    private string themeColor { get; set; } = "#8b5cf6";
    private string accentColor { get; set; } = "#ec4899";
}

Dense color picker

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
<TwColorPicker Label="Dense Color" @bind-Value="primaryColor" Dense />

Disabled state

Use the Disabled property to prevent interaction with the color picker.
RAZOR
<TwColorPicker Label="Disabled Color" Value="#cccccc" Disabled />

Output format

Use OutputFormat to control whether the bound value is emitted as hex or RGB, regardless of the input format.

Value: #3b82f6

Value: rgba(16, 185, 129, 0.8)

Value: hsl(262, 83%, 58%)

RAZOR
<div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
    @* Output as Hex (default) *@
    <div>
        <TwColorPicker Label="Hex (default)" @bind-Value="hexColor" />
        <p class="text-sm text-gray-600 dark:text-gray-400 mt-2">Value: @hexColor</p>
    </div>

    @* Output as RGB with alpha *@
    <div>
        <TwColorPicker Label="RGB with Alpha"
                       @bind-Value="rgbColor"
                       OutputFormat="ColorMode.Rgb"
                       ShowAlpha="true" />
        <p class="text-sm text-gray-600 dark:text-gray-400 mt-2">Value: @rgbColor</p>
    </div>

    @* Input format is auto-detected, independent of output format *@
    <div>
        <TwColorPicker Label="HSL Input → RGB Output"
                       @bind-Value="hslToRgbColor"
                       OutputFormat="ColorMode.Rgb" />
        <p class="text-sm text-gray-600 dark:text-gray-400 mt-2">Value: @hslToRgbColor</p>
    </div>
</div>
CSHARP
@code {
    private string hexColor { get; set; } = "#3b82f6";
    private string rgbColor { get; set; } = "rgba(16, 185, 129, 0.8)";
    private string hslToRgbColor { get; set; } = "hsl(262, 83%, 58%)";
}

Keyboard navigation

The swatch opens the picker panel and the text field accepts a typed color. Inside the panel each slider is its own Tab stop.
Key What it does
Enter or Space On the swatch: opens the panel and moves focus into it.
Tab or Shift+ plus Tab Moves between the controls in the open panel. Focus stays in the panel until it is closed.
Arrow Left or Arrow Right Saturation and lightness square: changes saturation.
Arrow Up or Arrow Down Saturation and lightness square: changes lightness.
Arrow Left or Arrow Right Hue and alpha sliders: decreases or increases the value.
Home or End Sets the focused slider to its minimum or maximum.
Enter or Space Presses the focused button: the eyedropper, the color format button, Cancel, or Confirm.
Escape Closes the panel without applying the color and returns focus to the swatch.

Theme configuration

Styling is controlled by TwBlazorTheme.Components (a TwColorPickerTheme), 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
Swatch string
SwatchDisabled string
SwatchHover string
InputContainer string
DialogPosition string
PreviewSwatch string
SelectorSquare string
SelectorThumb string
SliderTrack string
SliderThumb string
AlphaLabel string
ActionBar string
ControlRow string
Body string
SliderRow string
HueSliderTouch string
InputColumn string
ModeSwitchButton string
AlphaReadoutAlign string

Full reference: TwColorPickerTheme on the API docs.

On this page

  • Basic color picker
  • With mode switch
  • With alpha channel
  • Input variants
  • Dense color picker
  • Disabled state
  • Output format
  • 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