Coding Hubs School of AI – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 8448811540
Back to HTML Notes
Topic #715

option

The <option> element defines a single choice inside a <select> — with a genuinely important distinction between what's displayed and what's actually submitted.

Syntax

<option value="submitted-value">Displayed Text</option>

Basic Example

<select name="course">
    <option value="ds">Data Science & Machine Learning</option>
</select>

Browser output: the dropdown shows "Data Science & Machine Learning" — but if this option is selected and the form is submitted, the server receives only the short value, ds.

How It Works

If value is omitted entirely, the option's own visible text is used as the submitted value instead — but writing an explicit value is almost always clearer and more stable for backend code to work with.

Important Attributes

AttributePurpose
valueWhat's actually submitted — can be completely different from the displayed text
selectedPre-selects this option by default
disabledMakes this specific option unselectable, while still visible (often grayed out)

Real-World Example

<select name="batch">
    <option value="" selected disabled>-- Select a batch --</option>
    <option value="2026-sep">September 2026</option>
    <option value="2026-dec" disabled>December 2026 (Full)</option>
</select>

A batch selector where the placeholder option is both pre-selected and disabled (so it can't be re-chosen after picking a real batch), and one full batch is visible but greyed out and unselectable.

Common Mistakes

  • Assuming the visible text is what gets submitted — always check what value is actually set to
  • Using a vague or inconsistent set of values that don't map cleanly to what the backend expects (like mixing "Data Science" and "ds" across different options)

Best Practices

  • Always set an explicit, backend-friendly value for every option
  • Use disabled for genuinely unavailable choices you still want visible, rather than hiding them entirely

Accessibility Considerations

Screen readers announce both the visible option text and its disabled state when applicable — the underlying value itself is never announced, since it's purely a data-submission detail, not user-facing content.

SEO Considerations

No direct ranking effect.

Browser & Modern HTML Notes

<optgroup> can wrap related <option>s under a bold, unselectable group label within a long dropdown — worth knowing for select lists with many categorized choices.

Mini Practice

  1. Build a dropdown where the displayed text and the submitted value are deliberately different.
  2. Add a disabled option representing a sold-out choice.

Related HTML Notes

Want to go beyond the notes?

Join Coding Hubs School of AI's HTML course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →