Jump to content

<p> tag useless?


shadowayex

Recommended Posts

I've been building webpages for a while now, and I've hardly ever used the <p>. In fact, usually if there is a place to use <p>, I either use <span> for short lines, or <div> for long lines. Is this a bad habit?

Link to comment
Share on other sites

<p> tag has a semantic meaning. It tells the browser and search engines that that is actually a paragraph.<div> is used to define a division in your document, for example "body", "content", or "navigation". Inside the <div> you'll use other tags for semantic meaning.<span> should rarely be used because you can always use something with more semantic meaning. For example: <em> and <strong> to emphasize text, <q> for quoted text, <h1><h2><h3><h4><h5><h6> for headers such as article titles and even the title of the website.All these elements can be styled with CSS just as well, so it's best to use them rather than <span> and <div>. Only use <span> and <div> if you see that no other element has a meaning that suits the content.

Link to comment
Share on other sites

Oh, I always found it easier to use those tags and style with CSS. The way I learned, you should avoid using HTML tags that are just for styling (like <b> or <i>) and instead use CSS. I suppose <p> and <h1> to <h6> aren't so bad. But I always try to avoid stuff like <strong>, <q>, and that type of stuff and use <span style="whatever[/i[\]"> or if there's more than one style I want to add, I make a class for it and put it in the <head> section. But I see how I could stop using <div> for a <p> replacement. Bad habit I guess.

Link to comment
Share on other sites

It's best not to use <b>, <u> and <i> tags. But it is recommended to use tags like <code>, <em>, <strong>. But not to change the style of the text, you use them to give the text a meaning.Here's an example of how to use these tags:

<h1>HTML</h1><h2>Necessary elements</h2><p>A proper HTML document <em>must</em> contain the following elements:<ul><li>&lt;html&gt;</li><li>&lt;head&gt;</li><li>&lt;title&gt;</li><li>&lt;body&gt;</li></ul>The following is an example of a very simple HTML document:<code>&lt;html&gt;&lt;head&gt; &lt;title&gt; &lt;/title&gt; &lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;</code><h2>The W3C says</h2><p>The following is a quote from the W3C about HTML:<q>HTML 4 is an SGML application conforming to International Standard ISO 8879 -- Standard Generalized Markup Language</q></p></p>
Note that all these elements can be styled with CSS. So it's better to use them instead of <span> so that your document has a meaning. There's a reason why tags like <strong>, <em>, <code> and <q> were not deprecated.
Link to comment
Share on other sites

By the way, HTML 5 is far more semantically detailed than the current version. In HTML 5, in your blog you can define the articles with <article>, the sidebar with <aside>, and the footer with <footer>.Being semantically correct also helps you understand your documents better. :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...