← Community home

When are datalist suggestions useful?

Community › Forums › HTML APIs & Embeds › When are datalist suggestions useful?

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 ↗
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #212

    The user should be able to type a custom HTML topic as well as choose suggestions.

    #213

    Detailed answer

    Datalist offers suggestions to a compatible input without forcing selection from them.

    Match the input list attribute to the datalist id. Use select when the person must choose a fixed option. Browser and assistive-technology behavior varies, so test the combinations your users need rather than assuming identical presentation.

    Example

    <label for="topic">HTML topic</label><input id="topic" name="topic" list="topics"><datalist id="topics"><option value="Forms"><option value="Tables"></datalist>

    Understanding the behavior

    Datalist provides suggestions to a compatible input while still allowing other values. It differs from a select, which presents a constrained option set. Browser and assistive-technology experiences vary, so test the actual audience's supported combinations.

    Practical implementation notes

    If the server only accepts certain values, validate that requirement separately. Do not assume that selecting from suggestions is mandatory or that every browser presents the same dropdown interface.

    How to check it

    Associate list with the datalist id and enter a value not among the suggestions.

    Expected result

    The input can accept free text; a fixed-choice rule needs separate validation.

    Watch out: Suggestions are not server-side validation of allowed values.

    Read the reference ↗

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