Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Label vs span: HTML

Tags:

html

I am a bit confused in what to use for rendering data. My scenario is that I have to render count and I am not sure about using span or label.

<span id="spnCount"></span> 

or

<label id="lblCount"></label> 
like image 397
jason Avatar asked Oct 15 '12 07:10

jason


People also ask

What is the difference between Span and label in HTML?

label is used for labeling form controls in html. It also has for attribute where you can set id of the control which this label related to. span used in case when you need to display some literal data.

Is it good to use SPAN in HTML?

div in HTML. Span and div are both generic HTML elements that group together related parts of a web page. However, they serve different functions. A div element is used for block-level organization and styling of page elements, whereas a span element is used for inline organization and styling.

What is a span HTML?

<span>: The Content Span element The <span> HTML element is a generic inline container for phrasing content, which does not inherently represent anything. It can be used to group elements for styling purposes (using the class or id attributes), or because they share attribute values, such as lang .

What is difference between name and label in HTML?

The for= attribute in the label is used to link the label to one specific input on the page. Since name= is not unique for inputs (I can have multiple inputs with the same name), the for= element on the label links to an id= attribute on the input.


2 Answers

A label is used when you have a form or input elements - the label is associated with an input element. Span is a general container for any inline content. I think you want a span in this case

like image 193
slapthelownote Avatar answered Oct 01 '22 02:10

slapthelownote


Span

The <span> tag is used to group inline-elements in a document.

The <span> tag provides no visual change by itself.

The <span> tag provides a way to add a hook to a part of a text or a part of a document.

Label

The <label> tag defines a label for an element.

The <label> element does not render as anything special for the user. However, it provides a usability improvement for mouse users, because if the user clicks on the text within the <label> element, it toggles the control.

The for attribute of the <label> tag should be equal to the id attribute of the related element to bind them together.

like image 25
Ron van der Heijden Avatar answered Oct 01 '22 02:10

Ron van der Heijden