Introducing PrimeReact v11-alpha 🎉Discover Now

Button

An unstyled button component with compound composition and group support.

Build fully custom button elements with complete control over layout and styling.

basic-demo

Pre-styled Versions

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

Features#

  • Single component with ButtonGroup for grouping multiple buttons
  • Native <button> semantics with full HTML attribute support
  • Icon composition via children — place icon components before or after text

Usage#

import { Button } from 'primereact/button';
import { ButtonGroup } from 'primereact/buttongroup';
<Button></Button>
 
<ButtonGroup>
    <Button></Button>
    <Button></Button>
</ButtonGroup>

Behavior#

Icon Composition#

Place icon components as children alongside text. DOM order determines icon position.

import { Check } from '@primeicons/react/check';
 
/* Icon before text */
<Button>
    <Check />
    Confirm
</Button>;
 
/* Icon after text */
<Button>
    Save
    <Check />
</Button>;

Polymorphic Rendering#

Use as to change the rendered HTML element or use a custom React component.

<Button as="a" href="/home">
    Home
</Button>

Render Function Children#

Button accepts a render function as children, providing access to the component instance.

<Button>{(instance) => <span>Custom render</span>}</Button>

Pass Through#

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

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

API#

Button#

NameTypeDefault
refRef<unknown>
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ButtonInstance) => CSSProperties)
The style to apply to the component.
classNamestring | ((instance?: ButtonInstance) => 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.
instanceButtonInstance
The instance to pass to the component.
ptSafeRecord<ButtonPassThrough>
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: ButtonInstance) => 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.
size"small" | "large" | "normal"
Size of the Button.
severitystring & {} | "secondary" | "info" | "success" | "warn" | "danger" | "contrast" | "help"
Severity type of the Button.
variant"link" | "text" | "outlined"
Variant of the Button.
plainboolean
Whether to show the Button with a plain style.
roundedboolean
Whether to show the Button with a rounded style.
raisedboolean
Whether to show the Button with a raised style.
iconOnlyboolean
Whether to show the Button with a borderless style.
fluidboolean
Whether to show the Button with a fluid width.
[key: string]any
pt-{optionName}-*-
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"button"
data-part"root"

Defines passthrough(pt) options of Button component.

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

ButtonGroup#

NameTypeDefault
refRef<unknown>
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ButtonGroupInstance) => CSSProperties)
The style to apply to the component.
classNamestring | ((instance?: ButtonGroupInstance) => 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.
instanceButtonGroupInstance
The instance to pass to the component.
ptSafeRecord<ButtonGroupPassThrough>
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: ButtonGroupInstance) => 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 Button component.

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

Accessibility#

Screen Reader#

Button renders a native <button> element by default and uses its built-in semantics. Provide an accessible name with visible text, aria-label, or aria-labelledby. Icon-only buttons must use aria-label to ensure an accessible name.

Keyboard Support#

KeyFunction
tabMoves focus to button.
enterActivates the button.
spaceActivates the button.