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

Last reviewed: February 9, 1998
Article ID: Q180153
The information in this article applies to:
  • Microsoft Internet Explorer (Programming), versions 4.0, 4.01
  • Internet Client SDK, versions 4.0, 4.01

SUMMARY

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

MORE INFORMATION

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

The <SPAN> tag is an inline element used to render text 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 will not behave as expected:

   <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 will succeed if you replace the <SPAN> tag pair with <DIV>.

REFERENCES

Internet Client SDK Help:

http://www.microsoft.com/msdn/sdk/inetsdk/help/

Keywords          : AXSDKIESripting kbfaq
Technology        : kbInetDev internet
Version           : WINDOWS:4.0,4.01
Platform          : WINDOWS
Issue type        : kbinfo


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 9, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.