Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
The first major formatting elements that we're going to take a look at are headings. Headings are used to structure pages and determine content hierarchies, so let's take a closer look, using the file headings.htm. I've opened that up here, in Komodo. Feel free to open that up in whatever code editor you have. Well, notice that inside the body tag we've got some text here, and I've sort of separated the text into sections, or chunks of text if you will, by placing them on separate lines. So you can kind of see where those Line breaks are denotes a new section of content.
It's easy for us to sort of look at that and determine that these are new sections of content, but if we were to preview this page in our browser, there's really not a lot going on here to let you know who's who and what's what, and that basically has everything to do with the lack of formatting structure currently within our code. We are going to add some headings, and the first thing I'm going to do is go up to this first line right up here where it says, "Up and Running with HTML" and I'm just going to format that as a top-level heading, or an h1.
We have six different levels of headings that we can use, and they range from h1 all the way down, of course, to h6. So if I save this and then wrap the second one in an h2, which of course is our second-level heading--and I'll save that and go back to my browser and preview this-- you can see that now there's a little bit more organization, in terms of the content. Up and Running with Html is a top-level heading. Formatting page is the second-level heading.
The browser is going to show us the levels of the headings based upon the size of the text. You'll notice that the h1, for example, is much larger and the h2 is a little bit smaller. Now, that's consistent all the way down. If I go down to the h2 and change this to, say, an h6, which is the smallest-level heading we can have--save that, again, refresh that-- you can see it's tiny. It's actually smaller than the body copy itself. So, browsers are going to sort of denote how important a heading is based upon the size of it, and that really sort of runs us into problems with most people as they start learning HTML, and that is this: the wrong way to approach using headings is to use a heading based upon what size you want it.
It's actually quite common for people to say, okay well, h6 is a little small, so let me go back and try an h3, maybe that will get it done, in terms of how big I want this, and save that and test it. That's much better. It's exactly the size I want it. But what they're doing is they're using headings to control the presentation of that, and that is the absolutely wrong approach to take. You want to develop a strategy around using your headings that's based upon the level of the heading itself and not necessarily the size of it, because, eventually you're going to be controlling that with CSS.
I can make through CSS an h6, actually larger and bigger and bolder than an h1, if I wanted to. So the size really has nothing to do with it; it's all about structuring it properly. So I have some additional headings here. If I took all of these headings and converted them all to h1s, so if I wrapped formatting page content in h1 and then went down to adding headings and wrapped that in h1 as well-- Same thing for using paragraphs, if I came in, wrapped this in an h1, and then, finally Line breaks, and wrap that in an h1.
What this is going to do, if I save this, go back into my browser and refresh, it's going to create all of these different sections for me that are all going to be sized exactly the same. But really, what I'm telling any user agent that parses this page is that these headings all have the same level of importance. And that's really what you ought to consider when you decide how to assign headings to the page: How important is this? One of the things that headings really do for us is to create sections within our content.
As a matter of fact, prior to HTML5, the only sectioning elements that we had in our page were headers. Now, with HTML5 we have some different sectioning elements that we can use, but headings really are still kind of the star of the show when it comes to creating sections within your page. So really think about your document as if you were going to generate a table contents from it, or if you were going to create an outline of that document later on. Do these sections have all the same level of importance? And of course for this document that answer would be no.
Obviously, the most important heading that we're looking at on the page right now would be Up and Running with HTML. After that, Formatting page content kind of is the title of the page whereas Up and Running with HTML is the title of the entire course. And then after that adding headings using paragraphs and line breaks, those do have sort of an equal level of importance, and they're basically subsections within formatting page content. So if you look at it that way, it becomes pretty easy to develop a heading strategy. So if I go back into my code, what I'd want to do is have Formatting page content as a heading 2 and then I'm going to convert all the rest of my headings to a heading 3, or an h3.
So again, the syntax behind these is simply an h, and then the number that you wish to have, and make sure that your opening and closing paragraphs match as far as it goes. That's very important. So if I save that, go back into my browser and refresh this, now that level of importance in the sections themselves are denoted, so it's very easy for a reader to scan the page right now, determine what's the most important content or the most important section of the page or what the page is all about, and then go through the individual sections as well. Now, there are some best practices involved with using headings.
For the most part, you want to limit the number of h1s you have on the page. There are a lot of SEO--search engine optimization-- people out there that will tell you to only use one h1 on a page. Well, there's no hard and fast rule that says that, and as a matter of fact, even Google who really should know about SEO, tells you that you don't get punished for using more than h1 on the page. They are just looking as to whether or not it's being used logically. So if you have two top-level headings that denote two sections of equal importance, there's nothing wrong with doing that; you just need to be logical in your approach to doing it.
The next thing you want to do is you don't want to skip a series of headings. On this page, for example, we're going to an h1 and then to an h2. Well, for these subsections, we wouldn't jump to an h5 or even to an h4. We want to go right down to an h3. The only time that you might change that is when you develop a sit-wide strategy. One of things that you're going to need to do as you plan your sites is you're going to think about the content that shows up on each and every page. Then, based upon that content, you can develop a heading strategy to denote the importance of certain sections.
In that case, one of the things you might think about is, okay, who does this content belong to, in terms of that level? If it is an h4 and you skip over and you will have any of those type of h3s on the page, then that would be fine. But for the most part your structure is going to be consistent like that, and that's one of the best practices that you want to make sure that you're aware of as you start planning your pages. So of course it's very important to establish site-wide rules around the use of headings, especially when you're planning your sites. Be sure to remember that the use of headings on your page should be driven by properly structuring the information and not by the visual formatting requirements of the page's content.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.