Jump to navigation.

All too often, I see references to alt tags or float tags. Sometimes even from people who should know better. Here's a little guide to keep the nomenclature on the straight and narrow, reducing the risk of misunderstanding.

HTML

Example: <abbr title="Cascading Style Sheets">CSS</abbr>

  • The whole text is an abbr element.
  • <abbr title="Cascading Style Sheets"> is a tag (an opening tag).
  • </abbr> is a tag (a closing tag).
  • title="Cascading Style Sheets" is an attribute, whose name is title and whose value is Cascading Style Sheets.
  • CSS is the element's content.

CSS

Example: img {float:left}

  • The whole text is a ruleset.
  • img is a selector.
  • {float:left} is a block.
  • float is a property.
  • left is a value.

Well, that's all settled, then. :)


1. Posted by Robert Wellock, 20 July 2004 at 10:46

Dear Tommy, what do I call my <img> tag then; is it an element thingy, or a tag. I heard it was called a replaced element but if it's replaced where does it go...

Joking aside I think it tends to separate those that have actually bothered to read any official literature on (x)html from those who haven't.


2. Posted by Tommy Olsson, 20 July 2004 at 11:37

<img> is both a tag and an element. It is a replaced element, since it is replaced by the contents of an image file.

The XHTML version, <img/>, is called a self-closing tag or singleton tag, since there is no corresponding closing tag.


3. Posted by Patrick H. Lauke, 20 July 2004 at 12:55

"The XHTML version, <img/>, is called a self-closing tag or singleton tag, since there is no corresponding closing tag."

or self-closing element ;)


4. Posted by Tommy Olsson, 20 July 2004 at 12:57

<blushing>That's probably a more accurate accurate term for it, yes.</blushing>


5. Posted by Robert Wellock, 22 July 2004 at 11:23

I just normally refer to it as an empty element, but I bet you weren't expecting so much comments on this particular post.


6. Posted by Tommy, 22 July 2004 at 15:07

The term empty element is indeed correct, meaning that it has no content. But <p></p> is also an empty element, although it isn't self-closing.


7. Posted by Mike Abbott, 22 July 2004 at 16:08

Very nicely put. I'll now go and draw myself a diagram to remind myself :)


8. Posted by Jim, 10 August 2004 at 13:14

What you call <img> depends on the context.

If you are talking about the general concept of <img>, i.e. how it is described in the HTML specifications, then you are talking about the img element type.

Example: "The img element type isn't as flexible as the object element type."

If you are talking about a particular instance of this element type in a document, you are referring to an img element.

Example: "This img element will be positioned at the top of the page."

You almost never want to actually talk about an img tag, so I'll use another element type as an example.

If you are talking about the actual <table> tag itself, i.e. you are talking about the text <table, the attributes, and the following >, then and only then do you refer to it as a tag. If you are referring to the whole table, that's the element.

Example: "You've forgotten to put the final > on that table tag."

99% of the time, if you use the word "tag", you are using incorrect terminology. Tags are merely the syntax used to mark the beginning and ends of elements. When you talk about a document's structure, you should be referring to elements. When you talk about adding features to the next version of XHTML, you should be referring to element types.

If that's confusing, consider this analogy: a parking space is usually bordered by two straight white lines. Tags are the lines. The parking space as a whole is the element.

Saying something like "I think this text should be in an em tag" is like saying "I'll go and park in that line". It makes no sense, does it? Saying something like "I think this text should be in em tags" is like saying "I'll go and park inbetween those two lines. That makes more sense, but what you actually mean to say is "I think this text should be an em element", which is the equivalent of "I'll go and park in that space".


9. Posted by Tommy Olsson, 10 August 2004 at 13:22

Jim, that's a very good description. I must admit that I'm frequently lazy enough to say element when I really mean element type. I get away with it by claiming it's an elipsis... :)


10. Posted by Rob Mientjes, 10 August 2004 at 22:08

But <p></p> is also an empty element, although it isn't self-closing.

Why would anyone use empty <p>s? It's starting to feel all 1999 again, with <br><br><p><p><br><hr>... Spooky :p


11. Posted by Tommy Olsson, 11 August 2004 at 06:11

Hopefully, one wouldn't. I doesn't make sense. It was just an example of an empty element (that is not declared EMPTY in the DTD).

As we all know, XHTML should not be sent as text/html. If it is, however, it needs to be as similar to HTML as possible. That means we cannot use the self-closing syntax for element types which require a closing tag in HTML (e.g. <script>), because HTML parsers don't understand it.


Comments are disabled, due to excessive spamming.

Don't blame me. Blame the morons who are destroying the web by spamming.


Sections