React Button - Flowbite
Enable user interaction with the button component to perform actions on your website as links, for payment, form submission, social buttons and more based on React and Tailwind CSS
The button component is a common UI component found on the web that allows users to trigger certain actions on your website such as submitting a form, navigating to a new page, or downloading a file.
The examples from the Flowbite React library allows you to customise the buttons with different colors, sizes, icons, and more. All examples are built with React and Tailwind CSS.
In order to start using the button component you need to import it from Flowbite React:
import { Button } from "flowbite-react";
#
Default buttonsUse this example to create a default button by using the <Button>
component from React and by adding the color
property you can change the color of the button.
import { Button } from "flowbite-react";
export function Component() {
return (
<div className="flex flex-wrap gap-2">
<Button>Default</Button>
<Button color="alternative">Alternative</Button>
<Button color="dark">Dark</Button>
<Button color="light">Light</Button>
<Button color="green">Green</Button>
<Button color="red">Red</Button>
<Button color="yellow">Yellow</Button>
<Button color="purple">Purple</Button>
</div>
);
}
#
Button pillsAdd the pill
property to the <Button>
component to create a button with rounded corners.
import { Button } from "flowbite-react";
export function Component() {
return (
<div className="flex flex-wrap gap-2">
<Button pill>Default</Button>
<Button color="alternative" pill>
Alternative
</Button>
<Button color="dark" pill>
Dark
</Button>
<Button color="light" pill>
Light
</Button>
<Button color="green" pill>
Green
</Button>
<Button color="red" pill>
Red
</Button>
<Button color="yellow" pill>
Yellow
</Button>
<Button color="purple" pill>
Purple
</Button>
</div>
);
}
#
Gradient monochromeThese beautifully colored buttons built with the gradient color utility classes from Tailwind CSS can be used as a creative alternative to the default button styles.
import { Button } from "flowbite-react";
export function Component() {
return (
<div className="flex flex-wrap gap-2">
<Button className="bg-gradient-to-r from-blue-500 via-blue-600 to-blue-700 text-white hover:bg-gradient-to-br focus:ring-blue-300 dark:focus:ring-blue-800">
Blue
</Button>
<Button className="bg-gradient-to-r from-green-400 via-green-500 to-green-600 text-white hover:bg-gradient-to-br focus:ring-green-300 dark:focus:ring-green-800">
Green
</Button>
<Button className="bg-gradient-to-r from-cyan-400 via-cyan-500 to-cyan-600 text-white hover:bg-gradient-to-br focus:ring-cyan-300 dark:focus:ring-cyan-800">
Cyan
</Button>
<Button className="bg-gradient-to-r from-teal-400 via-teal-500 to-teal-600 text-white hover:bg-gradient-to-br focus:ring-teal-300 dark:focus:ring-teal-800">
Teal
</Button>
<Button className="bg-gradient-to-r from-lime-200 via-lime-400 to-lime-500 text-gray-900 hover:bg-gradient-to-br focus:ring-lime-300 dark:focus:ring-lime-800">
Lime
</Button>
<Button className="bg-gradient-to-r from-red-400 via-red-500 to-red-600 text-white hover:bg-gradient-to-br focus:ring-red-300 dark:focus:ring-red-800">
Red
</Button>
<Button className="bg-gradient-to-r from-pink-400 via-pink-500 to-pink-600 text-white hover:bg-gradient-to-br focus:ring-pink-300 dark:focus:ring-pink-800">
Pink
</Button>
<Button className="bg-gradient-to-r from-purple-500 via-purple-600 to-purple-700 text-white hover:bg-gradient-to-br focus:ring-purple-300 dark:focus:ring-purple-800">
Purple
</Button>
</div>
);
}
#
Gradient duotoneThese buttons use a style that includes two contrasted colors creating an impressive mesh gradient effect.
import { Button } from "flowbite-react";
export function Component() {
return (
<div className="flex flex-wrap gap-2">
<Button className="bg-gradient-to-br from-purple-600 to-blue-500 text-white hover:bg-gradient-to-bl focus:ring-blue-300 dark:focus:ring-blue-800">
Purple to Blue
</Button>
<Button className="bg-gradient-to-r from-cyan-500 to-blue-500 text-white hover:bg-gradient-to-bl focus:ring-cyan-300 dark:focus:ring-cyan-800">
Cyan to Blue
</Button>
<Button className="bg-gradient-to-br from-green-400 to-blue-600 text-white hover:bg-gradient-to-bl focus:ring-green-200 dark:focus:ring-green-800">
Green to Blue
</Button>
<Button className="bg-gradient-to-r from-purple-500 to-pink-500 text-white hover:bg-gradient-to-l focus:ring-purple-200 dark:focus:ring-purple-800">
Purple to Pink
</Button>
<Button className="bg-gradient-to-br from-pink-500 to-orange-400 text-white hover:bg-gradient-to-bl focus:ring-pink-200 dark:focus:ring-pink-800">
Pink to Orange
</Button>
<Button className="bg-gradient-to-r from-teal-200 to-lime-200 text-gray-900 hover:bg-gradient-to-l hover:from-teal-200 hover:to-lime-200 focus:ring-lime-200 dark:focus:ring-teal-700">
Teal to Lime
</Button>
<Button className="bg-gradient-to-r from-red-200 via-red-300 to-yellow-200 text-gray-900 hover:bg-gradient-to-bl focus:ring-red-100 dark:focus:ring-red-400">
Red to Yellow
</Button>
</div>
);
}
#
Outline buttonsUse the outline
property to create an outline button with transparent background and colored border.
import { Button } from "flowbite-react";
export function Component() {
return (
<div className="flex flex-wrap gap-2">
<Button outline>Default</Button>
<Button color="dark" outline>
Dark
</Button>
<Button color="green" outline>
Green
</Button>
<Button color="red" outline>
Red
</Button>
<Button color="yellow" outline>
Yellow
</Button>
<Button color="purple" outline>
Purple
</Button>
</div>
);
}
#
Button sizesYou can update the size of the button by adding the size
property to the <Button>
component.
Choose from xs
, sm
, md
, lg
, and xl
as the value.
import { Button } from "flowbite-react";
export function Component() {
return (
<div className="flex flex-wrap items-start gap-2">
<Button size="xs">Extra small</Button>
<Button size="sm">Small</Button>
<Button size="md">Base</Button>
<Button size="lg">Large</Button>
<Button size="xl">Extra large</Button>
</div>
);
}
#
Buttons with iconYou can add icons to the buttons by adding it inside the <Button>
component near the text.
import { Button } from "flowbite-react";
import { HiOutlineArrowRight, HiShoppingCart } from "react-icons/hi";
export function Component() {
return (
<div className="flex flex-wrap gap-2">
<Button>
<HiShoppingCart className="mr-2 h-5 w-5" />
Buy now
</Button>
<Button>
Choose plan
<HiOutlineArrowRight className="ml-2 h-5 w-5" />
</Button>
</div>
);
}
#
Button with labelThis example can be used to show a notification count or helper text inside a button using the Badge component.
import { Badge, Button } from "flowbite-react";
export function Component() {
return (
<Button>
Messages
<Badge className="ms-2 rounded-full px-1.5">2</Badge>
</Button>
);
}
#
Button with only iconsCreate a button with only icons by adding the iconOnly
property to the <Button>
component. These are useful when you want to show buttons in a small space and for things like pagination.
import { Button } from "flowbite-react";
import { HiOutlineArrowRight } from "react-icons/hi";
export function Component() {
return (
<div className="flex flex-wrap gap-2">
<Button>
<HiOutlineArrowRight className="h-6 w-6" />
</Button>
<Button pill>
<HiOutlineArrowRight className="h-6 w-6" />
</Button>
<Button outline>
<HiOutlineArrowRight className="h-6 w-6" />
</Button>
<Button outline pill>
<HiOutlineArrowRight className="h-6 w-6" />
</Button>
</div>
);
}
#
Button with loading stateUse the following Spinner component to indicate a loader animation inside buttons:
import { Button, Spinner } from "flowbite-react";
export function Component() {
return (
<div className="flex flex-wrap items-start gap-2">
<Button>
<Spinner size="sm" aria-label="Info spinner example" className="me-3" light />
Loading...
</Button>
<Button color="alternative">
<Spinner size="sm" aria-label="Info spinner example" className="me-3" light />
Loading...
</Button>
</div>
);
}
#
Disabled buttonsYou can disable the button by adding the disabled
property to the <Button>
component.
import { Button } from "flowbite-react";
export function Component() {
return <Button disabled>Disabled button</Button>;
}
#
Override Button base componentThe as
prop provides you the ability to transform the <Button />
component into another component or HTML element. This prop accepts a string representing an HTML tag or a functional React component.
import { Button } from "flowbite-react";
import Link from "next/link";
export function Component() {
return (
<div className="flex flex-wrap gap-2">
<Button as="span" className="cursor-pointer">
Span Button
</Button>
<Button as={Link} href="#">
Next Link Button
</Button>
</div>
);
}
#
ThemeTo learn more about how to customize the appearance of components, please see the Theme docs.
{
"base": "relative flex items-center justify-center rounded-lg text-center font-medium focus:outline-none focus:ring-4",
"disabled": "pointer-events-none opacity-50",
"fullSized": "w-full",
"grouped": "rounded-none border-l-0 first:rounded-s-lg first:border-l last:rounded-e-lg focus:ring-2",
"pill": "rounded-full",
"size": {
"xs": "h-8 px-3 text-xs",
"sm": "h-9 px-3 text-sm",
"md": "h-10 px-5 text-sm",
"lg": "h-12 px-5 text-base",
"xl": "h-[52px] px-6 text-base"
},
"color": {
"default": "bg-primary-700 text-white hover:bg-primary-800 focus:ring-primary-300 dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800",
"alternative": "border border-gray-200 bg-white text-gray-900 hover:bg-gray-100 hover:text-primary-700 focus:ring-gray-100 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-700",
"blue": "bg-blue-700 text-white hover:bg-blue-800 focus:ring-blue-300 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800",
"cyan": "bg-cyan-700 text-white hover:bg-cyan-800 focus:ring-cyan-300 dark:bg-cyan-600 dark:hover:bg-cyan-700 dark:focus:ring-cyan-800",
"dark": "bg-gray-800 text-white hover:bg-gray-900 focus:ring-gray-300 dark:bg-gray-800 dark:hover:bg-gray-700 dark:focus:ring-gray-700",
"gray": "bg-gray-700 text-white hover:bg-gray-800 focus:ring-gray-300 dark:bg-gray-600 dark:hover:bg-gray-700 dark:focus:ring-gray-800",
"green": "bg-green-700 text-white hover:bg-green-800 focus:ring-green-300 dark:bg-green-600 dark:hover:bg-green-700 dark:focus:ring-green-800",
"indigo": "bg-indigo-700 text-white hover:bg-indigo-800 focus:ring-indigo-300 dark:bg-indigo-600 dark:hover:bg-indigo-700 dark:focus:ring-indigo-800",
"light": "border border-gray-300 bg-white text-gray-900 hover:bg-gray-100 focus:ring-gray-100 dark:border-gray-600 dark:bg-gray-800 dark:text-white dark:hover:border-gray-600 dark:hover:bg-gray-700 dark:focus:ring-gray-700",
"lime": "bg-lime-700 text-white hover:bg-lime-800 focus:ring-lime-300 dark:bg-lime-600 dark:hover:bg-lime-700 dark:focus:ring-lime-800",
"pink": "bg-pink-700 text-white hover:bg-pink-800 focus:ring-pink-300 dark:bg-pink-600 dark:hover:bg-pink-700 dark:focus:ring-pink-800",
"purple": "bg-purple-700 text-white hover:bg-purple-800 focus:ring-purple-300 dark:bg-purple-600 dark:hover:bg-purple-700 dark:focus:ring-purple-800",
"red": "bg-red-700 text-white hover:bg-red-800 focus:ring-red-300 dark:bg-red-600 dark:hover:bg-red-700 dark:focus:ring-red-800",
"teal": "bg-teal-700 text-white hover:bg-teal-800 focus:ring-teal-300 dark:bg-teal-600 dark:hover:bg-teal-700 dark:focus:ring-teal-800",
"yellow": "bg-yellow-400 text-white hover:bg-yellow-500 focus:ring-yellow-300 dark:bg-yellow-600 dark:hover:bg-yellow-400 dark:focus:ring-yellow-900"
},
"outlineColor": {
"default": "border border-primary-700 text-primary-700 hover:border-primary-800 hover:bg-primary-800 hover:text-white focus:ring-primary-300 dark:border-primary-600 dark:text-primary-500 dark:hover:border-primary-700 dark:hover:bg-primary-700 dark:hover:text-white dark:focus:ring-primary-800",
"blue": "border border-blue-700 text-blue-700 hover:border-blue-800 hover:bg-blue-800 hover:text-white focus:ring-blue-300 dark:border-blue-500 dark:text-blue-500 dark:hover:border-blue-700 dark:hover:bg-blue-700 dark:hover:text-white dark:focus:ring-blue-800",
"cyan": "border border-cyan-700 text-cyan-700 hover:border-cyan-800 hover:bg-cyan-800 hover:text-white focus:ring-cyan-300 dark:border-cyan-500 dark:text-cyan-500 dark:hover:border-cyan-700 dark:hover:bg-cyan-700 dark:hover:text-white dark:focus:ring-cyan-800",
"dark": "border border-gray-800 text-gray-800 hover:border-gray-900 hover:bg-gray-900 hover:text-white focus:ring-gray-300 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-600 dark:hover:text-white dark:focus:ring-gray-800",
"gray": "border border-gray-700 text-gray-700 hover:border-gray-800 hover:bg-gray-800 hover:text-white focus:ring-gray-300 dark:border-gray-600 dark:text-gray-400 dark:hover:border-gray-700 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-800",
"green": "border border-green-700 text-green-700 hover:border-green-800 hover:bg-green-800 hover:text-white focus:ring-green-300 dark:border-green-600 dark:text-green-500 dark:hover:border-green-700 dark:hover:bg-green-700 dark:hover:text-white dark:focus:ring-green-800",
"indigo": "border border-indigo-700 text-indigo-700 hover:border-indigo-800 hover:bg-indigo-800 hover:text-white focus:ring-indigo-300 dark:border-indigo-600 dark:text-indigo-400 dark:hover:border-indigo-700 dark:hover:bg-indigo-700 dark:hover:text-white dark:focus:ring-indigo-800",
"lime": "border border-lime-700 text-lime-700 hover:border-lime-800 hover:bg-lime-800 hover:text-white focus:ring-lime-300 dark:border-lime-600 dark:text-lime-500 dark:hover:border-lime-700 dark:hover:bg-lime-700 dark:hover:text-white dark:focus:ring-lime-800",
"pink": "border border-pink-700 text-pink-700 hover:border-pink-800 hover:bg-pink-800 hover:text-white focus:ring-pink-300 dark:border-pink-600 dark:text-pink-500 dark:hover:border-pink-700 dark:hover:bg-pink-700 dark:hover:text-white dark:focus:ring-pink-800",
"purple": "border border-purple-700 text-purple-700 hover:border-purple-800 hover:bg-purple-800 hover:text-white focus:ring-purple-300 dark:border-purple-600 dark:text-purple-400 dark:hover:border-purple-700 dark:hover:bg-purple-700 dark:hover:text-white dark:focus:ring-purple-800",
"red": "border border-red-700 text-red-700 hover:border-red-800 hover:bg-red-800 hover:text-white focus:ring-red-300 dark:border-red-600 dark:text-red-500 dark:hover:border-red-700 dark:hover:bg-red-700 dark:hover:text-white dark:focus:ring-red-800",
"teal": "border border-teal-700 text-teal-700 hover:border-teal-800 hover:bg-teal-800 hover:text-white focus:ring-teal-300 dark:border-teal-600 dark:text-teal-400 dark:hover:border-teal-700 dark:hover:bg-teal-700 dark:hover:text-white dark:focus:ring-teal-800",
"yellow": "border border-yellow-400 text-yellow-400 hover:border-yellow-500 hover:bg-yellow-500 hover:text-white focus:ring-yellow-300 dark:border-yellow-300 dark:text-yellow-300 dark:hover:border-yellow-400 dark:hover:bg-yellow-400 dark:hover:text-white dark:focus:ring-yellow-900"
}
}