Formatting Text in Web Pages: Is the HTML Span Tag a Better Option than the P Tag?

Article by Lucinda Watrous (17,979 pts ) , published Jul 31, 2009

What's the difference between the HTML span tag and the P Tag? When should the span tag be used? Read on to find out more so you can be sure you're properly coding your websites.

What is the HTML Span Tag?

The span tag in HTML is simply the word "span" (without the quotes of course) in between the <> symbols used to denote HTML.The span tag doesn't do anything to change the visual appearance of text on its own, and requires variables to tell it what to do. It can change text color, add background color to lines of text, and even add mouse overs.

What is the HTML P Tag?

The P tag in HTML is simply the letter "p" denoted between the <> symbols used to denote HTML. As with the span tag, it doesn't do anything to change the visual appearance of the text without variables that tell it to do so. It can change text color, add background color to lines of text, and behaves like the span tag. It is meant to denote paragraphs and inserts line breaks so you don't have to waste time using the old break return (br in <>) to get one.

Why Does the Choice Between HTML Span Tag and the P Tag Matter?

Truth is, it doesn't. There are many programmers who argue that because a sentence fragment or a few sentences is not a paragraph, the span tag should be used instead of the p tag. Others say that because HTML is a structural language, the grammatical rules we follow in English do not apply, and the P tag can refer to any block of text.

If you want to use the p tag, go ahead, but remember any attributes you set will apply to all the text within that p tag set. You could break the text up according to what you want it to look like, using a separate p tag for anything that needs to look diferent; or, you could use a p tag for each paragraph, and use span tags where needed to adjust the appearance of certain areas within each paragraph.

Both will function the same in browsers. The way you decide to do it comes down to what you beleive is easier, and if you follow grammatical or structural definitions of the word "paragraph."

 
Subscribe to Web Development
RSS
Get free weekly updates, directly to your inbox.
Browse Web Development