Button
A button allows a user to perform an action, with mouse, touch, and keyboard interactions.
Features
On the surface, building a custom styled button seems simple. However, there are many
cross browser inconsistencies in interactions and accessibility features to consider.
Button
handles all of these interactions for you, so you can focus on the styling.
- Styleable – Hover, press, and keyboard focus states are provided for easy styling. These states only apply when interacting with an appropriate input device, unlike CSS pseudo classes.
- Accessible – Uses a native
<button>
element under the hood, with support for the Space and Enter keys. - Cross-browser – Mouse, touch, keyboard, and focus interactions are normalized to ensure consistency across browsers and devices.
Anatomy
Buttons consist of a clickable area usually containing a textual label or an icon that users can click to perform an action. In addition, keyboard users may activate buttons using the Space or Enter keys.
If a visual label is not provided (e.g. an icon only button), then an aria-label
or
aria-labelledby
prop must be passed to identify the button to assistive technology.
Examples

Events
Button
supports user interactions via mouse, keyboard, and touch. You can handle all of these via the onPress
prop. This is similar to the standard onClick
event, but normalized to support all interaction methods equally. In addition, the onPressStart
, onPressEnd
, and onPressChange
events are fired as the user interacts with the button.
Each of these handlers receives a PressEvent, which exposes information about the target and the type of event that triggered the interaction. See usePress for more details.
Ready to be pressed.
import {Button} from 'react-aria-components';
import {useState} from 'react';
function Example() {
let [pointerType, setPointerType] = useState('');
return (
<>
<Button
onPressStart={e => setPointerType(e.pointerType)}
onPressEnd={() => setPointerType('')}>
Press me
</Button>
<p>{pointerType ? `You are pressing the button with a ${pointerType}!` : 'Ready to be pressed.'}</p>
</>
);
}
Props
Name | Type | |
---|---|---|
isPending | boolean | |
Whether the button is in a pending state. This disables press and hover events while retaining focusability, and announces the pending state to screen readers. | ||
isDisabled | boolean | |
Whether the button is disabled. | ||
children | ChildrenOrFunction | |
The children of the component. A function may be provided to alter the children based on component state. | ||
Default className: react-aria-Button
Render Prop | CSS Selector | Description |
---|---|---|
isHovered | CSS Selector: [data-hovered]
| Whether the button is currently hovered with a mouse. |
isPressed | CSS Selector: [data-pressed]
| Whether the button is currently in a pressed state. |
isFocused | CSS Selector: [data-focused]
| Whether the button is focused, either via a mouse or keyboard. |
isFocusVisible | CSS Selector: [data-focus-visible]
| Whether the button is keyboard focused. |
isDisabled | CSS Selector: [data-disabled]
| Whether the button is disabled. |
isPending | CSS Selector: [data-pending]
| Whether the button is currently in a pending state. |