The Material pattern in plain CSS: a soft halo on hover, a ripple that spreads and fades when you check it, and a tick that draws across the filled box. Box and halo follow Material's proportions.
Also known as: material checkbox css, ripple checkbox, material ui checkbox.
<label class="chk-material-checkbox">
<input type="checkbox">
<span class="chk-material-checkbox-box">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4.5 12.5l5 5L19.5 7"/></svg>
</span>
Show notifications
</label>.chk-material-checkbox {
--c: var(--chk-color, #3b82f6);
font-size: var(--chk-size, 24px);
position: relative;
display: inline-flex;
align-items: center;
gap: 0.6em;
font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
line-height: 1.3;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
isolation: isolate;
gap: 0.75em;}
.chk-material-checkbox input {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
z-index: 1;
}
.chk-material-checkbox-box {
position: relative;
box-sizing: border-box;
display: grid;
place-items: center;
flex: none;
width: 1.125em;
height: 1.125em;
border: 0.125em solid color-mix(in srgb, currentColor 60%, transparent);
border-radius: 0.125em;
transition: background-color 0.15s ease, border-color 0.15s ease;
}
.chk-material-checkbox-box::before {
content: "";
position: absolute;
z-index: -1;
left: 50%;
top: 50%;
width: 2.5em;
height: 2.5em;
margin: -1.25em 0 0 -1.25em;
border-radius: 50%;
background: currentColor;
opacity: 0;
transform: scale(0.5);
transition: opacity 0.2s ease, transform 0.2s ease;
}
.chk-material-checkbox-box svg {
display: block;
fill: none;
stroke-linecap: round;
stroke-linejoin: round;
width: 0.85em;
height: 0.85em;
stroke: #fff;
stroke-width: 3.4;
stroke-dasharray: 23;
stroke-dashoffset: 23;
transition: stroke-dashoffset 0.1s linear;
}
.chk-material-checkbox:hover .chk-material-checkbox-box::before {
opacity: 0.07;
transform: scale(1);
}
.chk-material-checkbox input:active + .chk-material-checkbox-box::before {
opacity: 0.16;
transform: scale(1);
}
.chk-material-checkbox input:checked + .chk-material-checkbox-box {
background: var(--c);
border-color: var(--c);
}
.chk-material-checkbox input:checked + .chk-material-checkbox-box::before {
background: var(--c);
animation: chk-material-checkbox-ripple 0.55s cubic-bezier(0.2, 0, 0, 1);
}
.chk-material-checkbox input:checked + .chk-material-checkbox-box svg {
stroke-dashoffset: 0;
transition: stroke-dashoffset 0.25s cubic-bezier(0.4, 0, 0.2, 1) 0.08s;
}
.chk-material-checkbox input:focus-visible + .chk-material-checkbox-box::before {
opacity: 0.18;
transform: scale(1);
}
.chk-material-checkbox input:focus-visible + .chk-material-checkbox-box {
outline: 0.125em solid var(--c);
outline-offset: 0.18em;
}
@keyframes chk-material-checkbox-ripple {
from { opacity: 0.35; transform: scale(0.4); }
to { opacity: 0; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
.chk-material-checkbox, .chk-material-checkbox *, .chk-material-checkbox::before, .chk-material-checkbox::after, .chk-material-checkbox *::before, .chk-material-checkbox *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--chk-color on the element or a parent.
Currently previewing #3b82f6.--chk-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 24px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.