Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML Introduction to HTML and CSS (2016) Make It Beautiful With CSS Select and Style by Element

what is the difference between h1,h2,h3?

I dont understand when to make a tag with h1 or h2 or h3

5 Answers

Adrian Grabowski
Adrian Grabowski
2,622 Points

Same as in Word document you can use different types of headings - h1 is going to be your main/top-level heading and h2 and h3 are going to be sub-headings, you can style them differently so they will have different font size or colour.

It's important to think about heading tags as elements that give meaning to your HTML content. It has nothing to do with size and style. Heading tags are used to convey information and to allow for screen-readers to read that information in a way that makes sense for people who are visually impaired.

Please disregard the idea that headings have anything to do with styling.

Think about a newspaper: You'll start with the main section of the newspaper

<main>
  <h1>World News</h1>
  <section>
    <h2>News on Europe </h2>
    <article>
       <h3>France will host the next Olympic games</h3>
       <p>lorem ipsum **insert news content here**</p>
    </article>
    <article>
       <h3>The UK has no idea what's going on right now with Brexit</h3>
       <p>lorem ipsum **insert news content here**</p>
    </article>
 </section>
  <section>
     <h2>News on Asia</h2>
     <article>
        <h3>Vietnam is the hottest place to travel</h3>
         <p>lorem ipsum **insert news content here**</p>
     </article>
     <article>
        <h3>Tokyo records the coolest day in years</h3>
         <p>lorem ipsum **insert news content here**</p>
     </article>
  </section>
</main>

Notice that the headings are organized with h1 being the main heading (i.e. World News), followed IMMEDIATELY with its child, the h2 (i.e. News on Europe), and then for each subsequent news article, the heading will be a h3.

We can conclude, therefore that headings must be organized in a parent-child relationship so that Screen-Readers can better organize the content and communicate it to those who are visually impaired. This also helps a ton with SEO/search-engines.

Again- your reasons for using h1,h2,h3,h4 should have nothing to do with sizing/font-styles. That's what CSS is for.

Here's a good resource on headings via MDN https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements

Cory Stover
Cory Stover
3,341 Points

h1, 2, and 3 also have different sizes. h1 will be the biggest, 3 the smallest.

sure- that's inherent to the user-agent, but any font-size consideration should be done with CSS. Headings were devised to give semantic meaning to the content.

This W3 schools link provides an example of h1 to h6 tags. Note, in this example, they get smaller as you go from h1 to h6. This is typical. However, the styling depends on CSS. While unusual, it is possible to have h1 smaller than or the same size as the h2 header. However, it's importance is always as the main heading and not a subheading like h2.

sorry, Cory- although you're technically right, I find myself misusing headings on the basis of their style and size. This is a no-no for web-accessibility.