A shipping form can offer a short list of delivery speeds. An HTML select menu displays those choices in a dropdown and sends the chosen value when the form is submitted.

A visible label gives the menu a name that screen readers can announce. The browser associates the label with the menu when the label's for matches the menu's id.

The text of a choice can change when a page is translated. An explicit value lets code that receives the form identify the choice even when readers see it in another language.

Steps to create an HTML select menu:

  1. Create a file named delivery.html in an empty test folder served by your local development server.
  2. Add the page structure with its test form to delivery.html in your text editor.
    delivery.html
    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>Delivery options</title>
    </head>
    <body>
      <h1>Delivery options</h1>
      <form action="delivery.html" method="get">
        <button type="submit">Check delivery</button>
      </form>
    </body>
    </html>

    The form sends a GET request to the same HTML page, so the submitted data appears in the URL without any server-side form code.

  3. Insert the labeled shipping menu immediately before the Check delivery button in the form.
        <label for="delivery-speed">Shipping speed</label>
        <select id="delivery-speed" name="shipping">
          <option value="standard">Standard shipping</option>
          <option value="express">Express shipping</option>
        </select>

    The select's name supplies the query parameter name. The selected option's value supplies its value, so choosing Express shipping sends shipping=express.

  4. Save delivery.html.
  5. Open delivery.html at its local preview URL in Chrome.

    If your local server uses port 8000 and serves the test folder as its root, the URL is http://localhost:8000/delivery.html.

  6. Expand the Shipping speed menu.
  7. Choose Express shipping.
  8. Click Check delivery.
  9. Verify that Delivery options reloads with shipping=express in the browser's address bar.

    The static page shows Standard shipping again after it reloads. The query shows the value the browser sent. The check fails if an error page appears or the query has a missing or different shipping value.

Share this guide