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?"
use the title ("Choose one") as the value. So better add explicitly a value="".
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.
<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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With