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 How to Make a Website Creating HTML Content Include External CSS

H C
H C
883 Points

What's the difference? For anchor elements to be indent/inside <li> and outside <li>?

For example, inside <header>, for bullet point portfolio, about and contact, anchor element is inside <li>; however, while inside <section>,the <img>s and <p>s are inside anchor element. Is it because of the direction differences (stay on the home page or direct to another page?) How do i know which element should be indent/inside another element? Thank you.

2 Answers

Samuel Webb
Samuel Webb
25,369 Points

Indentation is used to show what elements are contained in other elements. You indent to see hierarchy in HTML. It's not required, its just easier to read the code when it's properly indented.

<ul>
    <li>
        <a href="#">Whatever</a>
    </li>
</ul>

Like I said, it's not necessary to indent like that and you can also get away with something like what follows. The big problem though is that it becomes difficult to read and update when your code gets longer.

<ul><li><a href="#">Whatever</a></li></ul>

Sometimes people keep some things on one line because there's no need for it to take up extra lines and make the code longer.

<ul>
    <li><a href="#">Whatever</a></li>
</ul>

It's all up to you, just remember that indentation is only important ascetically and does not alter how the code works at all. I hope this helped answer your question or at least leads you down the right path.

H C
H C
883 Points

Thank you very much!