<option> - HTML CSS HTML Tag

HTML CSS examples for HTML Tag:option

Introduction

Item Value
Element: option
Element Type:N/A
Permitted Parents: datalist, select, optgroup
Local Attributes:disabled, selected, label, value
Contents:Character data
Tag Style: Void or start and end
New in HTML5?No
Changes in HTML5:None
Style Convention:None

The following code shows the datalist and option elements used to create a set of values for a text box.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
   <head> 
      <title>Example</title> 
   </head> 
   <body> 
      <form method="post" action="http://example.com/form"> 
         <p> 
            <label for="name">
                Name: <!--  w  ww .j  a  v a  2s.c  o m-->
               <input placeholder="Your name" id="name" name="name"> 
            </label> 
         </p> 
         <p> 
            <label for="city">
                City: 
               <input placeholder="Where you live" id="city" name="city"> 
            </label> 
         </p> 
         <p> 
            <label for="fave">
                Fruit: 
               <input list="fruitlist" id="fave" name="fave"> 
            </label> 
         </p> 
         <button type="submit">Submit Vote</button> 
      </form> 
      <datalist id="fruitlist"> 
         <option value="CSS" label="CSS"></option> 
         <option value="HTML">HTML</option> 
         <option value="Oracle"></option> 
      </datalist>  
   </body>
</html>

Related Tutorials