Order summary with a delivery choice in HTML, CSS and vanilla JS
A copy-paste Order summary with a delivery choice in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.
Live preview
Source (copy-ready)
<section class="dcl-order-summary-delivery-choice-root" aria-label="Order summary with a delivery choice" data-dcl-scheme="light">
<h2>Check delivery and total</h2><div class="dcl-order-summary-delivery-choice-scroll"><table><caption>Items in your order</caption><thead><tr><th scope="col">Item</th><th scope="col">Qty</th><th scope="col">Price</th></tr></thead><tbody><tr><th scope="row">Pocket trail guide</th><td>2</td><td>$20.00</td></tr><tr><th scope="row">Waterproof route sheet</th><td>1</td><td>$6.00</td></tr></tbody></table></div><div class="dcl-order-summary-delivery-choice-split"><fieldset><legend>Delivery method</legend><ul class="dcl-order-summary-delivery-choice-stack" role="list"><li><label class="dcl-order-summary-delivery-choice-bar"><input type="radio" name="delivery" value="4" checked> Standard ($4.00)</label></li>
<li><label class="dcl-order-summary-delivery-choice-bar"><input type="radio" name="delivery" value="10"> Express ($10.00)</label></li></ul></fieldset>
<div class="dcl-order-summary-delivery-choice-panel"><dl class="dcl-order-summary-delivery-choice-stack"><div class="dcl-order-summary-delivery-choice-bar dcl-order-summary-delivery-choice-spread"><dt>Items</dt><dd>$26.00</dd></div><div class="dcl-order-summary-delivery-choice-bar dcl-order-summary-delivery-choice-spread"><dt>Delivery</dt><dd>$4.00</dd></div></dl><p role="status">Order total: $30.00</p></div></div>
<script>
(() => {
const root = document.currentScript.closest(".dcl-order-summary-delivery-choice-root");
const preference = matchMedia("(prefers-color-scheme: dark)");
const apply = () => {
root.dataset.dclScheme = document.documentElement.dataset.theme || (preference.matches ? "dark" : "light");
};
preference.addEventListener("change", apply);
apply();
const usd = new Intl.NumberFormat("en-US", {style: "currency", currency: "USD"});
const fields = [...root.querySelectorAll("input")];
const instance = [...document.getElementsByClassName(root.className)].indexOf(root);
fields.forEach((field) => { field.name += "--" + instance; });
const values = root.querySelectorAll("dd");
fields.forEach((field) => field.addEventListener("change", () => {
const cost = Number(field.value);
values[1].textContent = usd.format(cost);
root.querySelector('[role="status"]').textContent = "Order total: " + usd.format(26 + cost);
}));
})();
</script>
</section>
<style>
.dcl-order-summary-delivery-choice-root { color: #11292f; background-color: #ffffff; color-scheme: light; }
.dcl-order-summary-delivery-choice-root .dcl-order-summary-delivery-choice-panel, .dcl-order-summary-delivery-choice-root .dcl-order-summary-delivery-choice-badge,
.dcl-order-summary-delivery-choice-root button, .dcl-order-summary-delivery-choice-root input, .dcl-order-summary-delivery-choice-root select, .dcl-order-summary-delivery-choice-root summary {
color: #11292f; background-color: #e4edef; border-color: #697f84;
}
.dcl-order-summary-delivery-choice-root .dcl-order-summary-delivery-choice-muted { color: #405a60; }
.dcl-order-summary-delivery-choice-root button:hover, .dcl-order-summary-delivery-choice-root button[aria-pressed="true"], .dcl-order-summary-delivery-choice-root summary:hover {
color: #ffffff; background-color: #00535a;
}
.dcl-order-summary-delivery-choice-root a { color: #005c62; }
.dcl-order-summary-delivery-choice-root :focus-visible { outline: 3px solid #005c62; outline-offset: 3px; }
.dcl-order-summary-delivery-choice-root { --edge: #697f84; --accent: #00535a; }
.dcl-order-summary-delivery-choice-root[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; color-scheme: dark; }
.dcl-order-summary-delivery-choice-root[data-dcl-scheme="dark"] .dcl-order-summary-delivery-choice-panel, .dcl-order-summary-delivery-choice-root[data-dcl-scheme="dark"] .dcl-order-summary-delivery-choice-badge,
.dcl-order-summary-delivery-choice-root[data-dcl-scheme="dark"] button, .dcl-order-summary-delivery-choice-root[data-dcl-scheme="dark"] input, .dcl-order-summary-delivery-choice-root[data-dcl-scheme="dark"] select, .dcl-order-summary-delivery-choice-root[data-dcl-scheme="dark"] summary {
color: #eff8f9; background-color: #1c3c44; border-color: #839fa5;
}
.dcl-order-summary-delivery-choice-root[data-dcl-scheme="dark"] .dcl-order-summary-delivery-choice-muted { color: #b0c9ce; }
.dcl-order-summary-delivery-choice-root[data-dcl-scheme="dark"] button:hover, .dcl-order-summary-delivery-choice-root[data-dcl-scheme="dark"] button[aria-pressed="true"], .dcl-order-summary-delivery-choice-root[data-dcl-scheme="dark"] summary:hover {
color: #11292f; background-color: #8fe1da;
}
.dcl-order-summary-delivery-choice-root[data-dcl-scheme="dark"] a { color: #8fe1da; }
.dcl-order-summary-delivery-choice-root[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 3px; }
.dcl-order-summary-delivery-choice-root[data-dcl-scheme="dark"] { --edge: #839fa5; --accent: #8fe1da; }
.dcl-order-summary-delivery-choice-root { display: grid; gap: 1rem; box-sizing: border-box; max-inline-size: 60rem; margin-inline: auto; padding: clamp(0.875rem, 3vw, 2rem);
border: 1px solid var(--edge); border-radius: 0.75rem; font: 1rem/1.55 system-ui, sans-serif; overflow-wrap: anywhere; }
.dcl-order-summary-delivery-choice-root * { box-sizing: border-box; min-inline-size: 0; }
.dcl-order-summary-delivery-choice-root h2, .dcl-order-summary-delivery-choice-root h3, .dcl-order-summary-delivery-choice-root p, .dcl-order-summary-delivery-choice-root ul, .dcl-order-summary-delivery-choice-root ol, .dcl-order-summary-delivery-choice-root dl, .dcl-order-summary-delivery-choice-root dd, .dcl-order-summary-delivery-choice-root figure, .dcl-order-summary-delivery-choice-root blockquote, .dcl-order-summary-delivery-choice-root fieldset { margin: 0; }
.dcl-order-summary-delivery-choice-root h2 { font-size: clamp(1.375rem, 3vw, 2rem); line-height: 1.18; }
.dcl-order-summary-delivery-choice-root h3 { font-size: 1.125rem; line-height: 1.3; }
.dcl-order-summary-delivery-choice-root ul, .dcl-order-summary-delivery-choice-root ol { padding: 0; list-style: none; }
.dcl-order-summary-delivery-choice-panel > * + *, .dcl-order-summary-delivery-choice-disclosure > * + * { margin-block-start: 0.65rem; }
.dcl-order-summary-delivery-choice-stack, .dcl-order-summary-delivery-choice-grid, .dcl-order-summary-delivery-choice-split, .dcl-order-summary-delivery-choice-rail { display: grid; gap: 1rem; align-items: start; }
.dcl-order-summary-delivery-choice-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); }
.dcl-order-summary-delivery-choice-split { grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); }
.dcl-order-summary-delivery-choice-rail { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.dcl-order-summary-delivery-choice-bar { display: flex; flex-wrap: wrap; gap: 0.625rem; align-items: center; }
.dcl-order-summary-delivery-choice-spread { justify-content: space-between; }
.dcl-order-summary-delivery-choice-panel { padding: 1rem; border: 1px solid var(--edge); border-radius: 0.625rem; }
.dcl-order-summary-delivery-choice-badge { display: inline-block; width: fit-content; border: 1px solid var(--edge); border-radius: 1rem;
padding: 0.16rem 0.65rem; font-size: 0.875rem; font-weight: 650; }
.dcl-order-summary-delivery-choice-muted { font-size: 0.875rem; }
.dcl-order-summary-delivery-choice-root button, .dcl-order-summary-delivery-choice-root input, .dcl-order-summary-delivery-choice-root select, .dcl-order-summary-delivery-choice-root summary {
font: inherit; padding: 0.45rem 0.7rem; border: 1px solid; border-radius: 0.375rem; max-inline-size: 100%; }
.dcl-order-summary-delivery-choice-root input[type="checkbox"], .dcl-order-summary-delivery-choice-root input[type="radio"] { inline-size: 1.15rem; block-size: 1.15rem; accent-color: var(--accent); }
.dcl-order-summary-delivery-choice-root button, .dcl-order-summary-delivery-choice-root select, .dcl-order-summary-delivery-choice-root summary, .dcl-order-summary-delivery-choice-root label { cursor: pointer; }
.dcl-order-summary-delivery-choice-root button:disabled { cursor: not-allowed; border-style: dashed; }
.dcl-order-summary-delivery-choice-root button:active, .dcl-order-summary-delivery-choice-root summary:active { text-decoration: underline; }
.dcl-order-summary-delivery-choice-root a { display: inline-block; padding: 0.2rem; text-underline-offset: 0.2em; }
.dcl-order-summary-delivery-choice-root a:hover { text-decoration-thickness: 2px; }
.dcl-order-summary-delivery-choice-root fieldset { padding: 0.75rem; border: 1px solid var(--edge); border-radius: 0.5rem; }
.dcl-order-summary-delivery-choice-root legend { font-weight: 700; padding-inline: 0.35rem; }
.dcl-order-summary-delivery-choice-scroll { overflow-x: auto; padding: 0.2rem; }
.dcl-order-summary-delivery-choice-root table { border-collapse: collapse; inline-size: 100%; text-align: start; }
.dcl-order-summary-delivery-choice-root caption { text-align: start; font-weight: 700; padding-block: 0.375rem; }
.dcl-order-summary-delivery-choice-root td, .dcl-order-summary-delivery-choice-root th { border-block-end: 1px solid var(--edge); padding: 0.5rem; text-align: start; }
.dcl-order-summary-delivery-choice-root svg { display: block; max-inline-size: 100%; block-size: auto; }
.dcl-order-summary-delivery-choice-border { border-inline-start: 0.25rem solid var(--accent); padding-inline-start: 0.875rem; }
.dcl-order-summary-delivery-choice-center { text-align: center; justify-items: center; }
.dcl-order-summary-delivery-choice-center svg { margin-inline: auto; }
.dcl-order-summary-delivery-choice-root [hidden] { display: none; }
.dcl-order-summary-delivery-choice-stack[hidden], .dcl-order-summary-delivery-choice-bar[hidden] { display: none; }
@media (max-width: 34rem) { .dcl-order-summary-delivery-choice-rail { grid-template-columns: minmax(0, 1fr); } }
.dcl-order-summary-delivery-choice-root td, .dcl-order-summary-delivery-choice-root th { overflow-wrap: normal; }
.dcl-order-summary-delivery-choice-root th[scope="col"], .dcl-order-summary-delivery-choice-root td { white-space: nowrap; }
</style>
When to use
Use when shipping changes the total and the order review is the place to select a method. Recalculate and validate payable totals on your server.
Avoid
Do not trust the example's client-side prices for a real checkout.
Accessibility
Native radio buttons group the two alternatives; the polite status reads the updated total without moving focus. Theme token text pairs reach at least 6.2:1 in light and 6.8:1 in dark.
Was this useful? Send feedback.