Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semantic value of span

The span element seems to be exactly like a div, but at the in-line level rather than at the block level. However, I can't seem to think of any beneficial logical divisions that the span element can provide.

A single sentence, or word if not contained in a sentence, seems to be the smallest logical part. Ignoring CSS, since CSS is only for layout and not for semantic meaning, when does span provide additional semantic value by chopping up a sentence or string of words?

It seems that in all cases, other elements are better suited to adding semantic value, making span a purely layout element. Is this true?

like image 863
cdeszaq Avatar asked Nov 10 '08 19:11

cdeszaq


People also ask

Does span have semantic value?

SPAN (and DIV) elements by themselves are generally considered to be semantically neutral.

Is Span non-semantic?

Examples of non-semantic elements: <div> and <span> - Tells nothing about its content.

Does span have value attribute?

Attribute Values: It contains the numeric value which specifies the number of supported element should span.

Why are div and SPAN not semantic tags?

Examples of non-semantic elements are div and span . These tags don't tell the computer anything about the meaning of the contents of the element.


1 Answers

Span can be used to add semantic meaning that falls outside the scope of HTML. This can be done by using classes which identify certain attributes. For example, if you are writing a science-fiction novel you can use span to identify made-up words, because you may want to format those differently, or because you may want the spell-checker to ignore them:

Then the wizard called upon the <span class="wizardword">gravenwist</span> and bade it attack the approaching army. The <span class="wizardword">gavenwist</span> resisted but the wizard's <span class="wizardword">wistwand</span> was too powerful.

This could render as

Then the wizard called upon the gravenwist and bade it attack the approaching army. The gavenwist resisted but the wizard's wistwand was too powerful.

Another good example of this sort of thing are microformats, which allow the creation of arbitrary structure within HTML:

<span class="tel">
 <span class="type">home</span>:
 <span class="value">+1.415.555.1212</span>
</span>

The advantage of span, versus div, is that spans can appear almost everywhere because they are inline content, and divs are block elements, so they can only occur inside certain other elements.

like image 125
Mr. Shiny and New 安宇 Avatar answered Sep 21 '22 13:09

Mr. Shiny and New 安宇