Should HTML5 spec correct the img element definition?
The <img> element is one of the more difficult HTML elements to use correctly. Part of the problem is caused by the unhelpful definition of the <img> element in the HTML specification.
HTML5 tries to correct the definition of some elements
HTML 4 contains a number of elements whose definition does not match the correct or best practice use of the elements. The following are some examples from the HTML 4 specification:
- The
<a> element is defined as an "anchor", whereas the correct use of this element is as a hyperlink. There is no need for a dedicated anchor element because any element can be an anchor if it has an id attribute. - The
<hr> element is defined as "[causing] a horizontal rule to be rendered by visual user agents", whereas the correct use of this element is as a content separator. - The
<table> element is defined as "[containing] all other elements that specify caption, rows, content, and formatting", whereas the correct use of this element is for organizing tabular data.
As a consequence, tool vendors built tools that encouraged the incorrect use of these elements, educators wrote books and tutorials that taught others the incorrect use of these elements, and Web site creators who read the spec for themselves also used these elements incorrectly.
HTML5 tries to correct the definition of these elements. Here is how HTML5 defines them:
- If the
<a> element has an href attribute, then it represents a hyperlink (a hypertext anchor). - The
<hr> element represents a paragraph-level thematic break, e.g. a scene change in a story, or a transition to another topic within a section of a reference book. - The
<table> element represents data with more than one dimension, in the form of a table.
Could the HTML5 definition of these elements be better written? Yes, because as they are, they are a little hard to understand. But it's a step in the right direction.
Time to correct the definition of img element
The HTML5 spec defines the <img> element as an element that "represents an image". The spec then defines alternate text (textual content) as "fallback content". What's wrong with this? These definitions suggest that the visual content (the image) is more important than the textual content. As a result, to many people, if the primary purpose of embedding an image is achieved, the secondary or fallback purpose (textual content) can be skipped or given cursory effort.
The following is a better way to describe the <img> element that gives equal weight to the visual and textual content: "The img element represents content that can be rendered visually (as an image) and textually. The src attribute provides visual content in the form of an image and the alt attribute provides textual content. The content in the src and alt attributes must convey equivalent meaning."
The principle behind this definition is already in practice in a publicly available HTML reference.
Conclusion
The <img> element's visual content and its textual content are equivalent in meaning and should therefore be of equal importance. How elements are defined in the specification influences tool vendors, educators and ultimately Web site creators, so that clearly defining the correct use of HTML elements can over time improve the use of HTML.
Comments are closed for this article.