Quick References
      ADO
      ASP
      CSS2
      HTML
      JavaScript
      Jet SQL
      VBScript
      WML
      WMLScript
      WSH
      XHTML
      XML DOM
      XSLT

Features
      Knowledge Base
      Tutorials

Partners
     ZVON.ORG
     XML
     Planet Source Code
     VisualBuilder
     Web Design
     Your HTML Source
     XML/XSLT Forums
     ASPAlliance
     Scripts
     
     Programmers Heaven
     Tek-Tips Forums
     Developer Fusion
     Code Project









TAG:  span

<span> ... </span>
 
The span tag is used to designate an inline portion of an HTML document as a span element and to apply any of the core attributes of this tag against the contents of that element. The behavior of this tag is inline because the effects occur in the normal flow of the text and images (without the tag inserting any additional linefeeds or carriage returns). span tags, which can be nested, allow a significant degree of control and manipulation of a localized part of your web page.
 
For example, you could use the class or style core attributes to apply the effects of Cascading Style Sheets or you could use the lang attribute to display a foreign language text.
 
In contrast, you should use the div tag when you want to apply attributes to a block of code. Note that the behavior of the div tag is not inline, but rather is block-line, since this tag causes a line break to occur both before and after the div element.
 
With the advent of Cascading Style Sheets, both the div and span tags have gained importance and usefulness.
 
The separate closing tag is mandatory.
 
Attributes and Events
 
class    dir    id    lang    onclick    ondblclick    onkeydown    onkeypress    onkeyup    onmousedown    onmousemove    onmouseout    onmouseover    onmouseup    style    title
 
As an example, all of the code samples on the DevGuru site are in blue colored text. This is done by enclosing the code sample inside a pair of span tag elements and designating a class attribute of "CODE". In turn, the "CODE" class has been assigned a text color of blue in the style sheets file (a .css file) that is located in the Include/ directory on the DevGuru web site. Thus, only one file is needed to define the appearance of the entire site.
 
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>DevGuru XHTML span Tag Example</title>
</head>
<body>
<span class="CODE">
This line is blue.
</span>
</body>
</html>

 
Output:
This line is blue.
 
However, if you do not wish to create a .css file, you can still get the exact same results by using the style attribute for the span tag and the style sheet color property.
 
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>DevGuru XHTML span Tag Example</title>
</head>
<body>
<span style="color: blue;">
This line is blue.
</span>
</body>
</html>

 
Output:
This line is blue.


 


Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information