Labels are used to tell the user what data they are expected to enter into a form field. In our last exercise, we built a search form. But how will the user know what they are expected to do? You need to make the form more "user-friendly".
In this exercise, you will add a label to the search field. Follow the steps below to add a label and connect it to your search field.
- Add a
<label>
above the<input>
field. The text in this element should beSearch on Google
. - Add an
id
attribute to the<input>
field. Theid
should besearch-input
. - Connect the
<label>
to the<input>
field by adding afor
attribute to the<label>
. Thefor
attribute should match theid
of the<input>
.
If you have done this correctly, you should see "Search on Google" appear above the label. When you click "Search on Google", it should move your focus to the search field.