XHTML Basics - DIV or SPAN? DIV vs SPAN.
Member Login:
Article Sender Submissions
 
:. MAIN SERVICES
:. Webmaster Radio Sites

Webmaster Radio

Webmaster Radio, Podcasts for Marketing and SEO Profesionals.

White Label Media

Providing our clients with fully branded turnkey audio solutions for a number of 'on demand' and 'live' applications. From simple audio commercials, to professionally produced product launches.

Radio Advertising

Buy Category based Ads with Webmaster Radio Display audio ads and banners base on show or show category.

Search Bash

If you haven't been to a search bash party, you're missing out! If you an advertiser help sponsor a Search Bash Event for maximum exposure.

Affiliate Bash

If you haven't been to a Affiliate bash party, you're missing out! If you an advertiser help sponsor a Search Bash Event for maximum exposure.

Free Trade Publications

Looking for Trade Publications, we have tons of them and their all free!

SEO Services

SEO Seek offers you Professional SEO Help Information and SEO Services.



   Web-Site » Programming » XHTML Basics - DIV or SPAN? DIV vs SPAN.
XHTML Basics - DIV or SPAN? DIV vs SPAN.
These two tags are often used inter-changeably by developers for different reasons, so what are the differences between them? How should they be used to markup web pages?

The basic difference between the two is their default behaviour. DIV tags are block-level tags and can be used as containers for other tags. SPAN tags are inline tags and should only contain content. These default behaviours can of course be altered by CSS definitions, but are default in any browser context.

As a reference, if you want to align text within these tags use the following CSS attributes;

DIV - text-align: left|right|center|justify

SPAN - float: left|right

DIV tags are also used to define logical divisions of page content. It also allows CSS to be defined for whole sections of HTML. By applying an id to a DIV you can also add controls using JavaScript.

A SPAN tag is not intended to container other tags, but rather to allow localised styling. This is especially useful when combined with classes. It has even been suggested that future semantic web models will use such markup to define relevant content.

For example by defining a class telephone, when can ensure all telephone numbers are displayed in the same fashion:

44-20-555-4444

SPAN tags have similar properties but should be used to reference inline content and apply style by classes.

In summary: use divs for defining sections of a page, and spans to enclose and style text or classes of text.

An example usage of this approach would be as follows.

Often a designer will wish to have a section or paragraph title bar which contains two separate pieces of text displayed on one line. This may be a text title on the left and a date or time stamp on the right.

This can be accomplished very cleanly with a few CSS attributes applied to the following HTML :-

Section: HTML help Date: 21st Apr

div { text-align: right; }
span { float: left; }

By using this simple approach it means that the content will still be displayed in the order it was intended to be viewed, even if CSS is not available or rendered correctly in the visitor's browser. This approach also avoids the temptation to use tables or even floating div tags. By using the DIV and SPAN tags, the semantic nature of the content is preserved.

Permission is granted for reproduction of this article, so long as it is published in its entirety, with footnotes attached.

Further HTML help, and XHTML tips can be found at http://www.xhtmltips.co.uk/

Bill has been developing, maintaining and promoting websites and web based applications since 1997. During this time he has worked for numerous companies and agencies to improvement their online presence and campaigns for blue chips, government and academic institutions. Further HTML help, and XHTML tips can be found at http://www.xhtmltips.co.uk/

Visit Our Site at XHTML Tips
:. ARTICLE CATEGORIES
Affiliate
Business
Computers & Internet
Economics
Entertainment
Finance & Accounting
Humanities
Industry Publications
Life Style
Web-Site
Writing


:. Featured Articles

You Need RSS, Atom, and ROR XML Codes on Your Website!

Do you have a website? If so, you need an RSS XML code button which leads to a full RSS code page for your website. This code tells search engines all about the special details you input into the code about your website.

The Benefits of Blogging For Business

It goes without saying that maintaining a blog is a good idea for the health of your business. Have you ever asked yourself Why?

RSS: THE KING OF PERMISSION MARKETING

In an industry that is predominated by a race for the next big thing, it is important to stay ahead of the pack.

xgfdg

ghfghfghy. Finally, I had found the elusive "luck factor" Here are Professor Wiseman's four top tips for becoming lucky: 1) Listen to your gut instincts - they are normally right 2) Be open to new experiences and break

Step by step process to create free blog on your own FTP within your web template

Create a blog from own FTP is somewhat technical & for the first time, it takes some time. This article help to create blogs within the own template on FTP seriver in few easy steps at less time.


©2008 ArticleSender.com All Rights Reserved.