HTML list Attribute


The HTML list attribute refers to a <datalist> element that contains pre-defined options for an <input> element in an HTML document.

Syntax

Following is the syntax −

<input list=”text”>

Let us see an example of HTML list Attribute:

Example

Live Demo

<!DOCTYPE html>
<html>
<style>
   body {
      color: #000;
      height: 100vh;
      background-color: #8BC6EC;
      background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%);
      text-align: center;
   }
   input {
      display: block;
      width: 60%;
      margin: 1rem auto;
   }
</style>
<body>
<h1>HTML list Attribute Demo</h1>
<input list="subject" placeholder='Select your elective subject'>
<datalist id='subject'>
<option>Maths</option>
<option>Physics</option>
<option>Economics</option>
</datalist>
</body>
</html>

Output

Updated on: 17-Feb-2021

153 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements