Radio tile cards in HTML, CSS and vanilla JS
A copy-paste Radio tile cards in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.
Live preview
Source (copy-ready)
<section class="example-radio-tile-cards" data-dcl-scheme="light" aria-labelledby="example-radio-tile-cards-title">
<header><h2 id="example-radio-tile-cards-title">Radio tile cards</h2>
<p>Each mutually exclusive plan is a card with enough room for a decision-making description.</p></header>
<div class="parts">
<fieldset>
<legend>Choose a workspace plan</legend>
<div class="tile-grid">
<label class="tile"><input type="radio" name="example-radio-tile-cards-plan" value="starter" checked data-plan><span><strong>Starter</strong><br>Core boards for a team of up to five.</span></label>
<label class="tile"><input type="radio" name="example-radio-tile-cards-plan" value="growth" data-plan><span><strong>Growth</strong><br>Automation and reporting for expanding teams.</span></label>
<label class="tile"><input type="radio" name="example-radio-tile-cards-plan" value="enterprise" data-plan><span><strong>Enterprise</strong><br>Advanced controls, audit logs, and support.</span></label>
</div>
</fieldset>
<p class="status" role="status" aria-live="polite" data-status></p>
</div>
<script>
(() => {
const root = document.currentScript.closest(".example-radio-tile-cards");
const instance = Array.from(document.getElementsByClassName("example-radio-tile-cards")).indexOf(root);
if (instance > 0) {
const singleReferences = ["id", "aria-activedescendant", "for", "list", "name"];
const tokenReferences = ["aria-labelledby", "aria-controls", "aria-describedby"];
for (const element of [root, ...root.querySelectorAll("*")]) {
for (const attr of singleReferences) {
if (element.hasAttribute(attr)) element.setAttribute(attr, element.getAttribute(attr) + "--" + instance);
}
for (const attr of tokenReferences) {
if (element.hasAttribute(attr)) {
const rewritten = element.getAttribute(attr).trim().split(/\s+/).filter(Boolean).map((reference) => reference + "--" + instance);
element.setAttribute(attr, rewritten.join(" "));
}
}
const href = element.getAttribute("href");
if (href && href.startsWith("#")) element.setAttribute("href", href + "--" + instance);
}
}
const preference = matchMedia("(prefers-color-scheme: dark)");
const apply = () => { root.dataset.dclScheme = preference.matches ? "dark" : "light"; };
preference.addEventListener("change", apply);
apply();
const inputs = Array.from(root.querySelectorAll("[data-plan]"));
const status = root.querySelector("[data-status]");
function sync() {
const selected = inputs.find((input) => input.checked);
for (const input of inputs) input.closest(".tile").toggleAttribute("data-active", input.checked);
status.textContent = selected ? selected.value[0].toUpperCase() + selected.value.slice(1) + " plan selected." : "No plan selected.";
}
inputs.forEach((input) => input.addEventListener("change", sync));
sync();
})();
</script></section>
<style>
.example-radio-tile-cards { color: #11292f; background-color: #ffffff; color-scheme: light; }
.example-radio-tile-cards a { color: #005c62; }
.example-radio-tile-cards button, .example-radio-tile-cards summary, .example-radio-tile-cards input, .example-radio-tile-cards select, .example-radio-tile-cards textarea {
color: #11292f; background-color: #e4edef; border-color: #697f84;
}
.example-radio-tile-cards button:hover, .example-radio-tile-cards summary:hover, .example-radio-tile-cards button[aria-selected="true"], .example-radio-tile-cards button[aria-pressed="true"] {
color: #ffffff; background-color: #00535a;
}
.example-radio-tile-cards dialog { color: #11292f; background-color: #ffffff; }
.example-radio-tile-cards [data-note] { color: #11292f; background-color: #e4edef; }
.example-radio-tile-cards [data-error] { color: #7f1d1d; background-color: #fee2e2; }
.example-radio-tile-cards [data-success] { color: #14532d; background-color: #dcfce7; }
.example-radio-tile-cards [data-warning] { color: #713f12; background-color: #fef9c3; }
.example-radio-tile-cards :focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }
.example-radio-tile-cards[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; color-scheme: dark; }
.example-radio-tile-cards[data-dcl-scheme="dark"] a { color: #8fe1da; }
.example-radio-tile-cards[data-dcl-scheme="dark"] button, .example-radio-tile-cards[data-dcl-scheme="dark"] summary,
.example-radio-tile-cards[data-dcl-scheme="dark"] input, .example-radio-tile-cards[data-dcl-scheme="dark"] select, .example-radio-tile-cards[data-dcl-scheme="dark"] textarea {
color: #eff8f9; background-color: #1c3c44; border-color: #839fa5;
}
.example-radio-tile-cards[data-dcl-scheme="dark"] button:hover, .example-radio-tile-cards[data-dcl-scheme="dark"] summary:hover,
.example-radio-tile-cards[data-dcl-scheme="dark"] button[aria-selected="true"], .example-radio-tile-cards[data-dcl-scheme="dark"] button[aria-pressed="true"] {
color: #11292f; background-color: #8fe1da;
}
.example-radio-tile-cards[data-dcl-scheme="dark"] dialog { color: #eff8f9; background-color: #142f36; }
.example-radio-tile-cards[data-dcl-scheme="dark"] [data-note] { color: #eff8f9; background-color: #1c3c44; }
.example-radio-tile-cards[data-dcl-scheme="dark"] [data-error] { color: #fecaca; background-color: #451a1a; }
.example-radio-tile-cards[data-dcl-scheme="dark"] [data-success] { color: #bbf7d0; background-color: #14532d; }
.example-radio-tile-cards[data-dcl-scheme="dark"] [data-warning] { color: #fde68a; background-color: #451a03; }
.example-radio-tile-cards[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 2px; }
.example-radio-tile-cards, .example-radio-tile-cards * { box-sizing: border-box; min-width: 0; }
.example-radio-tile-cards { display: block; font: 1rem/1.5 system-ui, sans-serif; padding: 1rem; border-radius: 0.75rem; overflow-wrap: anywhere; }
.example-radio-tile-cards h2, .example-radio-tile-cards h3 { line-height: 1.15; margin-block: 0 0.75rem; }
.example-radio-tile-cards header p, .example-radio-tile-cards p { margin-block: 0.5rem; }
.example-radio-tile-cards ul, .example-radio-tile-cards ol { margin-block: 0.5rem; padding-inline-start: 1.5rem; }
.example-radio-tile-cards dl { margin-block: 0.5rem; }
.example-radio-tile-cards dt { font-weight: 700; }
.example-radio-tile-cards dd { margin: 0 0 0.6rem; }
.example-radio-tile-cards fieldset { min-inline-size: 0; margin: 0; border: 1px solid; border-radius: 0.5rem; padding: 0.75rem; }
.example-radio-tile-cards legend { padding-inline: 0.25rem; font-weight: 700; }
.example-radio-tile-cards button, .example-radio-tile-cards input, .example-radio-tile-cards select, .example-radio-tile-cards textarea {
min-block-size: 44px; border: 1px solid; border-radius: 0.375rem; padding: 0.5rem 0.75rem; font: inherit;
}
.example-radio-tile-cards input, .example-radio-tile-cards select, .example-radio-tile-cards textarea { display: block; inline-size: 100%; max-inline-size: 100%; }
.example-radio-tile-cards input[type="checkbox"], .example-radio-tile-cards input[type="radio"] {
display: inline-block; inline-size: auto; min-block-size: auto; padding: 0; flex: 0 0 auto;
}
.example-radio-tile-cards input[type="file"] { padding: 0.45rem; }
.example-radio-tile-cards input[type="range"] { padding-inline: 0; }
.example-radio-tile-cards textarea { min-block-size: 6rem; resize: vertical; }
.example-radio-tile-cards button, .example-radio-tile-cards summary { cursor: pointer; transition: background-color 140ms ease-out; }
.example-radio-tile-cards button:disabled { cursor: not-allowed; text-decoration: line-through; }
.example-radio-tile-cards table { border-collapse: collapse; inline-size: 100%; }
.example-radio-tile-cards th, .example-radio-tile-cards td { padding: 0.5rem; text-align: start; border-block-end: 1px solid; }
.example-radio-tile-cards [hidden] { display: none !important; }
.example-radio-tile-cards [data-note], .example-radio-tile-cards [data-error], .example-radio-tile-cards [data-success], .example-radio-tile-cards [data-warning] { border-radius: 0.5rem; padding: 0.65rem; }
.example-radio-tile-cards .parts { display: grid; gap: 1rem; }
.example-radio-tile-cards .field, .example-radio-tile-cards .fields { display: grid; gap: 0.4rem; }
.example-radio-tile-cards .fields { gap: 0.75rem; }
.example-radio-tile-cards .actions, .example-radio-tile-cards .inline-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.example-radio-tile-cards .panel { border: 1px solid; border-radius: 0.5rem; padding: 0.75rem; }
.example-radio-tile-cards .plain-list { margin: 0; padding: 0; list-style: none; }
.example-radio-tile-cards .choice { display: flex; gap: 0.5rem; align-items: flex-start; }
.example-radio-tile-cards .choice input { margin-block-start: 0.25rem; }
.example-radio-tile-cards .choice-stack { display: grid; gap: 0.55rem; }
.example-radio-tile-cards .tile { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.55rem; align-items: start; border: 1px solid; border-radius: 0.5rem; padding: 0.75rem; }
.example-radio-tile-cards .tile[data-active] { border-width: 3px; padding: calc(0.75rem - 2px); }
.example-radio-tile-cards .pill { display: inline-flex; gap: 0.4rem; align-items: center; border: 1px solid; border-radius: 999px; padding: 0.35rem 0.7rem; }
.example-radio-tile-cards .pill[data-active] { border-width: 3px; padding: calc(0.35rem - 2px) calc(0.7rem - 2px); }
.example-radio-tile-cards .hint { font-size: 0.875rem; }
.example-radio-tile-cards .status { min-block-size: 1.5rem; margin-block: 0; }
.example-radio-tile-cards .two-column, .example-radio-tile-cards .split-layout { display: grid; gap: 1rem; }
.example-radio-tile-cards .sticky-panel { position: sticky; inset-block-start: 1rem; align-self: start; }
.example-radio-tile-cards .scroll-x { overflow-x: auto; max-inline-size: 100%; }
.example-radio-tile-cards .visually-hidden {
position: absolute; inline-size: 1px; block-size: 1px; padding: 0; margin: -1px;
overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
@media (min-width: 34rem) {
.example-radio-tile-cards .two-column { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.example-radio-tile-cards .split-layout { grid-template-columns: minmax(0, 1fr) minmax(12rem, 18rem); }
}
@media (max-width: 30rem) {
.example-radio-tile-cards { padding: 0.75rem; }
.example-radio-tile-cards .actions, .example-radio-tile-cards .inline-row { align-items: stretch; }
.example-radio-tile-cards .wizard-steps { grid-template-columns: minmax(0, 1fr) !important; }
}
@media (prefers-reduced-motion: reduce) { .example-radio-tile-cards * { transition: none !important; } }
.example-radio-tile-cards .tile-grid { display: grid; gap: 0.75rem; }
@media (min-width: 34rem) { .example-radio-tile-cards .tile-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
</style>
When to use
Use this when only one option can apply but each choice needs explanation. Keep the number of cards small enough that people can compare them without scrolling back and forth.
Avoid
Do not use large tiles for routine binary choices; a simple radio row is easier to scan and takes less space.
Accessibility
Every card is a label around a native radio input sharing one group name, so arrow keys move between options natively. Selection has a thicker border and written status rather than colour alone. Main text contrast is 15.19:1 light and 13.07:1 dark; controls are 12.78:1 and 10.94:1.
Was this useful? Send feedback.