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

Layout

TwCollapse

TwCollapse is a Blazor collapse component that expands and hides content. Bind IsOpen, set Title or HeaderContent, and react to OnToggle.

Last updated 7 November 2026

Basic collapse

The TwCollapse component provides a collapsible drawer panel that expands and collapses when the trigger button is clicked.

twblazor is a Tailwind CSS component library for Blazor that makes it easy to build modern, accessible UIs.

RAZOR
<TwCollapse Title="What is twblazor?" Class="mt-4">
    <p class="px-4 py-3 text-sm text-gray-700 dark:text-gray-300">twblazor is a Tailwind CSS component library for Blazor that makes it easy to build modern, accessible UIs.</p>
</TwCollapse>

Default open

Set IsOpen="true" to have the panel expanded on first render.

Install the twblazor NuGet package and call AddTwBlazor() in your service registration.

RAZOR
<TwCollapse Title="Getting started" IsOpen Class="mt-4">
    <p class="px-4 py-3 text-sm text-gray-700 dark:text-gray-300">Install the twblazor NuGet package and call <code>AddTwBlazor()</code> in your service registration.</p>
</TwCollapse>

Two-way binding

Use @bind-IsOpen to control the panel state from a parent component.
Panel is closed

This panel is controlled from outside the component via two-way binding.

RAZOR
<div class="flex items-center gap-3 mt-4 mb-4">
    <TwButton Label="@(isOpen ? "Close" : "Open")" OnClick="@(() => isOpen = !isOpen)" Color="Color.Primary" />
    <span class="text-sm text-gray-500 dark:text-gray-400">Panel is <strong>@(isOpen ? "open" : "closed")</strong></span>
</div>
<TwCollapse Title="Controlled panel" @bind-IsOpen="isOpen">
    <p class="px-4 py-3 text-sm text-gray-700 dark:text-gray-300">This panel is controlled from outside the component via two-way binding.</p>
</TwCollapse>

Custom header

Use the HeaderContent parameter to replace the plain title with fully custom markup.

Custom header content lets you compose icons, badges, or any Blazor markup inside the trigger button.

RAZOR
<TwCollapse Class="mt-4">
    <HeaderContent>
        <TwIcon Icon="Icon.Info_Circle" Class="text-blue-500" />
        <span>Additional information</span>
    </HeaderContent>
    <ChildContent>
        <p class="px-4 py-3 text-sm text-gray-700 dark:text-gray-300">Custom header content lets you compose icons, badges, or any Blazor markup inside the trigger button.</p>
    </ChildContent>
</TwCollapse>

Keyboard navigation

The header is a button that reports whether its content is expanded. Collapsed content is hidden from the Tab order.
Key What it does
Tab Moves focus to the header.
Enter or Space Expands or collapses the content.

Theme configuration

Styling is controlled by TwBlazorTheme.Components (a TwCollapseTheme), 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
Container string
Trigger string
Icon string
IconOpen string
Content string

Full reference: TwCollapseTheme on the API docs.

On this page

  • Basic collapse
  • Default open
  • Two-way binding
  • Custom header
  • 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