Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
CSS background gradient transition on hover example
<!doctype html>
<title>Gradient Transition Example</title>
<link href="^1.0/dist/tailwind.min.css" rel="stylesheet">
.card {
position: relative;
background: linear-gradient(to bottom, #90cdf4, #2c5282)
.card:after {
content: '';
opacity: 0;
position: absolute;
z-index: 1;
top: 0;
left: 0;
bottom: 0;
right: 0;
border-radius: inherit;
transition: opacity .3s;
background: linear-gradient(to bottom, red, purple)
.card:hover:after {
opacity: 1;
<body class="grid place-items-center min-h-screen">
<div class="card py-6 px-10 rounded-xl text-center">
<div class="relative z-10">
<h1 class="font-semibold text-lg text-white mb-1">
Animate My Background Gradient
<h2 class="text-gray-500">With Pseudo Classes</h2>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment