Shipping FAQ in HTML, CSS and vanilla JS
A copy-paste Shipping FAQ in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.
Live preview
Source (copy-ready)
<section class="example-shipping-faq" data-dcl-layout="compact" data-dcl-scheme="light" aria-labelledby="example-shipping-faq-title"><header><h2 id="example-shipping-faq-title">Shipping FAQ</h2></header><div class="parts"><details open><summary>Pickup</summary><p>Collect any time before 5 p.m.</p></details><details><summary>Tracking</summary><p>Use the link in your dispatch email.</p></details><details><summary>Returns</summary><p>Print the prepaid label within 14 days.</p></details></div>
<script>
(() => {
const root = document.currentScript.closest(".example-shipping-faq");
const instance = Array.from(document.getElementsByClassName("example-shipping-faq")).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();
})();
</script></section>
<style>
.example-shipping-faq { color: #11292f; background-color: #ffffff; color-scheme: light; }
.example-shipping-faq a { color: #005c62; }
.example-shipping-faq button, .example-shipping-faq summary, .example-shipping-faq input, .example-shipping-faq select {
color: #11292f; background-color: #e4edef; border-color: #697f84;
}
.example-shipping-faq button:hover, .example-shipping-faq summary:hover, .example-shipping-faq button[aria-selected="true"] {
color: #ffffff; background-color: #00535a;
}
.example-shipping-faq dialog { color: #11292f; background-color: #ffffff; }
.example-shipping-faq [data-note] { color: #11292f; background-color: #e4edef; }
.example-shipping-faq :focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }
.example-shipping-faq[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; color-scheme: dark; }
.example-shipping-faq[data-dcl-scheme="dark"] a { color: #8fe1da; }
.example-shipping-faq[data-dcl-scheme="dark"] button, .example-shipping-faq[data-dcl-scheme="dark"] summary, .example-shipping-faq[data-dcl-scheme="dark"] input, .example-shipping-faq[data-dcl-scheme="dark"] select {
color: #eff8f9; background-color: #1c3c44; border-color: #839fa5;
}
.example-shipping-faq[data-dcl-scheme="dark"] button:hover, .example-shipping-faq[data-dcl-scheme="dark"] summary:hover, .example-shipping-faq[data-dcl-scheme="dark"] button[aria-selected="true"] {
color: #11292f; background-color: #8fe1da;
}
.example-shipping-faq[data-dcl-scheme="dark"] dialog { color: #eff8f9; background-color: #142f36; }
.example-shipping-faq[data-dcl-scheme="dark"] [data-note] { color: #eff8f9; background-color: #1c3c44; }
.example-shipping-faq[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 2px; }
.example-shipping-faq, .example-shipping-faq * { box-sizing: border-box; }
.example-shipping-faq { font: 1rem/1.5 system-ui, sans-serif; padding: 1rem; border-radius: 0.75rem; overflow-wrap: anywhere; }
.example-shipping-faq h2, .example-shipping-faq h3 { line-height: 1.15; margin-block: 0 0.75rem; }
.example-shipping-faq p { margin-block: 0.5rem; }
.example-shipping-faq ul { margin-block: 0.5rem; padding-inline-start: 1.5rem; }
.example-shipping-faq article, .example-shipping-faq details, .example-shipping-faq [data-note] { border: 1px solid; border-radius: 0.375rem; padding: 0.75rem; }
.example-shipping-faq button, .example-shipping-faq summary, .example-shipping-faq input, .example-shipping-faq select {
min-block-size: 44px; border: 1px solid; border-radius: 0.375rem; padding: 0.5rem 0.75rem; font: inherit;
}
.example-shipping-faq button, .example-shipping-faq summary { cursor: pointer; transition: background-color 140ms ease-out; }
.example-shipping-faq button:disabled { cursor: not-allowed; text-decoration: line-through; }
.example-shipping-faq input { display: block; inline-size: 100%; }
.example-shipping-faq dialog { max-inline-size: min(32rem, 90vw); border-radius: 0.75rem; padding: 1rem; }
.example-shipping-faq th, .example-shipping-faq td { padding: 0.5rem; text-align: start; border-block-end: 1px solid; }
.example-shipping-faq table { border-collapse: collapse; inline-size: 100%; }
.example-shipping-faq caption { font-weight: bold; text-align: start; }
.example-shipping-faq dt { font-weight: 600; }
.example-shipping-faq dd { margin: 0 0 0.75rem; }
.example-shipping-faq [hidden] { display: none !important; }
.example-shipping-faq .parts { display: grid; gap: 0.375rem; max-inline-size: 25rem; } .example-shipping-faq li { display: inline-block; margin-inline-end: 0.75rem; }
@media (max-width: 30rem) {
.example-shipping-faq[data-dcl-layout="rail"] .parts { grid-template-columns: minmax(0, 1fr); }
.example-shipping-faq[data-dcl-layout="rail"] .parts > :is(p, ul, article) { grid-column: 1; grid-row: auto; }
.example-shipping-faq[data-dcl-layout="rail"] .parts > :is(details, nav) { grid-row: auto; }
}
@media (prefers-reduced-motion: reduce) { .example-shipping-faq * { transition: none !important; } }
</style>
When to use
Use this compact arrangement when the details are short and space is limited.
Avoid
Keep critical information visible rather than requiring a disclosure.
Accessibility
Keep each summary descriptive so native Enter and Space activation are useful.
Was this useful? Send feedback.