Support CoreUI Development

CoreUI is an MIT-licensed open source project and is completely free to use. However, the amount of effort needed to maintain and develop new features for the project is not sustainable without proper financial backing.

You can support our Open Source software development in the following ways:

  • Buy the CoreUI PRO, and get access to PRO components, and dedicated support.
  • Became a sponsor, and get your logo on files or each site of this documentation
  • Give us a star ⭐️ on Github.

React Button Component

React button component for actions in tables, forms, cards, and more. CoreUI for React.js provides various styles, states, and size. Ready to use and easy to customize.

How to use React Button Component.#

CoreUI includes a bunch of predefined buttons components, each serving its own semantic purpose. React buttons show what action will happen when the user clicks or touches it. CoreUI buttons are used to initialize operations, both in the background or foreground of an experience.

1<CButton color="primary" disabled>Primary</CButton>
2<CButton color="secondary">Secondary</CButton>
3<CButton color="success">Success</CButton>
4<CButton color="danger">Danger</CButton>
5<CButton color="warning">Warning</CButton>
6<CButton color="info">Info</CButton>
7<CButton color="light">Light</CButton>
8<CButton color="dark">Dark</CButton>
9<CButton color="link">Link</CButton>
Conveying meaning to assistive technologies

Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (e.g. the visible text), or is included through alternative means, such as additional text hidden with the `.visually-hidden` class.

Disable text wrapping#

If you don't want the react button text to wrap, you can add the .text-nowrap className to the <CButton>. In Sass, you can set $btn-white-space: nowrap to disable text wrapping for each button.

Button components#

The <CButton> component are designed for <button> , <a> or <input> elements (though some browsers may apply a slightly different rendering).

If you're using <CButton> component as <a> elements that are used to trigger functionality ex. collapsing content, these links should be given a role="button" to adequately communicate their meaning to assistive technologies such as screen readers.

1<CButton component="a" color="primary" href="#" role="button">Link</CButton>
2<CButton type="submit" color="primary">Button</CButton>
3<CButton component="input" type="button" color="primary" value="Input"/>
4<CButton component="input" type="submit" color="primary" value="Submit"/>
5<CButton component="input" type="reset" color="primary" value="Reset"/>

Outline buttons#

If you need a button, but without the strong background colors. Set variant="outline" prop to remove all background colors.

1<CButton color="primary" variant="outline">Primary</CButton>
2<CButton color="secondary" variant="outline">Secondary</CButton>
3<CButton color="success" variant="outline">Success</CButton>
4<CButton color="danger" variant="outline">Danger</CButton>
5<CButton color="warning" variant="outline">Warning</CButton>
6<CButton color="info" variant="outline">Info</CButton>
7<CButton color="light" variant="outline">Light</CButton>
8<CButton color="dark" variant="outline">Dark</CButton>

Ghost buttons#

If you need a ghost variant of react button, set variant="ghost" prop to remove all background colors.

1<CButton color="primary" variant="ghost">Primary</CButton>
2<CButton color="secondary" variant="ghost">Secondary</CButton>
3<CButton color="success" variant="ghost">Success</CButton>
4<CButton color="danger" variant="ghost">Danger</CButton>
5<CButton color="warning" variant="ghost">Warning</CButton>
6<CButton color="info" variant="ghost">Info</CButton>
7<CButton color="light" variant="ghost">Light</CButton>
8<CButton color="dark" variant="ghost">Dark</CButton>
Some of the button styles use a relatively light foreground color, and should only be used on a dark background in order to have sufficient contrast.


Larger or smaller react buttons? Add size="lg" or size="sm" for additional sizes.

1<CButton color="primary" size="lg">Large button</CButton>
2<CButton color="secondary" size="lg">Large button</CButton>
1<CButton color="primary" size="sm">Small button</CButton>
2<CButton color="secondary" size="sm">Small button</CButton>


Pill buttons#

1<CButton color="primary" shape="rounded-pill">Primary</CButton>
2<CButton color="secondary" shape="rounded-pill">Secondary</CButton>
3<CButton color="success" shape="rounded-pill">Success</CButton>
4<CButton color="danger" shape="rounded-pill">Danger</CButton>
5<CButton color="warning" shape="rounded-pill">Warning</CButton>
6<CButton color="info" shape="rounded-pill">Info</CButton>
7<CButton color="light" shape="rounded-pill">Light</CButton>
8<CButton color="dark" shape="rounded-pill">Dark</CButton>
9<CButton color="link" shape="rounded-pill">Link</CButton>

Square buttons#

1<CButton color="primary" shape="rounded-0">Primary</CButton>
2<CButton color="secondary" shape="rounded-0">Secondary</CButton>
3<CButton color="success" shape="rounded-0">Success</CButton>
4<CButton color="danger" shape="rounded-0">Danger</CButton>
5<CButton color="warning" shape="rounded-0">Warning</CButton>
6<CButton color="info" shape="rounded-0">Info</CButton>
7<CButton color="light" shape="rounded-0">Light</CButton>
8<CButton color="dark" shape="rounded-0">Dark</CButton>
9<CButton color="link" shape="rounded-0">Link</CButton>

Disabled state#

Add the disabled boolean prop to any <CButton> component to make buttons look inactive. Disabled button has pointer-events: none applied to, disabling hover and active states from triggering.

1<CButton color="primary" size="lg" disabled>Primary button</CButton>
2<CButton color="secondary" size="lg" disabled>Button</CButton>

Disabled buttons using the <a> component act a little different:

<a>s don't support the disabled attribute, so CoreUI has to add .disabled className to make buttons look inactive. CoreUI also has to add to the disabled button component aria-disabled="true" attribute to show the state of the component to assistive technologies.

1<CButton component="a" href="#" color="primary" size="lg" disabled>Primary link</CButton>
2<CButton component="a" href="#" color="secondary" size="lg" disabled>Link</CButton>

The .disabled class uses pointer-events: none to try to disable the link functionality of <a>s, but that CSS property is not yet standardized. Besides, even in browsers that do support pointer-events: none, keyboard navigation remains unaffected, meaning that sighted keyboard users and users of assistive technologies will still be able to activate these links. So to be safe, we automatically add a tabindex="-1" attribute on disabled links (to prevent them from receiving keyboard focus) and use custom JavaScript to disable their functionality.

Block buttons#

Create buttons that span the full width of a parent—by using utilities.

1<div className="d-grid gap-2">
2 <CButton color="primary">Button</CButton>
3 <CButton color="primary">Button</CButton>

Here we create a responsive variation, starting with vertically stacked buttons until the md breakpoint, where .d-md-block replaces the .d-grid class, thus nullifying the gap-2 utility. Resize your browser to see them change.

1<div className="d-grid gap-2 d-md-block">
2 <CButton color="primary">Button</CButton>
3 <CButton color="primary">Button</CButton>

You can adjust the width of your block buttons with grid column width classes. For example, for a half-width "block button", use .col-6. Center it horizontally with .mx-auto, too.

1<div className="d-grid gap-2 col-6 mx-auto">
2 <CButton color="primary">Button</CButton>
3 <CButton color="primary">Button</CButton>

Additional utilities can be used to adjust the alignment of buttons when horizontal. Here we've taken our previous responsive example and added some flex utilities and a margin utility on the button to right align the buttons when they're no longer stacked.

1<div className="d-grid gap-2 d-md-flex justify-content-md-end">
2 <CButton color="primary" className="me-md-2">
3 Button
4 </CButton>
5 <CButton color="primary">Button</CButton>


CSS variables#

React buttons use local CSS variables on .btn for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.

1--cui-btn-padding-x: #{$btn-padding-x};
2--cui-btn-padding-y: #{$btn-padding-y};
3--cui-btn-font-family: #{$btn-font-family};
4--cui-btn-font-size: #{$btn-font-size};
5--cui-btn-font-weight: #{$btn-font-weight};
6--cui-btn-line-height: #{$btn-line-height};
7--cui-btn-color: #{$body-color};
8--cui-btn-bg: transparent;
9--cui-btn-border-width: #{$btn-border-width};
10--cui-btn-border-color: transparent;
11--cui-btn-border-radius: #{$btn-border-radius};
12--cui-btn-box-shadow: #{$btn-box-shadow};
13--cui-btn-disabled-opacity: #{$btn-disabled-opacity};
14--cui-btn-focus-box-shadow: 0 0 0 #{$btn-focus-width} rgba(var(--cui-btn-focus-shadow-rgb), .5);

How to use CSS variables#

1const vars = {
2 '--my-css-var': 10,
3 '--my-another-css-var': "red"
5return <CButton style={vars}>...</CButton>

SASS variables#

1$btn-padding-y: $input-btn-padding-y;
2$btn-padding-x: $input-btn-padding-x;
3$btn-font-family: $input-btn-font-family;
4$btn-font-size: $input-btn-font-size;
5$btn-line-height: $input-btn-line-height;
6$btn-white-space: null; // Set to `nowrap` to prevent text wrapping
8$btn-padding-y-sm: $input-btn-padding-y-sm;
9$btn-padding-x-sm: $input-btn-padding-x-sm;
10$btn-font-size-sm: $input-btn-font-size-sm;
12$btn-padding-y-lg: $input-btn-padding-y-lg;
13$btn-padding-x-lg: $input-btn-padding-x-lg;
14$btn-font-size-lg: $input-btn-font-size-lg;
16$btn-border-width: $input-btn-border-width;
18$btn-font-weight: $font-weight-normal;
19$btn-box-shadow: inset 0 1px 0 rgba($white, .15), 0 1px 1px rgba($black, .075);
20$btn-focus-width: $input-btn-focus-width;
21$btn-focus-box-shadow: $input-btn-focus-box-shadow;
22$btn-disabled-opacity: .65;
23$btn-active-box-shadow: inset 0 3px 5px rgba($black, .125);
25$btn-link-color: var(--cui-link-color);
26$btn-link-hover-color: var(--cui-link-hover-color);
27$btn-link-disabled-color: $gray-600;
29// Allows for customizing button radius independently from global border radius
30$btn-border-radius: $border-radius;
31$btn-border-radius-sm: $border-radius-sm;
32$btn-border-radius-lg: $border-radius-lg;
34$btn-transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;
36$btn-hover-bg-shade-amount: 15%;
37$btn-hover-bg-tint-amount: 15%;
38$btn-hover-border-shade-amount: 20%;
39$btn-hover-border-tint-amount: 10%;
40$btn-active-bg-shade-amount: 20%;
41$btn-active-bg-tint-amount: 20%;
42$btn-active-border-shade-amount: 25%;
43$btn-active-border-tint-amount: 10%;
45// scss-docs-start button-variants
46$button-variants: (
47 "primary": btn-color-map($primary, $primary),
48 "secondary": btn-color-map($secondary, $secondary),
49 "success": btn-color-map($success, $success),
50 "danger": btn-color-map($danger, $danger),
51 "warning": btn-color-map($warning, $warning),
52 "info": btn-color-map($info, $info),
53 "light": btn-color-map($light, $light),
54 "dark": btn-color-map($dark, $dark)
57$button-outline-ghost-variants: (
58 "primary": btn-outline-color-map($primary),
59 "secondary": btn-outline-color-map($secondary),
60 "success": btn-outline-color-map($success),
61 "danger": btn-outline-color-map($danger),
62 "warning": btn-outline-color-map($warning),
63 "info": btn-outline-color-map($info),
64 "light": btn-outline-color-map($light),
65 "dark": btn-outline-color-map($dark)
67// scss-docs-end button-variants



1import { CButton } from '@coreui/react'
2// or
3import CButton from '@coreui/react-pro/src/components/button/CButton'
activeToggle the active state for the component.boolean-
classNameA string of all className you want applied to the base component.string-
colorSets the color context of the component to one of CoreUI’s themed colors.'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | stringprimary
componentComponent used for the root node. Either a string to use a HTML element or a component.string | ComponentClass<any, any> | FunctionComponent<any>button
disabledToggle the disabled state for the component.boolean-
hrefThe href attribute specifies the URL of the page the link goes to.string-
roleThe role attribute describes the role of an element in programs that can make use of it, such as screen readers or magnifiers.string-
shapeSelect the shape of the component.'rounded' | 'rounded-top' | 'rounded-end' | 'rounded-bottom' | 'rounded-start' | 'rounded-circle' | 'rounded-pill' | 'rounded-0' | 'rounded-1' | 'rounded-2' | 'rounded-3' | string-
sizeSize the component small or large.'sm' | 'lg'-
typeSpecifies the type of button. Always specify the type attribute for the <button> element.
Different browsers may use different default types for the <button> element.
'button' | 'submit' | 'reset'button
variantSet the button variant to an outlined button or a ghost button.'outline' | 'ghost'-