Release Tabs in HTML, CSS and vanilla JS
A copy-paste Release Tabs in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.
Live preview
Source (copy-ready)
<section class="example-release-tabs" data-dcl-layout="stack" data-dcl-scheme="light" aria-labelledby="example-release-tabs-title"><header><h2 id="example-release-tabs-title">Release Tabs</h2></header><div class="parts"><div role="tablist" aria-label="Topics" aria-orientation="horizontal"><button type="button" role="tab" id="example-release-tabs-tab-0" aria-controls="example-release-tabs-panel-0" aria-selected="true" tabindex="0">Overview</button><button type="button" role="tab" id="example-release-tabs-tab-1" aria-controls="example-release-tabs-panel-1" aria-selected="false" tabindex="-1">Fixes</button><button type="button" role="tab" id="example-release-tabs-tab-2" aria-controls="example-release-tabs-panel-2" aria-selected="false" tabindex="-1">Migration</button></div><section role="tabpanel" id="example-release-tabs-panel-0" aria-labelledby="example-release-tabs-tab-0"><p>See what shipped this week.</p></section><section role="tabpanel" id="example-release-tabs-panel-1" aria-labelledby="example-release-tabs-tab-1" hidden><p>Keyboard shortcuts no longer intercept typing.</p></section><section role="tabpanel" id="example-release-tabs-panel-2" aria-labelledby="example-release-tabs-tab-2" hidden><p>Rename the old config key before upgrading.</p></section></div>
<script>
(() => {
const root = document.currentScript.closest(".example-release-tabs");
const instance = Array.from(document.getElementsByClassName("example-release-tabs")).indexOf(root);
if (instance > 0) {
const references = ["id", "aria-labelledby", "aria-controls", "aria-describedby", "for", "name"];
for (const element of [root, ...root.querySelectorAll("*")]) {
for (const attr of references) {
if (element.hasAttribute(attr)) element.setAttribute(attr, element.getAttribute(attr) + "--" + instance);
}
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 tabs = Array.from(root.querySelectorAll('[role="tab"]'));
root.querySelectorAll('[role="tabpanel"]').forEach((panel) => { panel.tabIndex = 0; });
const vertical = root.querySelector('[role="tablist"]').getAttribute("aria-orientation") === "vertical";
function activate(selected) {
tabs.forEach((tab) => {
const active = tab === selected;
tab.setAttribute("aria-selected", String(active));
tab.tabIndex = active ? 0 : -1;
document.getElementById(tab.getAttribute("aria-controls")).hidden = !active;
});
selected.focus();
}
tabs.forEach((tab, index) => {
tab.addEventListener("click", () => activate(tab));
tab.addEventListener("keydown", (event) => {
const next = vertical ? "ArrowDown" : "ArrowRight";
const previous = vertical ? "ArrowUp" : "ArrowLeft";
let indexToSelect;
if (event.key === next) indexToSelect = (index + 1) % tabs.length;
else if (event.key === previous) indexToSelect = (index + tabs.length - 1) % tabs.length;
else if (event.key === "Home") indexToSelect = 0;
else if (event.key === "End") indexToSelect = tabs.length - 1;
else return;
event.preventDefault();
activate(tabs[indexToSelect]);
});
});
})();
</script></section>
<style>
.example-release-tabs { color: #11292f; background-color: #ffffff; color-scheme: light; }
.example-release-tabs a { color: #005c62; }
.example-release-tabs button, .example-release-tabs summary, .example-release-tabs input, .example-release-tabs select {
color: #11292f; background-color: #e4edef; border-color: #697f84;
}
.example-release-tabs button:hover, .example-release-tabs summary:hover, .example-release-tabs button[aria-selected="true"] {
color: #ffffff; background-color: #00535a;
}
.example-release-tabs dialog { color: #11292f; background-color: #ffffff; }
.example-release-tabs [data-note] { color: #11292f; background-color: #e4edef; }
.example-release-tabs :focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }
.example-release-tabs[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; color-scheme: dark; }
.example-release-tabs[data-dcl-scheme="dark"] a { color: #8fe1da; }
.example-release-tabs[data-dcl-scheme="dark"] button, .example-release-tabs[data-dcl-scheme="dark"] summary, .example-release-tabs[data-dcl-scheme="dark"] input, .example-release-tabs[data-dcl-scheme="dark"] select {
color: #eff8f9; background-color: #1c3c44; border-color: #839fa5;
}
.example-release-tabs[data-dcl-scheme="dark"] button:hover, .example-release-tabs[data-dcl-scheme="dark"] summary:hover, .example-release-tabs[data-dcl-scheme="dark"] button[aria-selected="true"] {
color: #11292f; background-color: #8fe1da;
}
.example-release-tabs[data-dcl-scheme="dark"] dialog { color: #eff8f9; background-color: #142f36; }
.example-release-tabs[data-dcl-scheme="dark"] [data-note] { color: #eff8f9; background-color: #1c3c44; }
.example-release-tabs[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 2px; }
.example-release-tabs, .example-release-tabs * { box-sizing: border-box; }
.example-release-tabs { font: 1rem/1.5 system-ui, sans-serif; padding: 1rem; border-radius: 0.75rem; overflow-wrap: anywhere; }
.example-release-tabs h2, .example-release-tabs h3 { line-height: 1.15; margin-block: 0 0.75rem; }
.example-release-tabs p { margin-block: 0.5rem; }
.example-release-tabs ul { margin-block: 0.5rem; padding-inline-start: 1.5rem; }
.example-release-tabs article, .example-release-tabs details, .example-release-tabs [data-note] { border: 1px solid; border-radius: 0.375rem; padding: 0.75rem; }
.example-release-tabs button, .example-release-tabs summary, .example-release-tabs input, .example-release-tabs select {
min-block-size: 44px; border: 1px solid; border-radius: 0.375rem; padding: 0.5rem 0.75rem; font: inherit;
}
.example-release-tabs button, .example-release-tabs summary { cursor: pointer; transition: background-color 140ms ease-out; }
.example-release-tabs button:disabled { cursor: not-allowed; text-decoration: line-through; }
.example-release-tabs input { display: block; inline-size: 100%; }
.example-release-tabs dialog { max-inline-size: min(32rem, 90vw); border-radius: 0.75rem; padding: 1rem; }
.example-release-tabs th, .example-release-tabs td { padding: 0.5rem; text-align: start; border-block-end: 1px solid; }
.example-release-tabs table { border-collapse: collapse; inline-size: 100%; }
.example-release-tabs caption { font-weight: bold; text-align: start; }
.example-release-tabs dt { font-weight: 600; }
.example-release-tabs dd { margin: 0 0 0.75rem; }
.example-release-tabs [hidden] { display: none !important; }
.example-release-tabs .parts { display: grid; gap: 1rem; }
@media (max-width: 30rem) {
.example-release-tabs[data-dcl-layout="rail"] .parts { grid-template-columns: minmax(0, 1fr); }
.example-release-tabs[data-dcl-layout="rail"] .parts > :is(p, ul, article) { grid-column: 1; grid-row: auto; }
.example-release-tabs[data-dcl-layout="rail"] .parts > :is(details, nav) { grid-row: auto; }
}
@media (prefers-reduced-motion: reduce) { .example-release-tabs * { transition: none !important; } }
</style>
When to use
Use this stacked pattern to give each item a full-width row.
Avoid
Use links instead if the destinations should have separate URLs.
Accessibility
Use arrow keys to move between tabs and Tab to move into the active panel.
Was this useful? Send feedback.