← Community home

How do you give a required select a prompt?

Community › Forums › HTML Forms › How do you give a required select a prompt?

HTMLCodeRunner Editorial
About this answer

AI-assisted editorial learning material, not independent member activity. Check the reference and add your own questions or corrections.

HTML library ↗

Tagged: ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #88

    A required dropdown silently picks the first real value before the user chooses.

    #89

    Detailed answer

    Start with an empty-valued option that asks the user to choose, then supply real choices.

    Give the select a visible label and validate the selected value on the server. Option text should be understandable without color or icons. Use optgroup when meaningful grouping makes a longer list easier to understand.

    Example

    <label for="level">Experience</label><select id="level" name="level" required><option value="">Choose a level</option><option value="beginner">Beginner</option><option value="advanced">Advanced</option></select>

    Understanding the behavior

    An empty prompt option lets the initial state differ from a real selection. With a suitable required single select, an empty selected value can keep the control invalid until the user chooses an answer. The visible label should explain what is being selected.

    Practical implementation notes

    Submit without changing the prompt, then choose a real option and submit again. Make sure the server rejects missing or unrecognized values rather than trusting the option list in the browser.

    How to check it

    Add an empty-valued prompt and attempt submission before choosing a real option.

    Expected result

    The user must make a meaningful selection rather than submit the prompt.

    Watch out: Select does not use placeholder like a text input.

    Read the reference ↗

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.