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 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,370 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!