Menu
HTML SPAN Basics

Whereas a <div> is a block element which defines a vertical section of a webpage or parent element, a <span> is an in-line element that is rendered during the line-by-line parsing of the html code for the webpage. Without styles a span provides no visible change. A span does allow you to group text so that you can style it with CSS, or manipulate it with JavaScript.

Shown below is how a span might appear:

We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness. That to secure these rights, Governments are instituted among Men, deriving their just powers from the consent of the governed, That whenever any Form of Government becomes destructive of these ends, it is the Right of the People to alter or to abolish it, and to institute new Government, laying its foundation on such principles and organizing its powers in such form, as to them shall seem most likely to effect their Safety and Happiness.

Shown below is the code for the section with the span:

... Liberty and <span style="border:solid 1px;">the pursuit of Happiness</span>. That to secure ...

Note that in order to make the span visible I had to use some style code, giving the span a border.

As an aside, you'll probably recognize this as a section form the American Declaration of Independence. The span is where Thomas Jefferson, the author of the document, replaced the third term of John Locke's trinity, "life, liberty, and property" with "the pursuit of Happiness". Why would Jefferson do that? Well, you can't confiscate peoples property when they don't pay taxes if property is their constitutional right.


Learn more at amazon.com

More HTML Code:
• Use HTML Target Attribute to Specify Where to Open Document
• Using col and colgroup to Apply Attributes to a Table Column
• How to Debug HTML
• Providing Alternate and Title Text for an Image
• Easy Code to Add Bing Site Search to Your Website
• Using del and ins Tags to Mark Up Editing on HTML Page
• How to Use a Meta Redirect
• XHTML Basics
• Setting the Number of Items Visible in a Select List
• Changing the Size of an Image on Your Webpage