Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

css

label

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?

like image 965
Mallika Iyer Avatar asked Apr 27 '10 22:04

Mallika Iyer


People also ask

Can you put an id on a label HTML?

An id on a <label> tag assigns an identifier to the label. The identifier must be unique across the page.

How do you set the id of an element in HTML?

The value of the id attribute must be unique within the HTML document. The id attribute is used to point to a specific style declaration in a style sheet. It is also used by JavaScript to access and manipulate the element with the specific id. The syntax for id is: write a hash character (#), followed by an id name.

Can you add an id to a label?

To associate the <label> with an <input> element, you need to give the <input> an id attribute. The <label> then needs a for attribute whose value is the same as the input's id .

Why is id used for label in HTML?

Definition and Usage The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document). The id attribute is most used to point to a style in a style sheet, and by JavaScript (via the HTML DOM) to manipulate the element with the specific id.


1 Answers

The for attribute contains the ID of the element that the label is for. I always thought this would be quite intuitive...

<label for="SomeTextField" id="SomeLabel">Some text field</label>
<input type="text" id="SomeTextField">

You style a label like any other element:

label {
  font-weight: bold;
  color: red;
}

I always thought this would be quite intuitive, as well. So - what are you really trying to do, the questions you ask are a sign that you have a different problem, actually.

like image 165
Tomalak Avatar answered Oct 04 '22 00:10

Tomalak