Button
A clickable element that triggers an action.
Import
import { Button } from '@matix/components/button';Usage
Variants
Buttons come in six visual variants.
Sizes
Disabled
With Icons
Pass any SVG icon as a child. Use size="1em" so the icon scales with the button's font size automatically — no per-size juggling.
The button auto-tightens inline padding on the icon side — icons carry their own optical padding, so equal padding looks loose.
Icon Only
For a button with no visible label, use the dedicated IconButton component — it renders a square target, scales the icon automatically, and requires an aria-label for accessibility.
As a Link
Pass a link element to render. The button styles go on the link, and the link keeps its own role. Screen readers announce a link, and Enter follows it.
If the render element has an href, Button sets nativeButton={false} for you and removes Base UI's role="button". If you give a role yourself, Button keeps it.
Tinted Destructive
The destructive variant is a solid fill by default. To get a tinted look, such as shadcn's, set the --mtx-btn-destructive-* hooks in your CSS. If you set only --mtx-btn-destructive-bg, the hover and active states keep that colour.
:root {
--mtx-btn-destructive-bg: color-mix(in oklab, #dc2626 10%, transparent);
--mtx-btn-destructive-bg-hover: color-mix(in oklab, #dc2626 16%, transparent);
--mtx-btn-destructive-color: #b91c1c;
}The hooks are -bg, -bg-hover, -bg-active, -color, -border, -border-width, -image, -image-hover, -shadow, and -shadow-hover. They follow the --mtx-btn-soft-* hooks.
Custom Styles
Use the sx prop to override styles. Your styles always win over internal styles.
import * as stylex from '@stylexjs/stylex';
const custom = stylex.create({
pill: { borderRadius: '9999px', paddingInline: '24px' },
});
<Button sx={custom.pill}>Pill Button</Button>;API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'solid' | 'outline' | 'ghost' | 'soft' | 'link' | 'destructive' | 'solid' | Visual style |
size | 'xs' | 'sm' | 'md' | 'lg' | 'md' | Size preset |
disabled | boolean | — | Disables the button |
render | ReactElement | — | Element to render in place of the <button>, e.g. a link |
nativeButton | boolean | true | false for a non-<button> element. Inferred for a link |
sx | StyleXStyles | — | StyleX style override |
All other props are forwarded to the underlying <button> element.
Accessibility
- Renders a native
<button>element by default. - With a link in
render, it renders that link with norole, so assistive tech announces a link, not a button. - Disabled state applies
aria-disabledand prevents all pointer and keyboard interaction. - Focus ring is visible only on keyboard navigation (
:focus-visible) — never on mouse click. - The
xssize is 22 px high, under the 24 px target size of WCAG 2.5.8. It passes when each target has 24 px of room: put at least 2 px between adjacentxsbuttons, and usesmor larger for dense touch layouts. - In forced colors mode (Windows contrast themes), solid and destructive buttons keep the system Highlight colours, and the focus ring shows as a system-colour outline.
- Inherits all Base UI Button accessibility behaviors, including ARIA role and keyboard handling.
Keyboard
| Key | Action |
|---|---|
Enter | Activates the button |
Space | Activates the button |