resources+tips

ABC (Always Be Closing)

Posted on: February 13th, 2011

Alec Baldwin

In HTML, almost all elements must be opened and then closed:

  • <p>...</p>
  • <a href="blahblah.html">....</a>
  • <div class = "clownbox">...</div>

If you don’t have both parts of the element, your page may not work correctly. It’s tough to keep track of this when you first start writing markup, but you will develop the ability to chase down stray tags very soon. (This is not the case in HTML and HTML5, but we’ll be closing our tags in this class)

Div element’s closing tags are hard to keep track of, because you can have divs inside divs inside divs, as you know, and then you end up with something like this:

</div>

</div>

</div>

</div>

Which closing </div>  goes with which opening <div>? This is what I and many tidy coders do: when you close your div element, include a comment next to it that tells you what  opening <div> it belongs to. For example,

<div id="clownbox">...

</div><!--end clownbox-->

The comment element: <!--  --> makes it so any text within them is visible in your code but not on the browser.

Leave a Reply

List o' Resources