Archive for October, 2008

After the storm

Thursday, October 23rd, 2008

sfter the storm on flickr

after the storm

Coalcliff is not famous for its beach. Actually, Coalcliff is not famous. It is really rather nice though, especially after a big spring storm.

Anatomy of html

Thursday, October 23rd, 2008

A mark of any group is their shared language; and a mark of any group involved in a craft is the technical precision of their language. Brick layers, dentists, lithographers and chefs all know what each other mean when they refer to a particular item. Web professionals are no different. Most of the people working on and with the web, however, are not web professionals; even some who should be are not. For those of you who are, what I am about to describe is blindingly obvious. So you can stop reading now.

A few years ago I embarked on a mission to educate the team in my day job. I got them all to refer to all the bits that make up HTML and CSS by the correct names, This was done partly so they could explain to me what they want, partly because I am a neurotic labeller, but mostly because they wanted to be professionals in their field and so needed to use the language correctly. Things, and teams, change and just this week, for the first time in over two years, I heard someone who would consider himself a web professional use the term alt tags.

There are no alt tags

Never were.

Anyone involved in web production who refers to image elements’ alternate text attribute as alt tags is a moron.

The basic unit of HTML is an element. A tag is part of an element. An element Starts with an opening tag. This is the angle-bracket stuff, and ends with a closing tag. The element is everything between the opening tag and the closing tag including the tags themselves. Self closing elements don’t have a closing tag and the element is equivalent to the tag.

Note I stated that an element is everything from the < of the opening tag to the > of the closing tag – inclusive. Therefore an element can (and often does) contain other elements. The DTD describe the allowed content for each element. For the purposes of the rest of this rant I will describe elements which require a closing tag as per the HTML 4 DTD. The accompanying image outlines all this in much clearer fashion so I apologise to anyone who cannot view it. Those of you who choose not to view it can just deal.

A representation of the parts of an HTML element

A representation of the parts of an HTML element

The opening tag may contain attributes. An attribute consists of name/value pairs represented as the name, equals sign and value, white space is ignored. In HTML 4 some attributes may be entered as singletons; that is as a name only with the value implied, I don’t consider this good practice but there is no reason not to do it. Attribute values ought to be quoted. This is required in XHTML. In HTML quotes are optional for single word values; this is really bad practice and you ought to quote all attribute values. An image’s alternate text is an attribute. Some attributes are required by certain doctypes, the alternate text attribute of an imgage element being one such required attribute.

There are some restrictions on attribute values but these are often specific to certain attributes. For example the id attribute’s value should not start with a numeric. Some parsers seem to expect some attributes in a particular order. The W3C HTML validator seems to chuck a wobbly if an image element’s opening tag has something other than a source attribute as the first attribute. This is not strictly required.

A (non-self-closing) HTML element usually contains child nodes. These may be other elements or text nodes (which is just text and is usually referred to as text except by weird DOM-nerds). White space only text nodes usually exist within a DOM tree but can be ignored for most cases except when traversing the tree.

Some elements are restricted in what they can contain as child nodes. An unordered list element, for example, may only contain list item elements as its child nodes and (in HTML 4.01) a fieldset element must contain a legend element. There are some general rules of thumb to make this a little clearer (these rules omit the possible existance of whitespace text nodes withing the DOM tree):

  • inline elements must not contain block elements;
  • block elements except the paragraph element (<p></p>) may contain other block elements;
  • ordered and unordered list elements must contain list item elements as their immediate descendents;
  • definition list elements must contain definition term and definition data elements as their immediate descendents;
  • select elements must contain option elements or option group elements as their immediate descendents and option group elements may only contain option elements;
  • uou cannot nest forms (which stuffs up many ASP applications) or textareas;
  • use your common sense!