User Experience & Design blog

5 simple ways to make your mark up more manageable

George Lucas once said “A movie is never finished, only abandoned.” Luckily for those of us who work in the world of the web, while never finished, web sites and applications don’t have to be abandoned; we can always come back to them and change those areas that we feel need a tweak or two (in the same way Lucas did when he “remastered” the original Star Wars series).

There is a downside to our freedom to tweak however; after months of work on a project it can often be several more months before we come back to the code we have written, which is (in my case at least) just long enough to forget exactly how and why we got the design working the way it does.

Having experienced this many times and having lived through the pain of having to remember what was going on in my code from older projects, I started to use 5 very simple techniques for making my mark up more manageable and easier to come back to:

1) Add a closing comment to divs

At the end of each <div> element in a page I add a comment that includes the id or class name of the element in question for example: <div id="container">foo</div> <!--container--> This may seem trivial, but it really helps out when the divs fill up with a lot of content and you’re trying to find the end of a section of a page. This also proves useful for when it comes to slicing and dicing a static HTML page into includes.

2) Make a HTML map of the main structural elements

I first saw the 3d CSS Zen Garden diagram a few years ago have been making my own HTML maps for my designs ever since. I don’t bother with the internal elements as shown in Mr Clarke’s example as these change page to page, but mapping out the overall structure like this makes coming back to the design a lot easier.

3) Use logical class and id names that are memorable

This is something everyone should be doing anyway, but unfortunately there are still plenty of coders who don’t. There are still people who will name elements things like “leftCol” which is a bad idea as it explicitly ties the element to the layout and will make no sense if the content in “leftCol” has to sit on the right of the screen in an updated design. But as well as choosing a name that is display independent, the name should be meaningful; “primaryContentContainer” not something like “xl42″ (which I have seen in one designer’s code). The more obvious the naming, the easier it is to “relearn” how the structure works (it also makes the HTML maps more readable).

4) Add some meta data to your CSS using comments

At the top of all my style sheets for each project I include a series of comments that tell the reader a bit about the file. They look something like this:

/* fileName.css - description of the site or product this is for, along with any specific styling this file contains (print styles for example)*/
/* Author: Name and email address */
/* Creation date: DD MMMM YYYY */
/* Last edit: DD MMMM YYYY - Name of person making the change */

This is really useful when you have to hand over a design to someone else, but is also useful when you have to revisit a design and there are a number of style sheets that control things. Remembering which does what becomes simpler.

5) Put Internet Explorer CSS hacks in a separate style sheet

Roll on the day when all browsers display CSS in the same way. Until that day IE will always need some help to make it play nice. There are many hacks for common problems out there, but including them all in the main style sheet for a project becomes a maintenance nightmare. Instead use a separate “ieonly.css” file that contains all of the IE specific styling rules. Then include this in your HTML using the IE conditional include. This allows you to collect all the IE only rules in one place and simply remove them by removing the conditional include should we ever reach the mythical day when IE works like the rest of the world.

Do you have any tips for making your mark up more manageable? Share them with us in the comments.

Comments (9 so far)

Another tip is using source control / versioning.

Rather than rely on people to document what changes manually, you can track the version history of a file from its incarnation and see exactly what changes have happened where.

James 'Smiler' Farrer on the 20th September 2007 at 12:06 pm

Source control is a good one. Yep. In fact we use source control for most things in work, and it proves invaluable when it comes to working with teams of more than 1

I reckon Source control is invaluable even in a team of 1, because it is a big giant undo button that lets you roll back any changes that you don’t want for any reason.

On the HTML Map idea – I was just playing around with the Web Developer extension for Firefox and you can get that effect by turning on “Display Topographical Information” and “Display id & class details”. All done for you then!

Hi Alex,

I guess it can be useful for teams of 1 too. It all comes down to the trade off between effort of setting it all up and following the process of using it, vs. the effort of undoing something without it. Only the most simple of applications wouldn’t benefit from using it now I stop to think about it.

In terms of the Firefox extension – I love the Web Developer toolbar, but I’d not noticed that I could get the HTML map effect using it. Good spot.

I never knew this thank you this will help me with my study…

Good tips there James.

On #1, this is good practice, but you really have to watch where you place comments in your html. For example, if your layout uses floats and you place a comment in between two floats you trigger some bugs in IE. This is the reason I stopped using comments. Seemed every time I tried to use them it triggered those bugs in IE and it made my brain hurt trying to strategically place them in the html so IE would play nice.

#3 is one that I need to start practicing more. I get in a habit of just naming columns “left-content” and “right-content.” My next design this will change.

Hi Deron,

Thanks for your comment.

I’ve not encountered any problems in IE so far because of using the closing comments, but I am aware that they can cause issues… as most things can in IE.

“I get in a habit of just naming columns left-content and right-content” I used to fall into this trap too. It really started to bite me when I started coding up sites and applications that needed to support multiple skins.

I forgot the name of the bug last night but it’s the “duplicate characters bug.” It’s really weird. When you place the comment in between floats it just starts duplicating characters from your content and throwing putting them at weird places in the page. It’s only IE6 though. I was thinking 7 had the problem too but I guess not. :)

I’ve never encountered that bug before. I knew there can be issues with whitespace and other randomness in IE, but I’d not heard of that one before. Thanks for pointing it out. I’ll keep my eyes peeled in future designs (I’ve quickly checked all old and current designs, no signs so far…).

Like what you see?

If you're looking for someone to help with the User Experience or Interaction design for your project, why not get in touch and we can talk through how I may be able to help.

Contact me now