How to add an input label for select html tag

Viewed 37

I want to add header text "Selected subscriptions" on my select html tag.
enter image description here

 <div>
  <select name="select"> 
    <option value="value1" selected>Subscription 1</option>
    <option value="value2">Subscription 2</option>
    <option value="value3">Subscription 3</option>
  </select>
</div>

1 Answers

This is called a Input Label in HTML. There are two options to link a label and a form field:

1. Use for and id attributes on label and field respectively

<label for="subscription-select">Selected subscriptions</label>
<select id="subscription-select" name="select">
    <option value="1">Sub 1</option>
</select>

2. Nest form field inside label

<label>
    Selected subscriptions
    <select id="subscription-select" name="select">
        <option value="1">Sub 1</option>
    </select>
</label>
Related