HTML <option> Tag
The <option> tag represents a selectable item in a dropdown menu. It must be inside a <select> or <optgroup> element. The text content of the option is what users see and can select.
Attributes
The <option> tag can have a value attribute that differs from the displayed text. This is useful when you want to send a different value to the server than what the user sees. The selected attribute marks an option as pre-selected. The disabled attribute makes an option non-selectable.
Common Use Cases
Common use cases include: dropdown menus for forms, country/state selectors, category filters, and any list where users need to choose one option. Options can be grouped with <optgroup> for better organization. Each option represents one choice in the dropdown.
Best Practices
Use <option> inside <select> or <optgroup> elements. Provide meaningful text content that users can understand. Use the value attribute when the submitted value should differ from the displayed text. Use selected for default selections. Consider grouping related options with <optgroup> for better UX.
