Open In App

How to create a Button with Tailwind CSS ?

Last Updated : 05 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Creating a button with Tailwind CSS is straightforward. Apply utility classes like bg-[color], text-[color], py-[padding], and px-[padding] to set the background colour, text colour, and padding for the button.

Syntax

<button class="bg-blue-500 text-white py-2 px-4 rounded-md">
Click me
</button>

Preview

Screenshot-2024-02-02-170906

Button Classes

Property Description
bg-[color] Sets the background colour of the button. Replace [color] with the desired colour name or value.
text-[color] Specifies the text colour of the button. Use [color] for the desired text colour.
py-[padding] Sets the vertical padding of the button. Replace [padding] with the desired vertical padding size.
px-[padding] Sets the horizontal padding of the button. Replace [padding] with the desired horizontal padding size.
rounded-md Applies a medium border-radius to create a rounded appearance for the button, enhancing its visual style.

Key Features

  • Customization: Easily customize button appearance by adjusting background colour, text colour, and padding.
  • Responsive Design: Utilize responsive variants (sm:, md:, lg:, xl:) for adaptive button styles on different screen sizes.
  • Consistency: Tailwind’s utility-first approach ensures consistent button styling throughout the project.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads