CollapsibleSection is a container with a tappable header that expands or collapses its body content. The body transition is driven by a max-height animation (0 → 2000 px, 250 ms ease-out) triggered by the collapsibleSection--expanded modifier class, so no code-side animation is required for the open/close motion.
Typical use cases:
FAQ accordion panels
Collapsible settings groups
Nested content trees inside scroll containers
Any section where body content should be hidden by default
Properties
Name
Description
Options
IsExpanded
Gets or sets the current expanded state. Setting this value animates the body and fires OnExpandedChanged.
bool
TitleText
Gets or sets the header label text.
string
USS Classes
Class
Description
collapsibleSection
Root element.
collapsibleSection__header
Tappable header row. Contains the title and chevron.
collapsibleSection__title
Label element inside the header.
collapsibleSection__chevron
Chevron/arrow icon that rotates to indicate state.
collapsibleSection__body
Outer body wrapper. Has max-height transition for the open/close animation.
collapsibleSection__bodyContent
Inner content container. Receives children added via AddBodyContent.
collapsibleSection--expanded
Modifier applied to the root when expanded. Drives the max-height transition and chevron rotation.
Events
Name
Description
Arguments
OnExpandedChanged
Fired after the expanded state changes.
bool isExpanded
Public Methods
Signature
Description
AddBodyContent(VisualElement element)
Appends a child element to the inner body content container.
SetBodyText(string text) : Label
Convenience method that creates and appends a Label with the given text. Returns the created label.
Toggle()
Toggles the expanded state. Equivalent to IsExpanded = !IsExpanded.
Using the Control
Basic Setup
usingUnityEngine;usingUnityEngine.UIElements;usingUnityUIToolkit.Extensions;publicclassFaqController:MonoBehaviour{[SerializeField]privateUIDocument_document;privatevoidOnEnable(){varroot=_document.rootVisualElement;varsection=newCollapsibleSection();section.TitleText="What is this app?";// Add plain text bodysection.SetBodyText("This app helps you track your daily habits and review progress over time.");// Add a richer body elementvarlinkLabel=newLabel("Learn more at example.com");linkLabel.style.color=newStyleColor(newColor(0.35f,0.65f,1f));section.AddBodyContent(linkLabel);section.OnExpandedChanged+=isExpanded=>{Debug.Log($"Section is now {(isExpanded?"open":"closed")}");};root.Add(section);}}
Programmatic Expand / Collapse
// Open all sections on first visitforeach(varsectionin_faqSections){section.IsExpanded=true;}// Toggle a section from an external button_toggleButton.clicked+=()=>_detailsSection.Toggle();