Skip to content

Button

Alpha
Use button for the main actions on a page or form.
import {Button} from '@primer/react'

Examples

Default button

This is the default variant for the Button component.

Danger button

The danger variant of Button is used to warn users about potentially destructive actions

Outline button

The outline variant of Button is typically used as a secondary button

Invisible button

The invisible variant of Button indicates that the action is a low priority one.

Different sized buttons

Button component supports three different sizes. small, medium, large.

Appending an icon

We can place an icon inside the Button in either the leading or the trailing position to enhance the visual context. It is recommended to use an octicon here.

Icon only button

A separate component called IconButton is used if the action shows only an icon with no text. This button will remain square in shape.

Different sized icon buttons

IconButton also supports the three different sizes. small, medium, large.

Counter component

A common use case for primer is a button with a counter component which shows the child count value. We provide Button.Counter as a composite component which requires you to provide a number as child. The counter will match the variant styles of the parent button.

Styling a button

A button can be styled in an appropriate manner using the sx prop. This may be to change width, or to add margins etc. Here's an example of a block button which takes 100% of available width. Checkout styled-system to see what you can send in an sx prop.

Props

Native <button> HTML attributes are forwarded to the underlying React button component and are not listed below.

Button

NameTypeDefaultDescription
children Required
React.ReactNode
Button description along with other components like Counter could be used here.
variant
'default' | 'primary' | 'danger' | 'outline' | 'invisible'
Changes the look and feel of the button which is different for each variant
size
'small' | 'medium' | 'large'
Changes the size of the button component
leadingIcon
Component
provide an octicon. It will be placed before the button text
trailingIcon
Component
provide an octicon. It will be placed after the button text
sx
SystemStyleObject
Style overrides to apply to the component. See also overriding styles.

Button.Counter

NameTypeDefaultDescription
children Required
number
The counter value as a number
sx
SystemStyleObject
Style overrides to apply to the component. See also overriding styles.

Status

Alpha

  • Component props are documented on primer.style/react.
  • Component does not have any unnecessary third-party dependencies.
  • Component can adapt to different themes.
  • Component can adapt to different screen sizes.
  • Component has 100% test coverage.

Beta

  • Component is used in a production application.
  • Common usage examples are documented on primer.style/react.
  • Common usage examples are documented in storybook stories.
  • Component has been reviewed by a systems designer and any resulting issues have been addressed.
  • Component has been manually reviewed by the accessibility team and any resulting issues have been addressed.

Stable

  • Component API has been stable with no breaking changes for at least one month.
  • Feedback on API usability has been sought from developers using the component and any resulting issues have been addressed.
  • Component has corresponding design guidelines documented in the interface guidelines.
  • Component has corresponding Figma component in the Primer Web library.