Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

INFO: The Difference Between the <DIV> and <SPAN> HTML Tags


View products that this article applies to.

This article was previously published under Q180153

↑ Back to the top


Summary

This article describes the difference between the <DIV> and <SPAN> HTML tags, which are available in Internet Explorer 4.0x.

↑ Back to the top


More information

The <DIV> tag is a block element used for creating a container to hold and to position other elements. It is commonly used for absolute positioning of content.

The <SPAN> tag is an inline element that is used to render text by using a style sheet. It is commonly used to change the style of an element, or text within a sentence, or block such as <P>, <DIV>, or <TABLE>.

Because the <SPAN> tag cannot create a line break, the following HTML does not behave as you expect:
   <HTML>
   <HEAD>

      <SCRIPT>
         function DoStuff()
         {
            txt.innerHTML = "<UL><LI>It worked</UL>";
         }
      </SCRIPT>

   </HEAD>
   <BODY>

      <P>
         <SPAN ID=txt>HTML<b> to be</b> replaced</SPAN>
      </P>

      <A HREF="javascript:DoStuff()">Click Me</A>

   </BODY>
   </HTML>
				
This use of the innerHTML property succeeds if you replace the <SPAN> tag pair with <DIV>.

Because the <SPAN> is not a block element, the <SPAN> does not have an ALIGN attribute. This is unlike a <DIV>.

↑ Back to the top


References

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

↑ Back to the top


Keywords: kbinfo, kbscript, kbfaq, KB180153

↑ Back to the top

Article Info
Article ID : 180153
Revision : 3
Created on : 5/11/2006
Published on : 5/11/2006
Exists online : False
Views : 575