Theme
Design your own
On this page (3)
Component Skill — components/address-form/component-skill.md

Native basis

A <fieldset> of labelled Inputs with the standard autocomplete tokens in a 6-column grid (data-span), a country Select, a "billing address is the same" Checkbox - or saved addresses as radio cards.

Built from

Input, Select, Checkbox, Label.

Web Platform APIs

autocomplete<fieldset>Constraint validation:has()<address>Container queries

Classes

.mk-address-form.mk-address-form-grid.mk-address-form-field.mk-address-form-same.mk-address-form-saved.mk-address-form-option.mk-address-form-add

Data attributes

data-span="2|3|4|6" on fields (of 6 columns); .mk-address-form-saved for saved addresses.

§Default

The standard autocomplete tokens on every field - one tap fills it all - in a 6-column grid (data-span) that collapses to one column when narrow. Country first; optional fields say so.

§Saved addresses

.mk-address-form-saved: saved addresses as radio cards (:has(:checked) outlines the choice), each with an edit link, and a way to add a new one.

§CSS view file

/* -- Address Form (website · Shop) ----------------------------------------
   Collects a shipping or billing address - the fields every browser can autofill, laid out in a grid, with saved addresses to pick from. */
@layer components {
  /* every box in the block measures border-box - the same on any page */
  :where(.mk-address-form, .mk-address-form *, .mk-address-form ::before, .mk-address-form ::after) {
    box-sizing: border-box;
  }
  .mk-address-form {
    container: mk-address-form / inline-size;
    display: grid;
    gap: 1rem;
    margin: 0;
    padding: 0;
    border: 0;
    min-width: 0;
    width: 100%;
    & legend {
      margin-block-end: 1rem;
      padding: 0;
      font-size: 1.0625rem;
      font-weight: 600;
    }
  }
  .mk-address-form-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
  }
  .mk-address-form-field {
    display: grid;
    gap: 0.375rem;
    align-content: start;
    & .label small {
      color: var(--muted-foreground);
      font-weight: 400;
    }
  }
  .mk-address-form-same {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
  }
  .mk-address-form-saved {
    display: grid;
    gap: 0.625rem;
  }
  .mk-address-form-option {
    position: relative;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: start;
    gap: 0.25rem 0.875rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    & strong {
      font-size: 0.9375rem;
    }
    & address {
      grid-column: 2;
      color: var(--muted-foreground);
      font-size: 0.875rem;
      font-style: normal;
      line-height: 1.5;
    }
    & a {
      position: relative;
      z-index: 1;
      color: var(--primary);
      font-size: 0.8125rem;
      font-weight: 600;
      text-decoration: none;
    }
    &:has(input:checked) {
      border-color: var(--primary);
      box-shadow: 0 0 0 1px var(--primary);
    }
  }
  .mk-address-form-add {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    width: fit-content;
    color: var(--primary);
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    & svg {
      width: 1rem;
      height: 1rem;
    }
  }
  @container mk-address-form (min-width: 36rem) {
    .mk-address-form-grid {
      grid-template-columns: repeat(6, minmax(0, 1fr));
    }
    .mk-address-form-field {
      grid-column: span 6;
    }
    .mk-address-form-field[data-span="2"] {
      grid-column: span 2;
    }
    .mk-address-form-field[data-span="3"] {
      grid-column: span 3;
    }
    .mk-address-form-field[data-span="4"] {
      grid-column: span 4;
    }
  }
  /* -- Accessibility ------------------------------------------- */
  @media (forced-colors: active) {
    .mk-address-form-option:has(input:checked) {
      border-color: Highlight;
    }
  }
}

Comments, ideas or improvements? Edit this page's source on GitHub