<div class="gradient">CSS Gradient</div>
<div class="gradient__css__custom">CSS Gradient with CSS Custom Property</div>
<div class="gradient__css__houdini">CSS Gradient with CSS Houdini</div>
@import url("https://fonts.googleapis.com/css2?family=Exo:wght@600&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
width: 100vw;
min-height: 100vh;
font-family: "Exo", Arial, sans-serif;
background-color: #222;
color: #fff;
display: flex;
justify-content: center;
align-items: center;
font-size: 1.5rem;
gap: 10px;
}
div {
display: flex;
justify-content: center;
align-items: center;
border-radius: 10rem;
padding: 10px 30px;
min-height: 90px;
cursor: pointer;
}
.gradient {
background-image: linear-gradient(to right, #0f9, #09f);
transition: all 0.28s linear;
}
.gradient:hover {
color: #f36;
background-image: linear-gradient(to right, #09f, #0f9);
}
.gradient__css__custom {
--colorStar: #ff9500;
--colorStop: #b320b0;
background-image: linear-gradient(
to right,
var(--colorStar),
var(--colorStop)
);
transition: --colorStart 0.28s linear, --colorStop 0.28s linear;
}
.gradient__css__custom:hover {
background-image: linear-gradient(
to right,
var(--colorStop),
var(--colorStar)
);
}
@property --startColor {
syntax: "<color>";
initial-value: magenta;
inherits: false;
}
@property --stopColor {
syntax: "<color>";
initial-value: magenta;
inherits: false;
}
@property --stop {
syntax: "<percentage>";
initial-value: 50%;
inherits: false;
}
.gradient__css__houdini {
--startColor: #2196f3;
--stopColor: #ff9800;
transition: --stop 0.5s, --startColor 0.2s, --stopColor 0.2s;
background: linear-gradient(
to right,
var(--startColor) var(--stop),
var(--stopColor)
);
}
.gradient__css__houdini:hover {
--startColor: #ff9800;
--stopColor: #2196f3;
--stop: 80%;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.