The HTML5 datalist tag is used to provide a list of predefined options for an input element, such as a text box. The purpose of the datalist tag is to provide the user with a dropdown list of options that they can select from, while still allowing them to enter a custom value if needed. The datalist is associated with an input element via the "list" attribute, which references the id of the datalist. The options within the datalist are defined using option elements.
When the user focuses on the associated input element, they will see a dropdown list of options. They can either select one of the options or type in a custom value. This provides a better user experience compared to a standard text input, as it helps guide the user towards valid inputs and reduces the chance of them entering invalid data.
The datalist tag is a useful tool for improving the user experience on forms and can be used in a variety of contexts, such as providing a list of country names, currency codes, or product names.
<!DOCTYPE html> <html> <head> <title>HTML | Tutor Joes</title> </head> <body> <form> <input placeholder="Enter Login Name" list="myList"> <datalist id="myList"> <option> Ram</option> <option> Sam</option> <option> Kumar</option> <option> Sakthi</option> <option> Ravi</option> </datalist> </form> </body> </html>
This code defines a simple HTML form that contains an input element and a datalist.
When the form is rendered, the user will see a text box with a placeholder text of "Enter Login Name". When the user focuses on the text box, a dropdown list with the options from the datalist will appear, allowing the user to select one of the predefined options or enter a custom value.
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions