Kinda Code
Home/HTML & CSS/Tailwind CSS: Create a Button with Gradient Background

Tailwind CSS: Create a Button with Gradient Background

Last updated: March 03, 2023

In TailwindCSS, you can implement color linear gradients by using bg-gradient-{direction}, from-{color}. via-{color}, and to-{color} utilities.

The quick example below creates a button with a gradient background.

Screenshot:

The code:

<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.tailwindcss.com"></script>
    <title>KindaCode.com</title>
</head>

<body>
    <div class="m-10">
        <button class="w-48 h-12 rounded-full text-white
        bg-gradient-to-r from-purple-500 via-red-500 to-yellow-500">
            Button
        </button>
    </div>
</body>

</html>

That’s it. Further reading:

You can also check out our CSS category page for the latest tutorials and examples.