Button

Button component is used to trigger an action or event, such as submitting a form, opening a Dialog, canceling an action, or performing a delete operation.

SourceTheme Source@chakra-ui/button

Import#

import { Button } from '@chakra-ui/react'

Usage#

<Button colorPalette='teal'>Button</Button>

Button Sizes#

Use the size prop to change the size of the button. You can set the value to xs, sm, md, or lg.

<Stack gap={4} direction='row' align='center'>
<Button colorPalette='teal' size='xs'>
Button
</Button>
<Button colorPalette='teal' size='sm'>
Button
</Button>
<Button colorPalette='teal' size='md'>
Button
</Button>
<Button colorPalette='teal' size='lg'>
Button
</Button>
</Stack>

Button variants#

Use the variant prop to change the visual style of the Button. You can set the value to solid, outline, or ghost

<Stack direction='row' gap={4} align='center'>
<Button colorPalette='teal' variant='solid'>
Button
</Button>
<Button colorPalette='teal' variant='outline'>
Button
</Button>
<Button colorPalette='teal' variant='ghost'>
Button
</Button>
</Stack>

Changing the color palette#

Use the colorPalette prop to change the color palette of the Button. You can set the value to any of the color scales from your design system, like whiteAlpha, blackAlpha, gray, red, blue, or your custom color scale.

<Wrap gap={4}>
<Button colorPalette='gray'>Gray</Button>
<Button colorPalette='red'>Red</Button>
<Button colorPalette='orange'>Orange</Button>
<Button colorPalette='yellow'>Yellow</Button>
<Button colorPalette='green'>Green</Button>
<Button colorPalette='teal'>Teal</Button>
</Wrap>

Using icons#

<Stack direction='row' gap={4}>
<Button colorPalette='teal'>
<FiMail />
Email
</Button>
<Button colorPalette='teal' variant='outline'>
Call us
<MdArrowForward />
</Button>
</Stack>

You can also use icons from popular libraries like react-icons and pass it into the button.

// import { MdBuild , MdCall } from "react-icons/md"
<Stack direction='row' gap={4}>
<Button colorPalette='pink'>
<MdBuild />
Settings
</Button>
<Button colorPalette='blue' variant='outline'>
Call us
<MdCall />
</Button>
</Stack>

Showing loading state#

To show a loading state, set the disabled prop to true and use the Spinner component.

<Button disabled colorPalette='teal'>
<Spinner size='sm' /> Loading
</Button>

To ensure the width of the button does not change when the loading state is active, use the AbsoluteCenter component.

<Button disabled colorPalette='teal'>
<AbsoluteCenter>
<BeatLoader size={8} color='white' />
</AbsoluteCenter>
<Span opacity='0'>Submitting</Span>
</Button>

Accessibility#

  • Button has role of button.
  • When Button has focus, Space or Enter activates it.
Edit this page on GitHub

Proudly made inNigeria by Segun Adebayo

Deployed by â–² Vercel