- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <datalist> Tag
The HTML <datalist> element contains a set of <option> elements that represent acceptable or recommended options available to choose from among other controls.
The HTML <datalist> tag specifies a list of pre-defined options for the <input> element, it provides autocomplete features to an input element, when the user clicks on the input field they will show the dropdown list of pre-defined options. The id attribute of <datalist> tag is equal to the list attribute of an input field.
Syntax
Following is the syntax for HTML <datalist> tag −
<datalist>.......</datalist>
Example
Let's look into the following example, where we are going to use the datalist tag without input element.
<!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>HTML datalist tag</title> </head> <body> <form> <input list="values"> <datalist id="values"> <option value="HTML"> </datalist> </form> </body> </html>
When we run the above code, it will generate an output displaying nothing on the webpage. because we are using the datalist tag without input element.
Example
Considering, the another scenario where we are going to use the datalist tag along with the input element.
<!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>HTML datalist tag</title> </head> <body> <!--create a datalist--> <p>Choose your option</p> <input type="text" list="values"> <datalist id='values'> <option value="HTML">HTML</option> <option value="CSS">CSS</option> <option value="JavaScript">JavaScript</option> </datalist> </body> </html>
On running the above code, the output window will pop up displaying the dropdown list on the webpage.
Example
In the following example, we are going to use the datalist tag with the date and time type.
<!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>HTML datalist tag</title> </head> <body> <!--create a datalist--> <p>Choose your Time</p> <input type="time" list="hours"> <datalist id='hours'> <option value="08:00"></option> <option value="10:00"></option> <option value="12:00"></option> </datalist> </body> </html>
When we run the above code, it will generate an output consisting of the predefined dropdown menu along with a text displayed on the webpage.