Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a title to a html select tag

Tags:

html

How would I go about setting a title in select tag? Here is my select box:

<select>     <option value="sydney">Sydney</option>     <option value="melbourne">Melbourne</option>     <option value="cromwell">Cromwell</option>     <option value="queenstown">Queenstown</option> </select> 

When I visit the site, by default it shows "Sydney". But I want to display a title, such as, "What is the name of your city?"

like image 548
Alamin Avatar asked Aug 12 '13 05:08

Alamin


People also ask

How do you add a title to a selection in HTML?

use the title ("Choose one") as the value. So better add explicitly a value="".

What is the title attribute in HTML?

HTML title Attribute The title attribute specifies extra information about an element. The information is most often shown as a tooltip text when the mouse moves over the element. The title attribute can be used on any HTML element (it will validate on any HTML element.


1 Answers

<select>     <option selected disabled>Choose one</option>     <option value="sydney">Sydney</option>     <option value="melbourne">Melbourne</option>     <option value="cromwell">Cromwell</option>     <option value="queenstown">Queenstown</option> </select> 

Using selected and disabled will make "Choose one" be the default selected value, but also make it impossible for the user to actually select the item, like so:

Dropdown menu

like image 196
kba Avatar answered Sep 24 '22 02:09

kba