Home Profile Projects Articles

The Three Cardinal Sins when writing HTML

Saturday, 15 of December , 2007 at 11:14 am

I had an interesting conversation with our local web guru at work yesterday about web standards. Although there is a lot of “technically” valid syntax when writing HTML, it doesn’t mean that a competent web developer should be using them. The worst mistake a web developer can make is when he starts merging the layout of the page with the style of the page. While working at Discovery, this concept has constantly been drilled into my head. The HTML should contain the structure of the page and the CSS should contain style. As a web developer, you should consider anything that breaks this rule as a cardinal sin. From my experiences, I have ran into three cardinal sins when writing HTML.

  1. Do not use any tags which alters the style, size, or position of any elements. This is by far the worst sin you can commit when writing HTML. I should never see <center> or <font> on your site! This may have been acceptable for HTML 1.0, but is definitely not acceptable now. Even the thought of using these tags should make you feel sick because no competent web developer should use them.

  2. Do not use any tag attributes which alters the style, size, or position of any elements. Although this a little better than using tags, it isn’t by much. Although it is tempting to use the align attribute (or other similiar attributes) to define the position of elements, please resist! It may save you a little bit of time in the immediately future… however, you will thank me the next time you need to change the style of your site.

  3. The last cardinal sin is to write your CSS inline with your HTML. For the inexperienced, the reason why this is bad may not be immediately obvious. The big reason is because separating your CSS and HTML makes your site more orthogonal. The idea behind orthogonality is that different concepts should be as independent as possible from each other. If you want to change the style (CSS), the structure of the page (HTML) should not be affected. For more information about orthogonality (and other programming concepts), I would suggest reading The Pragmatic Programmer. This concept in web development is often called the Model, View, and Controller which should be applied, also, when programming in PHP (or something equivalent).

Like any “sinner”, I have committed all these sins (and continue to do so). I may not completely understand the zen of web development, but it doesn’t mean I should accept bad practices.

Category: Programming

No Comments

No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> [tex]