Component Library

← Back to gallery

Delivery Form Fields in HTML, CSS and vanilla JS

A copy-paste Delivery Form Fields in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.

Category: Forms · Tags: form field, stack, form, input

Live preview

Source (copy-ready)

<section class="example-delivery-form-fields" data-dcl-layout="stack" data-dcl-scheme="light" aria-labelledby="example-delivery-form-fields-title"><header><h2 id="example-delivery-form-fields-title">Delivery Form Fields</h2></header><div class="parts"><div><label for="example-delivery-form-fields-field-0">Recipient</label><input type="text" id="example-delivery-form-fields-field-0" aria-describedby="example-delivery-form-fields-hint-0"><p id="example-delivery-form-fields-hint-0">Enter the name on the delivery address.</p></div><div><label for="example-delivery-form-fields-field-1">Building</label><input type="text" id="example-delivery-form-fields-field-1" aria-describedby="example-delivery-form-fields-hint-1"><p id="example-delivery-form-fields-hint-1">Include a unit or floor number.</p></div><div><label for="example-delivery-form-fields-field-2">Instructions</label><input type="text" id="example-delivery-form-fields-field-2" aria-describedby="example-delivery-form-fields-hint-2"><p id="example-delivery-form-fields-hint-2">Describe where to leave the parcel.</p></div></div>
<script>
(() => {
  const root = document.currentScript.closest(".example-delivery-form-fields");
  const instance = Array.from(document.getElementsByClassName("example-delivery-form-fields")).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-delivery-form-fields { color: #11292f; background-color: #ffffff; color-scheme: light; }
.example-delivery-form-fields a { color: #005c62; }
.example-delivery-form-fields button, .example-delivery-form-fields summary, .example-delivery-form-fields input, .example-delivery-form-fields select {
  color: #11292f; background-color: #e4edef; border-color: #697f84;
}
.example-delivery-form-fields button:hover, .example-delivery-form-fields summary:hover, .example-delivery-form-fields button[aria-selected="true"] {
  color: #ffffff; background-color: #00535a;
}
.example-delivery-form-fields dialog { color: #11292f; background-color: #ffffff; }
.example-delivery-form-fields [data-note] { color: #11292f; background-color: #e4edef; }
.example-delivery-form-fields :focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }


.example-delivery-form-fields[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; color-scheme: dark; }
.example-delivery-form-fields[data-dcl-scheme="dark"] a { color: #8fe1da; }
.example-delivery-form-fields[data-dcl-scheme="dark"] button, .example-delivery-form-fields[data-dcl-scheme="dark"] summary, .example-delivery-form-fields[data-dcl-scheme="dark"] input, .example-delivery-form-fields[data-dcl-scheme="dark"] select {
  color: #eff8f9; background-color: #1c3c44; border-color: #839fa5;
}
.example-delivery-form-fields[data-dcl-scheme="dark"] button:hover, .example-delivery-form-fields[data-dcl-scheme="dark"] summary:hover, .example-delivery-form-fields[data-dcl-scheme="dark"] button[aria-selected="true"] {
  color: #11292f; background-color: #8fe1da;
}
.example-delivery-form-fields[data-dcl-scheme="dark"] dialog { color: #eff8f9; background-color: #142f36; }
.example-delivery-form-fields[data-dcl-scheme="dark"] [data-note] { color: #eff8f9; background-color: #1c3c44; }
.example-delivery-form-fields[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 2px; }

.example-delivery-form-fields, .example-delivery-form-fields * { box-sizing: border-box; }
.example-delivery-form-fields { font: 1rem/1.5 system-ui, sans-serif; padding: 1rem; border-radius: 0.75rem; overflow-wrap: anywhere; }
.example-delivery-form-fields h2, .example-delivery-form-fields h3 { line-height: 1.15; margin-block: 0 0.75rem; }
.example-delivery-form-fields p { margin-block: 0.5rem; }
.example-delivery-form-fields ul { margin-block: 0.5rem; padding-inline-start: 1.5rem; }
.example-delivery-form-fields article, .example-delivery-form-fields details, .example-delivery-form-fields [data-note] { border: 1px solid; border-radius: 0.375rem; padding: 0.75rem; }
.example-delivery-form-fields button, .example-delivery-form-fields summary, .example-delivery-form-fields input, .example-delivery-form-fields select {
  min-block-size: 44px; border: 1px solid; border-radius: 0.375rem; padding: 0.5rem 0.75rem; font: inherit;
}
.example-delivery-form-fields button, .example-delivery-form-fields summary { cursor: pointer; transition: background-color 140ms ease-out; }
.example-delivery-form-fields button:disabled { cursor: not-allowed; text-decoration: line-through; }
.example-delivery-form-fields input { display: block; inline-size: 100%; }
.example-delivery-form-fields dialog { max-inline-size: min(32rem, 90vw); border-radius: 0.75rem; padding: 1rem; }
.example-delivery-form-fields th, .example-delivery-form-fields td { padding: 0.5rem; text-align: start; border-block-end: 1px solid; }
.example-delivery-form-fields table { border-collapse: collapse; inline-size: 100%; }
.example-delivery-form-fields caption { font-weight: bold; text-align: start; }
.example-delivery-form-fields dt { font-weight: 600; }
.example-delivery-form-fields dd { margin: 0 0 0.75rem; }
.example-delivery-form-fields [hidden] { display: none !important; }
.example-delivery-form-fields .parts { display: grid; gap: 1rem; }

@media (max-width: 30rem) {
  .example-delivery-form-fields[data-dcl-layout="rail"] .parts { grid-template-columns: minmax(0, 1fr); }
  .example-delivery-form-fields[data-dcl-layout="rail"] .parts > :is(p, ul, article) { grid-column: 1; grid-row: auto; }
  .example-delivery-form-fields[data-dcl-layout="rail"] .parts > :is(details, nav) { grid-row: auto; }
}
@media (prefers-reduced-motion: reduce) { .example-delivery-form-fields * { transition: none !important; } }
</style>

When to use

Use this stacked pattern to give each item a full-width row.

Avoid

Do not use placeholders in place of labels or visible instructions.

Accessibility

Associate every visible label and supporting hint with its input.

Was this useful? Send feedback.