albert.walickihire me
← all solutions
html

How to add a placeholder for HTML <select> component?

Show placeholder text in a select dropdown with a disabled, selected first option.

To add a placeholder to a <select> element in HTML, you can use the <option> element as the placeholder and give it the disabled and selected attributes. Here is an example:

<select>
  <option disabled selected>Select an option</option>
  <option value="op1">Option 1</option>
  <option value="op2">Option 2</option>
  <option value="op3">Option 3</option>
</select>

This prevents the user from selecting this option from the dropdown menu and instead creates a <select> element with the placeholder "Select an option." The placeholder will appear in the dropdown menu when the user clicks the <select> element, but it won't be selectable. The placeholder will be changed to the selected option whenever the user chooses one of the other choices.

more solutions
work with me

Got something that needs building?

Frontend builds, full-stack features in Django, design-system work. Available for work.

See my workGet in touch