Version 0.13.2

Button

A button with primary, secondary, and tertiary variants, destructive styling, and loading state.

Usage#

import { Button } from '@backstage/ui';

<Button>Click me</Button>

API reference#

PropTypeDefaultDescription
variant
primarysecondarytertiary
primaryVisual style. Use primary for main actions, secondary for alternatives, tertiary for low-emphasis.
destructive
boolean
falseApplies destructive styling for dangerous actions like delete or remove.
size
smallmedium
smallButton size. Use small for dense layouts.
iconStart
ReactElement
-Icon displayed before the button text.
iconEnd
ReactElement
-Icon displayed after the button text.
isDisabled
boolean
falsePrevents interaction and applies disabled styling.
loading
boolean
falseShows a spinner and disables the button.
children
ReactNode
-Button label text or content.
type
buttonsubmitreset
buttonHTML button type attribute.
onSurface
0123dangerwarningsuccessauto
-Surface context for correct color contrast.
className
string
-Additional CSS class name for custom styling.
style
CSSProperties
-Inline CSS styles object.

Inherits all React Aria Button props.

Examples#

Variants#

<Flex>
  <Button variant="primary" iconStart={<RiCloudLine />}>
    Button
  </Button>
  <Button variant="secondary" iconStart={<RiCloudLine />}>
    Button
  </Button>
  <Button variant="tertiary" iconStart={<RiCloudLine />}>
    Button
  </Button>
</Flex>

Sizes#

<Flex align="center">
  <Button size="small">Small</Button>
  <Button size="medium">Medium</Button>
</Flex>

With Icons#

Icons can appear before or after the label.

<Flex align="center">
  <Button iconStart={<RiCloudLine />}>Button</Button>
  <Button iconEnd={<RiArrowRightSLine />}>Button</Button>
  <Button iconStart={<RiCloudLine />} iconEnd={<RiArrowRightSLine />}>
    Button
  </Button>
</Flex>

Disabled#

<Flex gap="4">
  <Button variant="primary" isDisabled>
    Primary
  </Button>
  <Button variant="secondary" isDisabled>
    Secondary
  </Button>
  <Button variant="tertiary" isDisabled>
    Tertiary
  </Button>
</Flex>

Destructive#

Use the destructive prop for dangerous actions like delete or remove.

<Flex gap="4">
  <Button variant="primary" destructive>
    Primary
  </Button>
  <Button variant="secondary" destructive>
    Secondary
  </Button>
  <Button variant="tertiary" destructive>
    Tertiary
  </Button>
</Flex>

Loading#

Shows a spinner and disables interaction during async operations.

<Button variant="primary" loading={true}>
  Load more items
</Button>

Responsive#

Button props accept responsive breakpoint objects.

<Button variant={{ initial: 'primary', lg: 'secondary' }}>
  Responsive Button
</Button>

If you want to use a button as a link, please use the ButtonLink component.

<MemoryRouter>
  <ButtonLink href="https://ui.backstage.io" target="_blank">
    Button
  </ButtonLink>
</MemoryRouter>

Theming#

Our theming system is based on a mix between CSS classes, CSS variables and data attributes. If you want to customise this component, you can use one of these class names below.

  • bui-Button
  • bui-ButtonContent
  • bui-ButtonSpinner

Changelog#

Version 0.13.0#

Changes

  • Fixed focus ring styles to use React Aria's [data-focus-visible] data attribute instead of the native CSS :focus-visible pseudo-class. This ensures keyboard focus rings render reliably when focus is managed programmatically by React Aria (e.g. inside a GridList, Menu, or Select). #33358

  • Fixed handling of the style prop on Button, ButtonIcon, and ButtonLink so that it is now correctly forwarded to the underlying element instead of being silently dropped. #33095

Version 0.12.0#

Breaking Changes

  • Breaking Replaced Surface / onSurface system with new provider/consumer background system

    The old Surface type ('0'–'3', 'auto') and its associated props (surface, onSurface) have been replaced by a provider/consumer bg architecture.

    Types:

    • ContainerBg — 'neutral-1' | 'neutral-2' | 'neutral-3' | 'danger' | 'warning' | 'success'
    • ProviderBg — ContainerBg | 'neutral-auto'

    Consumer components (e.g. Button) inherit the parent's bg via data-on-bg, and CSS handles the visual step-up. See "Neutral level capping" below for details on how levels are bounded.

    Hooks:

    • useBgProvider(bg?) — for provider components. Returns { bg: undefined } when no bg is given (transparent). Supports 'neutral-auto' to auto-increment from the parent context.
    • useBgConsumer() — for consumer components. Returns the parent container's bg unchanged.

    Component roles:

    • Provider-only (Box, Flex, Grid): set data-bg, wrap children in BgProvider. Transparent by default — they do not auto-increment; pass bg="neutral-auto" explicitly if you want automatic neutral stepping.
    • Consumer-only (Button, ButtonIcon, ButtonLink): set data-on-bg, inherit the parent container's bg unchanged.
    • Provider + Consumer (Card): sets both data-bg and data-on-bg, wraps children. Card passes bg="neutral-auto" to its inner Box, so it auto-increments from the parent context.

    Neutral level capping:

    Provider components cap at neutral-3. There is no neutral-4 prop value. The neutral-4 level exists only in consumer component CSS — for example, a Button sitting on a neutral-3 surface uses neutral-4 tokens internally via data-on-bg. #32711

    Migration Guide:

    Rename the surface prop to bg on provider components and update values:

    - <Box surface="1">
    + <Box bg="neutral-1">
    
    - <Card surface="2">
    + <Card bg="neutral-2">
    
    - <Flex surface="0">
    + <Flex bg="neutral-1">
    
    - <Grid.Root surface="1">
    + <Grid.Root bg="neutral-1">
    

    Remove onSurface from consumer components — they now always inherit from the parent container:

    - <Button onSurface="1" variant="secondary">
    + <Button variant="secondary">
    
    - <ButtonIcon onSurface="2" variant="secondary" />
    + <ButtonIcon variant="secondary" />
    
    - <ToggleButton onSurface="1">
    + <ToggleButton>
    

    Update type imports:

    - import type { Surface, LeafSurfaceProps, ContainerSurfaceProps } from '@backstage/ui';
    + import type { ContainerBg, ProviderBg } from '@backstage/ui';
    

    Replace hook usage in custom components:

    - import { useSurface, SurfaceProvider } from '@backstage/ui';
    + import { useBgProvider, useBgConsumer, BgProvider } from '@backstage/ui';
    
    - const { surface } = useSurface({ surface: props.surface });
    + const { bg } = useBgProvider(props.bg);
    
    - const { surface } = useSurface({ onSurface: props.onSurface });
    + const { bg } = useBgConsumer();
    

    Update CSS selectors targeting surface data attributes:

    - [data-surface='1'] { ... }
    + [data-bg='neutral-1'] { ... }
    
    - [data-on-surface='1'] { ... }
    + [data-on-bg='neutral-1'] { ... }
    

    Note: Provider components use data-bg (values: neutral-1 through neutral-3, plus intent values). Consumer components use data-on-bg, which reflects the parent container's bg directly. The neutral-4 level never appears as a prop or data-bg value — it is used only in consumer CSS.

  • Breaking Removed large size variant from Button component as it was never implemented. #32541

    Migration Guide:

    - <Button size="large">Click me</Button>
    + <Button size="medium">Click me</Button>
    

Changes

  • Added destructive prop to Button for dangerous actions like delete or remove. Works with all variants (primary, secondary, tertiary). #32554

Version 0.11.0#

Changes

  • Fixes disabled state in primary and secondary buttons in Backstage UI. #32297

  • Fixed disabled tertiary buttons incorrectly showing hover effects on surfaces. #32385

Version 0.9.0#

Changes

  • Added loading prop to Button and ButtonIcon components for displaying spinner during async operations. #31681