AI CSS Animations

Radio Group with Descriptions

A settings radio group in a real fieldset and legend, each option with a title and a muted description. The picked row tints, and its dot springs in and sends out one soft halo ripple.

Also known as: css radio group, radio group with description, radio button with helper text, fieldset radio group css.

Email notifications

HTML

<fieldset class="rad-described-radio-group">
  <legend>Email notifications</legend>
  <label><input type="radio" name="rad-described-radio-group" value="all"><span class="rad-described-radio-group-text"><span class="rad-described-radio-group-title">Everything</span><span class="rad-described-radio-group-desc">Comments, mentions and deploys</span></span></label>
  <label><input type="radio" name="rad-described-radio-group" value="mentions" checked><span class="rad-described-radio-group-text"><span class="rad-described-radio-group-title">Mentions only</span><span class="rad-described-radio-group-desc">Only when someone tags you by name</span></span></label>
  <label><input type="radio" name="rad-described-radio-group" value="none"><span class="rad-described-radio-group-text"><span class="rad-described-radio-group-title">Nothing</span><span class="rad-described-radio-group-desc">Keep alerts in the app, skip the inbox</span></span></label>
</fieldset>

CSS

.rad-described-radio-group {
  --c: var(--rad-color, #3b82f6);
  font-size: var(--rad-size, 18px);
  display: grid;
  gap: 0;
  min-width: 0;
  width: 17em;
  margin: 0;
  padding: 0;
  border: 0;
  font-family: system-ui, sans-serif;
  line-height: 1.2;
}
.rad-described-radio-group legend {
  padding: 0 0 0.3em 0.6em;
  font-size: 0.75em;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: color-mix(in srgb, currentColor 50%, transparent);
}
.rad-described-radio-group label {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 0.7em;
  padding: 0.3em 0.6em;
  border-radius: 0.6em;
  cursor: pointer;
  transition: background-color 0.25s ease;
}
.rad-described-radio-group label:hover {
  background: color-mix(in srgb, currentColor 5%, transparent);
}
.rad-described-radio-group label:has(:checked) {
  background: color-mix(in srgb, var(--c) 9%, transparent);
}
.rad-described-radio-group input {
  -webkit-appearance: none;
  appearance: none;
  display: grid;
  place-content: center;
  width: 1.1em;
  height: 1.1em;
  margin: 0.05em 0 0;
  border: 0.1em solid color-mix(in srgb, currentColor 32%, transparent);
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.15s ease;
}
.rad-described-radio-group input::before {
  content: "";
  width: 0.52em;
  height: 0.52em;
  border-radius: 50%;
  background: var(--c);
  transform: scale(0);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.rad-described-radio-group input:checked {
  border-color: var(--c);
  animation: rad-described-radio-group-halo 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}
.rad-described-radio-group input:checked::before {
  transform: scale(1);
}
.rad-described-radio-group input:active {
  transform: scale(0.86);
}
.rad-described-radio-group input:focus-visible {
  outline: 0.12em solid var(--c);
  outline-offset: 0.18em;
}
.rad-described-radio-group-text {
  display: grid;
  gap: 0.1em;
}
.rad-described-radio-group-title {
  font-size: 0.92em;
  font-weight: 600;
}
.rad-described-radio-group-desc {
  font-size: 0.76em;
  color: color-mix(in srgb, currentColor 55%, transparent);
}
@keyframes rad-described-radio-group-halo {
  from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c) 45%, transparent); }
  to { box-shadow: 0 0 0 0.55em color-mix(in srgb, var(--c) 0%, transparent); }
}
@media (prefers-reduced-motion: reduce) {
  .rad-described-radio-group *,
  .rad-described-radio-group *::before,
  .rad-described-radio-group *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rad-described-radio-group, .rad-described-radio-group *, .rad-described-radio-group::before, .rad-described-radio-group::after, .rad-described-radio-group *::before, .rad-described-radio-group *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --rad-color on the element or a parent. Currently previewing #3b82f6.
  • Size: set --rad-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 18px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar radio buttons