written on:13 Jan, 2008 by Alen Grakalic

How to use headings in HTML

Delicious | Digg | Stumble | Reddit | Float | Subscribe to RSS Feed

h1 illustration

Many of web standards rookies feel that passing validation is good enough to call their work web standards compliant. Those who are more involved in web standards know that there's more than that. Use of headings is a good example. While validator will not show any warnings or errors for headings, you can't say that your page is valid if your heading structure fails.

Meaning of headings

Some say that the largest role of headings are their SEO meaning. I am not going into that. They maybe right, but I say (since I am not a SEO expert but a web standards enthusiast) that their importance lies in semantics.
What are headings anyway? Headings are elements that describe the content that follows and also define a document's structure. Similar to large headings and subheadings in printed newspapers, html headings should briefly describe what the page or sections are about, making it clear to the reader (human or non-human) what to expect if he continues to read.
We have <h1> to <h6> heading tags. The numbers in the tag name carry a certain "weight", where <h1> is the "heaviest" and <h6> is the "lightest". That hierarchy is the principle that we should follow when structuring our document.

Document structure

So how to properly structure a document? Let's compare document's heading structure with some well formed XML file.

<h1>
	<h2>
		<h3></h3>
		<h3>
			<h4></h4>
		</h3>
	</h2>
	<h2>
		<h3></h3>
		<h3></h3>
	</h2>
	<h2>
		<h3></h3>
	</h2>
</h1>

Those of you confused by this code, this is merely an illustration of heading structure transformed into XML.
Find a more visual approach below:

heading structure illustration

H1, H2, H3 and H4 represent heading tags (titles) while boxes represent content where darkest box carries more "weight" in terms of importance then lighter ones.

First heading, <h1> defines a large section, usually an entire document. I believe that it should be used once per page as a top level heading, describing the content of entire page. Exceptionally, if you have separate large sections on the same page you may use two or more h1.
Choosing which heading tag to use on a specific spot shouldn't be a matter of thought. You simply use the next one in line. If the content you're describing could be treated as a "child" of the previous content, then use the heading that is one step down in hierarchy. If we are talking about "sibling" content than you should use same one. That creates a certain logical flow that shouldn't be broken, otherwise your document will make less sense.

"Don'ts" when using heading tags

As some of you know, and some of you guess, the power of CSS is rather large. There's no need for compromises when we're talking about headings. One of the thing that I see a lot is using heading tags based on browser's default styling. Some will use h4 instead of h2 on a certain spot just because they need a smaller headline. What we should do is use h2 and use CSS to make it smaller. Simple, right?

Further more, not all content belong in the heading. i.e. if you have a blog post title and you decided to put it into h2 or h3, don't worry what heading to use for the date and publisher info. Don't use headings for that type of content. Even in newspapers you will not see large and bold "Written By John, Aug 22nd".

The largest error that I see often is separating headings from their belonging content because of design compromise i.e putting some floated navigation between heading and the paragraphs. You shouldn't make compromises in that area. Make document structure a priority and don't bend it just because you have complex design. In most (I would say "all") cases CSS can give you a hand. Just make an extra effort and pretty soon you will be happy.

About the author:

cssglobe's image Designer, developer and a passionate standardista with large experience in all types of front-end work. Started to get involved with web in 1999. and turned freelance in 2005., the same year he started Css Globe. Alen's work has been featured on numerous css galleries including famous Css Zen Garden official list. Available for contract work.

Enjoyed the article?

Subscribe to our RSS feed or share it with your friends.

Delicious | Digg | Stumble | Reddit | Float | Subscribe to RSS Feed

Comments

  • didoo on 14 Jan, 2008 wrote:

    As far as i know, heading are for "titles", not for sections...

    "A heading element briefly describes the topic of the section it introduces." (see http://www.w3.org/TR/html401/struct/global.html#h-7.5.5 )
  • cssglobe on 14 Jan, 2008 wrote:

    That's what I said. Headings are meant to describe sections... If you are referring to that xml code there, as I said in my note, it is only an illustration of a heading structure not the actual html code.
  • Franck on 14 Jan, 2008 wrote:

    The role of headings is quite clear for most people (imo). How tu use them is a bit more complicated.
    I don't agree with your XML scheme. I often use several H1 on a page and I think this is not a problem at all. Indeed, the first title of a page is the tag in the head. </div> </li> <li> <p class="info"> Franck on 14 Jan, 2008 wrote:</p> <div class="body"> ... TITLE tag in the head (sorry). </div> </li> <li> <p class="info"> Björn on 14 Jan, 2008 wrote:</p> <div class="body"> Is this the correct way to write xml from headings? or is it just an illustrative example? It seems abit strange. Is for instance h1 really a parent to h2. Arent they all nodes of something else, like <body> or something? </div> </li> <li> <p class="info"> <a href="http://www.cssglobe.com" rel="nofollow" title="Visit cssglobe's site">cssglobe</a> on 14 Jan, 2008 wrote:</p> <div class="body"> Yes, in many ways title tag can be considered as H0 and you can build your structure from there if you want to go that way. <br/>Main reason for going with only one h1 is that it is a top level heading and, as I said in my article, it carries the most "weight". That means that content that follows is the most important. So if you use more than one h1 tags that means that you have two or more sections of equal importance - same "weight". <br/>The other reason I am going for one h1 is that I use that tag inside the content. i.e when you print out a document it will print your h1 but not the title tag. <br/>Anyway, this article is not (only) about whether we should use one h1 or not. What I wanted to say in this article is that when working with headings you should be consistent and pay attention to content hierarchy and do not break the logical flow of the headings, don't jump from h2 to h4. <br/>If you want to use more than one h1, use that scheme more than once and you'll get your structure :) </div> </li> <li> <p class="info"> <a href="http://www.cssglobe.com" rel="nofollow" title="Visit cssglobe's site">cssglobe</a> on 14 Jan, 2008 wrote:</p> <div class="body"> @Björn: it is an illustration of a heading structure, not the actual code. I thought it would help us understand the relations between heading tags, similar to parent-child relations in xml. </div> </li> <li> <p class="info"> Franck on 14 Jan, 2008 wrote:</p> <div class="body"> You said : "pay attention to content hierarchy and do not break the logical flow of the headings"<br/>I really agree with that. Then, there are many ways of using headings and it is a good discussion. </div> </li> <li> <p class="info"> <a href="http://3oneseven.com" rel="nofollow" title="Visit milo317's site">milo317</a> on 14 Jan, 2008 wrote:</p> <div class="body"> Funny coincidence, some of those "premium" WordPress paid themes are featuring bad habit with headings on the front page,<br/>e.g. no h2 tag followed by h3 tags with not even an h1 tag, using an image instead of an image replacement technique.<br/>Premium?<br/>Apart from that it's a nightmare in terms of SEO. </div> </li> <li> <p class="info"> <a href="http://www.cssglobe.com" rel="nofollow" title="Visit cssglobe's site">cssglobe</a> on 14 Jan, 2008 wrote:</p> <div class="body"> Actually it's looking at those sites based on various WP themes that got me to write this article. It seems that heading usage is not that obvious after all. </div> </li> <li> <p class="info"> Rob Knight on 14 Jan, 2008 wrote:</p> <div class="body"> Good overview on heading use. I'm curious about the h4 nested in an h3...even if just an example that might give someone the wrong idea.<br/><br/>Cheers, Rob </div> </li> <li> <p class="info"> <a href="http://www.cssglobe.com" rel="nofollow" title="Visit cssglobe's site">cssglobe</a> on 14 Jan, 2008 wrote:</p> <div class="body"> I got a lot of criticism about this illustration so I decided to put new , more visual approach. Hope the things are clearer now. </div> </li> <li> <p class="info"> sunil on 21 Jan, 2008 wrote:</p> <div class="body"> is there any limitation of heading tags used in a page (count). I seen some of the css deveopers using h1 for logo (background of h1). Can we use another h1 for titles. Is it considered as spamming? </div> </li> <li> <p class="info"> <a href="http://www.cssglobe.com" rel="nofollow" title="Visit cssglobe's site">cssglobe</a> on 21 Jan, 2008 wrote:</p> <div class="body"> As I said earlier, h1 define content that carries the most "weight" and there's no other heading that is "heavier" than h1. If you have separate content sections that are of EQUAL and MOST importance than there's no other choice but to use multiple h1.<br/>Btw, with things you see around web sites, I doubt that multiple h1 would be considered spamming. </div> </li> <li> <p class="info"> <a href="http://dezinerfolio.com" rel="nofollow" title="Visit Navdeep's site">Navdeep</a> on 24 Jan, 2008 wrote:</p> <div class="body"> thanks for the tips... </div> </li> <li> <p class="info"> Joe on 25 Jan, 2008 wrote:</p> <div class="body"> How do you feel about using h1 tags for the website name/logo; does that constitute as a logical heading? </div> </li> <li> <p class="info"> <a href="http://www.cssglobe.com" rel="nofollow" title="Visit cssglobe's site">cssglobe</a> on 25 Jan, 2008 wrote:</p> <div class="body"> I almost always use h1 for the sites logo or even entire header, but I also always use image replacement technique so that in the source h1 contains text. </div> </li> <li> <p class="info"> <a href="http://www.keenpixel.com" rel="nofollow" title="Visit Ryan's site">Ryan</a> on 15 Feb, 2008 wrote:</p> <div class="body"> Hi, just came across this post...<br/><br/>I have been using h1 for logos with image replacement as you mentioned...but I've come to wonder if that is really best practice. Is the logo, i.e. the company's name, really the most important feature of any given page? It's most likely already used in the <title>. It seems that perhaps the page topic really is the most important, for both semantics and SEO. </div> </li> </ul> <form id="commentForm" method="post" action=""> <h3>Post a comment</h3> <p><label for="name">name</label> <input type="text" name="name" id="name" class="inputField" /></p> <p><label for="email">email (will be hidden)</label> <input type="text" name="email" id="email" class="inputField" /></p> <p><label for="web">web</label> <input type="text" name="web" id="web" class="inputField" value="http://" /></p> <p><label class="captcha" for="captcha">Answer?</label> <input type="text" name="captcha" id="captcha" class="inputField" /></p> <input type="hidden" name="itemId" id="itemId" value="1213" /> <p><label for="comment">comment</label> <textarea name="comment" id="comment" class="inputArea" cols="30" rows="10"></textarea></p> <p class="submit"> <input type="image" name="submit" id="publicSubmit" src="/v3.0/images/btn_submit.gif" /> </p> </form> </div> <div class="side"> <div id="search"> <form action="http://www.google.com/cse" id="cse-search-box"> <input type="hidden" name="cx" value="001382409290499745115:yffak9ophzg" /> <input type="hidden" name="ie" value="UTF-8" /> <input type="text" name="q" size="31" /> <button type="submit" name="sa">Search</button> </form> </div> <script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script> <h2 class="category"><a href="http://feeds.feedburner.com/cssglobe/" title="Subscribe to our RSS feed">Subscribe</a></h2> <p id="subscribe">Join 6000+ subscribers and receive our content instantly.</p> <p class="more"><a href="http://feeds.feedburner.com/cssglobe/" title="Subscribe to our RSS feed">Subscribe to our feed</a></p> <h2 class="category"><a href="http://twitter.com/cssglobe" title="Css Globe on Twitter">Follow us on Twitter</a></h2> <p id="twitter">Want to be the first to know when a new article is published?</p> <p class="more"><a href="http://twitter.com/cssglobe" title="Follow Css Globe on Twitter">Follow us on Twitter</a></p> <h2 class="category">Sponsors</h2> <p class="ad"> <a href="http://www.psd2html.com/order-now.html" title="PSD to HTML"><img src="http://cssglobe.com/ads/psd2html.gif" alt="PSD to HTML" /></a><br /> <a href="http://www.psd2html.com/order-now.html" title="PSD to HTML">PSD to HTML</a> </p> <p class="ad"> <a href="http://www.freshbooks.com?ref=356" title="Look Professional with FreshBooks"><img src="http://cssglobe.com/ads/freshbooks.png" alt="Look Professional with FreshBooks" /></a><br /> <a href="http://www.freshbooks.com?ref=356" title="Look Professional with FreshBooks">Look Professional with FreshBooks</a> </p> <p class="ad"> <a href="http://www.medialab.com/sitegrinder/?gad=CMLlgfkIEghxs-SBpFpBxRji78r-AyD2gbUy" title="Sitegrinder 2 Photoshop Plugin"><img src="http://cssglobe.com/ads/sitegrinder.jpg" alt="Sitegrinder 2 Photoshop Plugin" /></a><br /> <a href="http://www.medialab.com/sitegrinder/?gad=CMLlgfkIEghxs-SBpFpBxRji78r-AyD2gbUy" title="Sitegrinder 2 Photoshop Plugin">Sitegrinder 2 Photoshop Plugin</a> </p> <p class="ad"> <a href="http://www.xhtml4u.com" title="Convert Design to XHTML/CSS"><img src="http://cssglobe.com/ads/xhtml4u.jpg" alt="Convert Design to XHTML/CSS" /></a><br /> <a href="http://www.xhtml4u.com" title="Convert Design to XHTML/CSS">Convert Design to XHTML/CSS</a> </p> <p class="ad"> <a href="http://deskload.com" title="Online Bookmark Manager"><img src="http://cssglobe.com/ads/deskload.gif" alt="Online Bookmark Manager" /></a><br /> <a href="http://deskload.com" title="Online Bookmark Manager">Online Bookmark Manager</a> </p> <p class="more"><a href="/advertising.asp">Advertise here</a></p> </div> </div> </div> <p id="footer"> <a href="/">Home</a> | <a href="/about.asp">About</a> | <a href="/register.asp">Register</a> | <a href="/contact.asp">Contact</a> | <a href="/feeds.asp" class="feed">RSS feeds</a><br /> © Copyright <a href="http://www.cssglobe.com" title="Web Standards Magazine and Community">cssglobe.com</a> 2008 | Css Globe is brought to you by Alen Grakalic, web standards designer and developer, available for <a href="http://www.cssglobe.com/contact.asp">contract work</a>.<br /> <a id="ninerules" href="http://9rules.com" title="Css Globe is a proud member of 9rules network"><img src="http://cssglobe.com/v3.0 /images/9rules.gif" alt="9rules logo" /></a> </p> <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> </script> <script type="text/javascript"> _uacct = "UA-783567-1"; urchinTracker(); </script> </body> </html>