Introducing PrimeReact v11-alpha 🎉Discover Now

Fieldset

An unstyled, accessible fieldset component with semantic legend and optional collapsible content.

Build fully custom fieldset containers with complete control over layout and styling.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
basic-demo

Pre-styled Versions

Choose a pre-styled library to use Fieldset with ready-made designs.
For hook-based usage without components, see the Headless API.

Features#

  • Compound component API with six sub-components: Root, Legend, Title, Trigger, Indicator, Content
  • Semantic fieldset/legend HTML structure for native form grouping

Usage#

import { Fieldset } from 'primereact/fieldset';
<Fieldset.Root>
    <Fieldset.Legend>
        <Fieldset.Trigger>
            <Fieldset.Indicator />
            <Fieldset.Title />
        </Fieldset.Trigger>
    </Fieldset.Legend>
    <Fieldset.Content />
</Fieldset.Root>

Behavior#

Motion Animation#

Use motionProps on Root to configure open/close animations.

<Fieldset.Root motionProps={{ name: 'p-collapsible', cssVarPrefix: 'fieldset-content', hideStrategy: 'none' }}>...</Fieldset.Root>

See Motion for animation phases, CSS variables, and hide strategies.

Polymorphic Rendering#

Use as on any sub-component to change the rendered HTML element.

<Fieldset.Root as="div">
    <Fieldset.Legend as="div">
        <Fieldset.Title as="h3">...</Fieldset.Title>
    </Fieldset.Legend>
    <Fieldset.Content as="section">...</Fieldset.Content>
</Fieldset.Root>

Default elements: Root=fieldset, Legend=legend, Title=span, Trigger=button, Content=div, Indicator=span.

Render Function Children#

Content accepts a render function as children, providing access to the component instance. The instance exposes fieldset (root instance) and motion (animation state).

<Fieldset.Content>{(instance) => <div>Fieldset is {instance.fieldset?.state.open ? 'open' : 'closed'}</div>}</Fieldset.Content>

Pass Through#

Some parts may not be visible in the preview depending on the component's current state.

Loading...
/* Select a part to see its CSS selector for custom styling */

API#

FieldsetRoot#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: FieldsetRootInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: FieldsetRootInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceFieldsetRootInstance—
The instance to pass to the component.
ptSafeRecord<FieldsetRootPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: FieldsetRootInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
openbooleanfalse
Controls the open state of the collapsible.
defaultOpenbooleanfalse
Defines the initial open state of the collapsible.
disabledbooleanfalse
When disabled, the component cannot be interacted with.
tabIndexnumber0
Index of the element in tabbing order.
onOpen(event?: SyntheticEvent) => void—
Callback triggered when the content is opened.
onClose(event?: SyntheticEvent) => void—
Callback triggered when the content is closed.
onOpenChange(event: useFieldsetOpenChangeEvent) => void—
Callback triggered when the content's toggle state changes.
lazybooleanfalse
When enabled, hidden content is not rendered at all. Defaults to false that hides content with css.
motionPropsMotionOptions—
Used to configure the motion of the fieldset content.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"fieldset"
data-part"root"
data-openPresent when expanded
data-closedPresent when collapsed
data-disabledPresent when disabled

Defines passthrough(pt) options of Fieldset component.

labeltypedescription
rootFieldsetRootPassThroughType<HTMLAttributes<HTMLFieldSetElement>>Used to pass attributes to the root's DOM element.
legendFieldsetRootPassThroughType<HTMLAttributes<HTMLLegendElement>>Used to pass attributes to the legend's DOM element.
titleFieldsetRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the title's DOM element.
triggerFieldsetRootPassThroughType<HTMLAttributes<HTMLButtonElement>>Used to pass attributes to the trigger's DOM element.
contentFieldsetRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the content's DOM element.
contentOuterFieldsetRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the content outer wrapper's DOM element.
contentInnerFieldsetRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the content inner wrapper's DOM element.
indicatorFieldsetRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the indicator's DOM element.

FieldsetLegend#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: FieldsetLegendInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: FieldsetLegendInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceFieldsetLegendInstance—
The instance to pass to the component.
ptSafeRecord<FieldsetLegendPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: FieldsetLegendInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of FieldsetLegend component.

labeltypedescription
rootFieldsetLegendPassThroughType<HTMLAttributes<HTMLLegendElement>>Used to pass attributes to the root's DOM element.

FieldsetTitle#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: FieldsetTitleInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: FieldsetTitleInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceFieldsetTitleInstance—
The instance to pass to the component.
ptSafeRecord<FieldsetTitlePassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: FieldsetTitleInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of FieldsetTitle component.

labeltypedescription
rootFieldsetTitlePassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the root's DOM element.

FieldsetTrigger#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: FieldsetTriggerInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: FieldsetTriggerInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceFieldsetTriggerInstance—
The instance to pass to the component.
ptSafeRecord<FieldsetTriggerPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: FieldsetTriggerInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"fieldset"
data-part"trigger"
data-content-openPresent when content open
data-content-closedPresent when content closed

Defines passthrough(pt) options of FieldsetTrigger component.

labeltypedescription
rootFieldsetTriggerPassThroughType<HTMLAttributes<HTMLButtonElement>>Used to pass attributes to the root's DOM element.

FieldsetIndicator#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: FieldsetIndicatorInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: FieldsetIndicatorInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceFieldsetIndicatorInstance—
The instance to pass to the component.
ptSafeRecord<FieldsetIndicatorPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: FieldsetIndicatorInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
match"open" | "closed"—
Determines the visibility of the indicator based on the state of the fieldset. Valid values are: - "open": Indicator is visible when the fieldset is expanded. - "closed": Indicator is visible when the fieldset is collapsed.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"fieldset"
data-part"indicator"
data-openPresent when expanded
data-closedPresent when collapsed

Defines passthrough(pt) options of FieldsetIndicator component.

labeltypedescription
rootFieldsetIndicatorPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the root's DOM element.

FieldsetContent#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: FieldsetContentInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: FieldsetContentInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceFieldsetContentInstance—
The instance to pass to the component.
ptSafeRecord<FieldsetContentPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: FieldsetContentInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"fieldset"
data-part"content"
data-openPresent when expanded
data-closedPresent when collapsed

Defines passthrough(pt) options of FieldsetContent component.

labeltypedescription
rootFieldsetContentPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

Accessibility#

Screen Reader#

Fieldset uses the semantic fieldset element with a legend for the title. This native structure provides accessible grouping without additional ARIA roles. For toggleable usage, the trigger button uses aria-controls to reference the content region and aria-expanded to reflect visibility state.

Keyboard Support#

KeyFunction
tabMoves focus to the next focusable element in the page tab sequence.
shift + tabMoves focus to the previous focusable element in the page tab sequence.
enterToggles the visibility of the content.
spaceToggles the visibility of the content.