tags:

views:

366

answers:

6

What is the theoretical explanation of

<span></span>

tag? And where we use? What is the use of this tag?

+11  A: 

From here:

Definition and Usage

The tag provides no visual change by itself.

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

When the text is hooked in a span element you can add styles to the content, or manipulate the content with for example JavaScript.

So, the short version is, it's to style some text (without a paragraph or linebreak which is different from <div> tag)

Peter
+1. A typical example is to use it to make some text have a different background color (or any other element of style that does not have it's own HTML tag).
Milan Babuškov
+3  A: 

It's just a way to logically group subelements together. You can also apply styles, etc at this level which will cascade down.

Take a look at the wikipedia article which goes into some depth.

joeslice
+5  A: 

It is for grouping HTML elements and content for applying structure, defined for HTML 4.0 at http://www.w3.org/TR/REC-html40/struct/global.html#h-7.5.4:

The DIV and SPAN elements, in conjunction with the id and class attributes, offer a generic mechanism for adding structure to documents. These elements define content to be inline (SPAN) or block-level (DIV) but impose no other presentational idioms on the content. Thus, authors may use these elements in conjunction with style sheets, the lang attribute, etc., to tailor HTML to their own needs and tastes.

It goes on to give an example of the usage.

mas
+2  A: 

Span has no structural meaning to the document (as h1 does, for instance), but can be used as a container when none of the other inline containers are appropiate. You would, for instance, use a span if you needed to apply some CSS to a small bit of text within some other text.

http://htmlhelp.com/reference/html40/special/span.html

driis
A: 

Hi

The span tag just tells the browser to apply what ever style changes are included within the span and if there is no styling within the span then there would be no formatting applied to the enclosed text. This is a bit different from the div tag which incorporates a paragraph break even if no styling options are included within a div.

So it is useful when you want to apply styles to elements without placing them in a separate block.

cheers

Andriyev
A: 

It's just a placeholder for javascript or css.

If you don't use javascript/css, has no use to u.

janetsmith
Rubbish you can style spans if you so wish.
mP
What so rubbish about, mP?"It's just a placeholder for javascript or css." so anyone can manipulate it, IF he/she knows css/javascript.Can u tell me, if he/she doesn't know about javascript/css, what does <span> mean to him/her?And I didn't say it can't be styled. What I meant is <span> tag only useful for those javascripter or css'er, for interactive design or graphic design.
janetsmith
Your answer is a bit deceiving. It is a placeholder element - like a div - with a difference of not being a block element - it is rendered as an inline element. It has no styling by default. Can be styled. Has no semantic meaning.
easwee