Mallika Iyer Mallika Iyer - 3 months ago 8
CSS Question

How to set the id of a 'label' HTML element?

If I have the following:

<label for="deletetxt">Delete This Text</label>


What is the 'for' attribute here? Is that the id?

Assuming that I cannot set a class for the label element to style the label element, how do i set css for this element?

Answer

Two question, two answers:

  1. What is the 'for' attribute here?

    It's here to tell the ID of the <input> element that label refers to. Some browsers will use it to set focus on that <input> element when user clicks on that <LABEL>

  2. how do i set css for this element?

    A. If you want to CSS all label elements :

      label {
         /* your styles */
      }

B. If you want to label that element, just use IDs or classnames as you usually do.

Comments