|
home—lects—exams—hws
D2L—breeze (snow day)
id — specify a unique node. The same value can't be used for the id attribute of two different tags. (And, it's wise to not even have two different ids which differ only in case.)
The id is commonly used for:
name - specify a set of nodes. All the related nodes can use the same value for their name attribute, to indicate their relation.
The name is commonly used for:
There are also entities. —, …. An entity represents an atomic2 piece of information: often a single glyph/fancy-charcater, but in theory you could use an entity for a logo or a motto.
There are five entities that are common to any xml (not just html/xhtml):
The most common (non-X)HTML example using improperly nested tags is <p>, which (in HTML) doesn't need to be closed; the browser auto-closes the tag when it reaches the next <p> (or more precisely: when it reaches the next block-level open-tag, or a close-tag which is terminating the enclosing block, e.g. if the paragraph was already inside an itemized list).
Browsers tend to go to great lengths to try to make sense of tag soup; just because a page looks fine in your browser doesn't mean it's legal. The result is that many people learned their HTML by doing a show-source on bad, illegal examples, and then propagating that bad HTML, and never realizing it because most browsers still did something reasonable (although the details of how a browser handled bad HTML are of course entirely non-standard).
Important: In HTML (and enforced by most modern browsers), you can only use the self-closing tag, for those tags which never are allowed a body. For tags that may or may not have a body (e.g.script ), you cannot use the self-closing version even when you want an empty body. There is no good reason for this!
- <hr />— fine;
hr never has a body.- <img src="foo.jpg" />— fine;
img never has a body.- <script type="text/javascript" src="foo.jpg"></script>— fine.
- <script type="text/javascript" >callSomeFunction();</script>— fine.
- <script type="text/javascript" src="foo.jpg" />— BAD; a browser may ignore the tag entirely!, which is an annoyingly difficult bug to track down.
2 common “dummy” tags: span, div. These are used when you want to group several in-line elements (or, block-elements resp.) They don't have any native meaning to HTML — they are solely for allowing the author to group things together than don't otherwise have a tag, and perhaps attach a style to them.
For example, you might want to give a “name” attribute to every mention of an indian-tribe in your document. But the tribe-names are just regular text, so there isn't a natural a or cite or tag to use. Instead we can put them in a span tag:
This has no effect on mark-up. span and div are commonly used to apply a class attribute to a section of a page (andThe <span name="clan">Catawba tribe</span> and the <span name="clan">Powhatan Confederacy</span> each roamed the part of the earth now known as “Virginia”.
1
In practice, you don't need to avoid all five characters — it's enough to just avoid &,
and avoid < followed by non-whitespace.
Also the term “pc-string” is not quite that standard use of "parsed character".
↩
2 That's “atomic information” as in it can't be divided into sub-chunks, not “atomic information” like “the iron atom has 26 protons”. ↩
3A best practice…and yet: ugh! ↩
home—lects—exams—hws
D2L—breeze (snow day)
©2012, Ian Barland, Radford University Last modified 2013.Mar.04 (Mon) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |