Radios as one joined button group with shared 1px borders, like a view switcher in a project tool. The pick rises above its neighbors with an accent border, a pressed-in tint and an icon pop.
Also known as: css radio group, radio button group css, button group radio buttons, joined radio buttons.
<div class="rad-button-group-radio" role="radiogroup" aria-label="View"> <label><input type="radio" name="rad-button-group-radio" value="list" checked><span><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M8 6h12M8 12h12M8 18h12M4 6h.01M4 12h.01M4 18h.01"/></svg>List</span></label> <label><input type="radio" name="rad-button-group-radio" value="board"><span><svg viewBox="0 0 24 24" aria-hidden="true"><rect x="3" y="4" width="5" height="16" rx="1.5"/><rect x="10" y="4" width="5" height="10" rx="1.5"/><rect x="17" y="4" width="4" height="13" rx="1.5"/></svg>Board</span></label> <label><input type="radio" name="rad-button-group-radio" value="timeline"><span><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 6h9M8 12h11M6 18h8"/></svg>Timeline</span></label> </div>
.rad-button-group-radio {
--c: var(--rad-color, #3b82f6);
font-size: var(--rad-size, 18px);
display: inline-flex;
border-radius: 0.6em;
box-shadow: 0 0.15em 0.3em -0.15em rgb(0 0 0 / 0.15);
font-family: system-ui, sans-serif;
line-height: 1.2;
}
.rad-button-group-radio label {
position: relative;
cursor: pointer;
}
.rad-button-group-radio label + label {
margin-left: -1px;
}
.rad-button-group-radio input {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
z-index: 1;
}
.rad-button-group-radio label span {
position: relative;
display: flex;
align-items: center;
gap: 0.45em;
padding: 0.55em 0.95em;
border: 1px solid color-mix(in srgb, currentColor 18%, transparent);
background: color-mix(in srgb, currentColor 2%, transparent);
font-size: 0.88em;
font-weight: 600;
color: color-mix(in srgb, currentColor 65%, transparent);
transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease, box-shadow 0.25s ease;
}
.rad-button-group-radio label:first-child span {
border-radius: 0.6em 0 0 0.6em;
}
.rad-button-group-radio label:last-child span {
border-radius: 0 0.6em 0.6em 0;
}
.rad-button-group-radio svg {
width: 1.1em;
height: 1.1em;
fill: none;
stroke: currentColor;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
}
.rad-button-group-radio label:hover span {
background: color-mix(in srgb, currentColor 6%, transparent);
color: currentColor;
}
.rad-button-group-radio label:has(:checked) {
z-index: 1;
}
.rad-button-group-radio input:checked + span {
border-color: var(--c);
background: color-mix(in srgb, var(--c) 10%, transparent);
color: var(--c);
box-shadow: inset 0 0.12em 0.25em color-mix(in srgb, var(--c) 18%, transparent);
}
.rad-button-group-radio input:checked + span svg {
animation: rad-button-group-radio-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.rad-button-group-radio label:active span {
box-shadow: inset 0 0.15em 0.35em color-mix(in srgb, currentColor 15%, transparent);
}
.rad-button-group-radio label:has(:focus-visible) {
z-index: 2;
}
.rad-button-group-radio input:focus-visible + span {
outline: 0.12em solid var(--c);
outline-offset: 0.15em;
}
@keyframes rad-button-group-radio-pop {
0% { transform: scale(0.7) rotate(-8deg); }
100% { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
.rad-button-group-radio *,
.rad-button-group-radio *::before,
.rad-button-group-radio *::after {
transition-duration: 0.01ms !important;
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
}
}
@media (prefers-reduced-motion: reduce) {
.rad-button-group-radio, .rad-button-group-radio *, .rad-button-group-radio::before, .rad-button-group-radio::after, .rad-button-group-radio *::before, .rad-button-group-radio *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--rad-color on the element or a parent.
Currently previewing #3b82f6.--rad-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 18px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.