Use Tailwind’s custom button styles for actions in forms, dialogs, and more with support for multiple sizes, states, and more.
Tailwind includes several predefined button styles, each serving its own semantic purpose, with a few extras thrown in for more control.
<button type="button" class="px-4 py-2 mb-4 mr-4 text-white transition-all duration-500 ease-in-out bg-blue-500 border border-blue-500 rounded shadow-md hover:shadow-xl hover:bg-blue-600 focus:bg-blue-600">Primary</button>
<button type="button" class="px-4 py-2 mb-4 mr-4 text-white transition-all duration-500 ease-in-out bg-gray-600 border border-gray-600 rounded shadow-md hover:shadow-xl hover:bg-gray-700 focus:bg-gray-700">Secondary</button>
<button type="button" class="px-4 py-2 mb-4 mr-4 text-white transition-all duration-500 ease-in-out bg-green-500 border border-green-500 rounded shadow-md hover:shadow-xl hover:bg-green-600 focus:bg-green-600">Success</button>
<button type="button" class="px-4 py-2 mb-4 mr-4 text-white transition-all duration-500 ease-in-out bg-red-500 border border-red-500 rounded shadow-md hover:shadow-xl hover:bg-red-600 focus:bg-red-600">Danger</button>
<button type="button" class="px-4 py-2 mb-4 mr-4 text-white transition-all duration-500 ease-in-out bg-orange-500 border border-orange-500 rounded shadow-md hover:shadow-xl hover:bg-orange-600 focus:bg-orange-600">Warning</button>
<button type="button" class="px-4 py-2 mb-4 mr-4 text-white transition-all duration-500 ease-in-out border rounded shadow-md bg-cyan-500 border-cyan-500 hover:drop-shadow-lg hover:bg-cyan-600 focus:bg-cyan-600">Info</button>
<button type="button" class="px-4 py-2 mb-4 mr-4 text-black transition-all duration-500 ease-in-out bg-gray-300 border border-gray-300 rounded shadow-md hover:drop-shadow-lg hover:bg-gray-400 focus:bg-gray-400">Light</button>
<button type="button" class="px-4 py-2 mb-4 mr-4 text-white transition-all duration-500 ease-in-out bg-gray-900 border border-gray-900 rounded shadow-md hover:drop-shadow-lg hover:bg-gray-900 focus:bg-gray-900">Dark</button>
<button type="button" class="px-4 py-2 mb-4 mr-4 text-blue-500 transition-all duration-500 ease-in-out bg-transparent hover:text-blue-600 focus:shadow-lg rounded">Link</button>
If you don’t want the button text to wrap, you can add the .text-nowrap
class to the button. In Sass, you can set $btn-white-space: nowrap
to disable text wrapping for each button.
When using button classes on <a>
elements that are used to trigger in-page functionality
(like collapsing content), rather than linking to new pages or sections within the current page, these links
should be given a role="button"
to appropriately convey their purpose to
assistive technologies such as screen readers.
<div class="flex flex-wrap items-center">
<button class="px-6 py-2 mb-4 mr-4 text-white transition-all duration-500 ease-in-out bg-blue-500 border border-blue-500 rounded shadow-md hover:shadow-xl hover:bg-blue-600 focus:bg-blue-600 ">Default</button>
<button class="px-6 py-2 mb-4 mr-4 text-white transition-all duration-500 ease-in-out bg-blue-500 border border-blue-500 rounded-full shadow-md hover:shadow-xl hover:bg-blue-600 focus:bg-blue-600 ">Rounded</button>
<button class="inline-flex justify-center px-6 py-2 mb-4 mr-4 text-white transition-all duration-500 ease-in-out bg-blue-500 border border-blue-500 rounded-full shadow-md hover:shadow-xl hover:bg-blue-600 focus:bg-blue-600 ">
<span class="mr-2">
<svg width="24" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"></path>
</svg>
</span>With Icon
</button>
<button class="px-2 py-1 mb-4 mr-4 text-white transition-all duration-500 ease-in-out bg-blue-500 border border-blue-500 rounded shadow-md hover:shadow-xl hover:bg-blue-600 focus:bg-blue-600 ">
<span>
<svg width="24" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"></path>
</svg>
</span>
</button>
</div>
Use our background utility classes to quickly change the appearance of a badge. Please
note that when using Tailwind’s default .bg-blue-500, you’ll likely need a text color utility like .text-blue-500
for proper styling. This is because background utilities do not set
anything but background-color.
<button type="button" class="px-6 py-2 mb-4 mr-4 text-blue-500 transition-all duration-500 ease-in-out border border-blue-500 rounded hover:shadow-md hover:bg-blue-500 hover:text-white">Primary</button>
<button type="button" class="px-6 py-2 mb-4 mr-4 text-gray-600 transition-all duration-500 ease-in-out border border-gray-600 rounded hover:shadow-md hover:bg-gray-600 hover:text-white">Secondary</button>
<button type="button" class="px-6 py-2 mb-4 mr-4 text-green-500 transition-all duration-500 ease-in-out border border-green-500 rounded hover:shadow-md hover:bg-green-500 hover:text-white">Success</button>
<button type="button" class="px-6 py-2 mb-4 mr-4 text-red-500 transition-all duration-500 ease-in-out border border-red-500 rounded hover:shadow-md hover:bg-red-500 hover:text-white">Danger</button>
<button type="button" class="px-6 py-2 mb-4 mr-4 text-orange-500 transition-all duration-500 ease-in-out border border-orange-500 rounded hover:shadow-md hover:bg-orange-500 hover:text-white">Warning</button>
<button type="button" class="px-6 py-2 mb-4 mr-4 transition-all duration-500 ease-in-out border rounded text-cyan-500 border-cyan-500 hover:shadow-md hover:bg-cyan-500 hover:text-white">Info</button>
<button type="button" class="px-6 py-2 mb-4 mr-4 text-gray-300 transition-all duration-500 ease-in-out border border-gray-300 rounded hover:shadow-md hover:bg-gray-300 hover:text-black">Light</button>
<button type="button" class="px-6 py-2 mb-4 mr-4 text-gray-900 transition-all duration-500 ease-in-out border border-gray-900 rounded hover:shadow-md hover:bg-gray-900 hover:text-white">Dark</button>
In need of a icon button, with all types of background colors and shapes they bring
In need of a icon button, with all types of background colors and shapes they bring
Fancy larger or smaller buttons? Add .btn-lg
or .btn-sm
for additional sizes
<button type="button" class="px-2 py-0.5 mb-4 mr-4 text-sm text-white transition-all duration-500 ease-in-out border border-blue-500 bg-blue-500 rounded shadow-md hover:shadow-xl focus:bg-blue-600 hover:bg-blue-600 ">Exsmall</button>
<button type="button" class="px-4 py-1 mb-4 mr-4 text-sm text-white transition-all duration-500 ease-in-out bg-blue-500 border border-blue-500 rounded shadow-md hover:shadow-xl focus:bg-blue-600 hover:bg-blue-600 ">Smallbutton</button>
<button type="button" class="px-6 py-2 mb-4 mr-4 text-white transition-all duration-500 ease-in-out bg-blue-500 border border-blue-500 rounded shadow-md hover:shadow-xl hover:bg-blue-600 focus:bg-blue-600 ">Defaultbutton</button>
<button type="button" class="px-6 py-2 mb-4 mr-4 text-xl text-white transition-all duration-500 ease-in-out bg-blue-500 border border-blue-500 rounded shadow-md hover:shadow-xl hover:bg-blue-600 focus:bg-blue-600 ">Largebutton</button>
<button type="button" class="px-2 py-0.5 mb-4 mr-4 text-sm text-white transition-all duration-500 ease-in-out border border-blue-500 bg-blue-500 rounded shadow-md hover:shadow-xl focus:bg-blue-600 hover:bg-blue-600 ">Exsmall</button>
<button type="button" class="px-4 py-1 mb-4 mr-4 text-sm text-white transition-all duration-500 ease-in-out bg-blue-500 border border-blue-500 rounded shadow-md hover:shadow-xl focus:bg-blue-600 hover:bg-blue-600 ">Smallbutton</button>
<button type="button" class="px-6 py-2 mb-4 mr-4 text-white transition-all duration-500 ease-in-out bg-blue-500 border border-blue-500 rounded shadow-md hover:shadow-xl hover:bg-blue-600 focus:bg-blue-600 ">Defaultbutton</button>
<button type="button" class="px-6 py-2 mb-4 mr-4 text-xl text-white transition-all duration-500 ease-in-out bg-blue-500 border border-blue-500 rounded shadow-md hover:shadow-xl hover:bg-blue-600 focus:bg-blue-600 ">Largebutton</button>
Make buttons look inactive by adding the disabled
boolean attribute to any <button>
element. Disabled buttons have pointer-events: none
applied to, preventing hover and active states from triggering.
Disabled buttons using the <a>
element behave a bit different:
<a>
s don’t support the disabled
attribute, so you must add the .disabled
class to make it visually appear disabled.pointer-events
on anchor buttons.aria-disabled="true"
attribute to indicate the state of the element to assistive technologies.
Create responsive stacks of full-width, “block buttons” like those in Bootstrap 4 with a mix of our display and gap utilities. By using utilities instead of button specific classes, we have much greater control over spacing, alignment, and responsive behaviors.
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
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.
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.
If you’re pre-toggling a button, you must manually add the .active
class and aria-pressed="true" to ensure that it is conveyed appropriately to
assistive technologies.
<button type="button" class="px-6 py-2 mb-4 mr-4 transition-all duration-500 ease-in-out border border-transparent rounded shadow-md text-cyan-800 bg-cyan-100 hover:shadow-xl hover:bg-cyan-200 focus:bg-cyan-200 ">Info</button>
<button type="button" class="px-6 py-2 mb-4 mr-4 text-blue-800 transition-all duration-500 ease-in-out bg-blue-100 border border-transparent rounded shadow-md hover:shadow-xl hover:bg-blue-200 focus:bg-blue-200">Primary</button>
<button type="button" class="px-6 py-2 mb-4 mr-4 text-green-800 transition-all duration-500 ease-in-out bg-green-100 border border-transparent rounded shadow-md hover:shadow-xl hover:bg-green-200 focus:bg-green-200">Success</button>
<button type="button" class="px-6 py-2 mb-4 mr-4 text-red-800 transition-all duration-500 ease-in-out bg-red-100 border border-transparent rounded shadow-md hover:shadow-xl hover:bg-red-200 focus:bg-red-200">Danger</button>
<button type="button" class="px-6 py-2 mb-4 mr-4 text-orange-800 transition-all duration-500 ease-in-out bg-orange-100 border border-transparent rounded shadow-md hover:shadow-xl hover:bg-orange-200 focus:bg-orange-200">Warning</button>
<button type="button" class="px-6 py-2 mb-4 mr-4 text-gray-800 transition-all duration-500 ease-in-out bg-gray-100 border border-transparent rounded shadow-md hover:shadow-xl hover:bg-gray-200 focus:bg-gray-200">Light</button>
<button type="button" class="px-6 py-2 mb-4 mr-4 text-gray-900 transition-all duration-500 ease-in-out bg-gray-400 border border-transparent rounded shadow-md hover:shadow-xl hover:bg-gray-500 focus:bg-gray-500">Dark</button>
<button type="button" class="inline-flex px-6 py-2 mb-2 mr-1 text-white transition-all duration-500 ease-in-out bg-blue-500 border border-transparent rounded shadow-md hover:shadow-xl hover:bg-blue-800 focus:bg-primary-200">
<span class="mr-2">
<svg width="24" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z">
</path>
</svg>
</span>Primary
</button>
<button type="button" class="inline-flex px-6 py-2 mb-2 mr-1 text-blue-500 transition-all duration-500 ease-in-out bg-primary-100 border border-blue-500 rounded shadow-md hover:shadow-xl hover:bg-blue-500 hover:text-white focus:bg-primary-200">
<span class="mr-2">
<svg width="24" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z">
</path>
</svg>
</span>Primary
</button>
<button type="button" class="inline-flex px-6 py-2 mb-2 mr-1 text-primary-800 transition-all duration-500 ease-in-out bg-indigo-200 border border-transparent rounded shadow-md hover:shadow-xl hover:bg-indigo-300 focus:bg-primary-200">
<span class="mr-2">
<svg width="24" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z">
</path>
</svg>
</span>Primary
</button>
<button type="button" class="inline-flex px-2 py-2 mb-2 mr-1 text-white transition-all duration-500 ease-in-out bg-blue-500 border border-primary-500 rounded-full shadow-md hover:shadow-xl hover:bg-blue-600 focus:bg-primary-600">
<span>
<svg width="24" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z">
</path>
</svg>
</span>
</button>
<div>
<button type="button" class="inline-flex px-2 py-2 mb-2 mr-1 text-blue-500 transition-all duration-500 ease-in-out border border-blue-500 rounded-full hover:shadow-md hover:bg-blue-500 hover:text-white focus:blue-500">
<span>
<svg width="24" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z">
</path>
</svg>
</span>
</button>
</div>
<div>
<button type="button" class="px-6 py-2 mb-2 mr-1 text-white transition-all duration-500 ease-in-out bg-blue-500 border border-blue-500 rounded-full shadow-md hover:shadow-xl hover:bg-blue-600 focus:bg-primary-600">Primary</button>
</div>
<div>
<button type="button" class="px-6 py-2 mb-2 mr-1 text-blue-500 transition-all duration-500 ease-in-out border border-blue-500 rounded-full hover:shadow-md hover:bg-blue-500 hover:text-white focus:blue-500">Primary</button>
</div>
Icon Size
<div>
<button type="button" class="inline-flex px-2 py-2 text-white transition-all duration-500 ease-in-out bg-blue-500 border border-blue-500 rounded-full shadow-md hover:shadow-xl hover:bg-primary-600 focus:bg-primary-600">
<span>
<svg width="16" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z">
</path>
</svg>
</span>
</button>
<button type="button" class="inline-flex px-2 py-2 text-white transition-all duration-500 ease-in-out bg-blue-500 border border-blue-500 rounded-full shadow-md hover:shadow-xl hover:bg-blue-600 focus:bg-primary-600">
<span>
<svg width="24" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z">
</path>
</svg>
</span>
</button>
<button type="button" class="inline-flex px-1 py-1 text-white transition-all duration-500 ease-in-out bg-blue-500 border border-blue-500 rounded-full shadow-md hover:shadow-xl hover:bg-blue-600 focus:bg-primary-600">
<span>
<svg width="40" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z">
</path>
</svg>
</span>
</button>
</div>