Add a comment to your closing DIV tag – it could save you hours

As time passes by and a repetitive task becomes even more repetitive bad habits begin to creep in. Before you know it the ‘bad habit’ is no longer a bad habit; it has become normal procedure.

Sometimes you can check yourself and realise you are doing something wrong and fix it. Other times you just need a gentle nudge.

Yesterday I got nudged

If you are hard/hand coding websites you will understand what a <DIV> tag is. You will also know that the more complicated a web page becomes, the more closing </DIV> tags you are going to need to keep the code clean and to make sure the page is displaying correctly.

Yesterday I was watching a video which reminded that adding a comment to a closing </DIV> tag is considered “best practice” when writing HTML.

This is what it should look like in your CSS file:

</DIV><!--end of class-->

Why is this a good thing to do?

If you are building websites using CSS you will know that the simplest of pages can consist of multiple opening and closing <DIV> tags. Each one controlling a particular element of the page. Whilst it is very easy to see where a CLASS or ID opens, it is not always so easy to know where it closes. If you add the closing comment to the closing </DIV> tag before you add any content between the two tags, it will help you to find exactly what is happening within the page.

This may not sound like something you could benefit from, but believe me, it could save you a lot of time in the future. Just because a webpage makes sense to you now, doesn’t mean it will in twelve or even six months time.

<DIV> overload is something I have suffered from in the past and stripping down a page to found out which <DIV> ends which piece of code is not the best way to pass time!

If you are new to coding get used to adding an end comment to your <DIV>‘s and keep up with the practice.

Other posts you might like to read

Tools, resources and services used by The Blogging Academy

This entry was posted in Blog Design Tips and tagged , , , , , , , , . Bookmark the permalink.

One Response to Add a comment to your closing DIV tag – it could save you hours

  1. freebirdmedia says:

    I get bogged down with divs sometimes too. I know your pain when you say stripping down a page to find a closing div is not fun.

    Great idea!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv Enabled