Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

HTML Introduction to HTML and CSS Adding a New Web Page Write the HTML

I don't understand why <ul> isn't nested inside of <h2>?

as above :)

3 Answers

Hi, <ul> should only contain list items <li> like this:

<ul> <li>1</li> <li>2</li> <li>3</li> </ul>

If you head to: https://validator.w3.org/#validate_by_input and paste in:

<ul> <h2>1</h2> <h2>2</h2> <h2>3</h2> </ul>

You will get this error: Error: Element h2 not allowed as child of element ul in this context. (Suppressing further errors from this subtree.)

And vice versa :)

Jason Anders
Jason Anders
Treehouse Moderator 145,526 Points

HI Ryan Straker

The best way to think of this formatting is to visualize it as it would be written on a piece of paper.

The <h2> tag should not be thought of as a container, but rather a formatter. This tag will make the font larger and bolder.
Imagine a menu at a restaurant:
The name of the restaurant will probably be in large print at the top of the menu. This would be like the <h1> tag. Now, lets say you wanted a burger. You would skim the menu looking for the section called "Burgers." The section title would be smaller than the name of the restaurant, but larger then then menu items, so this would be like an <h2>.
If it was all formatted as an <h2> element, than it would all look the same and the point of using an <h2> would become moot.

In short, it's a formatting thing, really. You could use heading tags inside a list to format the <li> tags, but this not in the way you are thinking, and is outside the scope of this post.

Overall, just remember that any heading tag should only contain one line of text and is almost always a title for the section following it.

I hope that this helps make more sense of the purpose and use of headings. If you would like to read up some more to further clarify, the MDN section for heading tags has some nice examples.

Keep Coding! :) :dizzy:

Sergio Andrés Herrera Velásquez
Sergio Andrés Herrera Velásquez
Courses Plus Student 12,809 Points

I would say that it is a matter of importance as h2 has greater importance in the overall markup than <ul> elements do , so, they cannot be contained by it,