Semantic HTML
Joseph Lindsay
ERMA New Zealand
Overview
- What is Semantic HTML?
- What it is
- Why it's important
- Some Practical HTML Examples
- How not to use it
- How to use it
Some definitions
- Syntax
- Sentence structure and language rules
- Semantic Markup
- Mark Pilgrim
…you use tags that have specific
meaning assigned to them, either in the (X)HTML specification, or in generally
accepted use.
- Jason Kottke
As much as possible, the tags surrounding the
content of a document should describe what that content is and/or what it's for.
…more
- HTML is for describing the structure and meaning
of content – not for describing presentation
- Semantics of HTML 4.01 and XHTML 1.0 are identical, the
syntax is different
- This presentation is related to, but not about "The Semantic Web"
In the beginning…
- On the 6th day God (a.k.a. Sir Tim Berners-Lee)
created the WWW (sort of)
- Originally designed for sharing scientific
documents and data
- Simple
- Designed for easy use
- About 20-30 elements
HTML Version 2.0
- RFC 1866. Proposed Standard
- November 1995
- Added elements that represented the current "State
of Play" from browser developers
- Became application of ISO 8879:1986 -
Standard Generalized Markup Language (SGML)
- Backwards compatible
Versions 3-4
- Added more complex elements and attributes
- Tables
- Framesets
- Objects
- Removed or deprecated some elements
ISINDEX
APPLET
CENTER
FONT
BASEFONT
STRIKE
S
U
DIR
MENU
- Backwards Compatible
Current version
- HTML 4.01
- 24 December 1999
- 3 Versions
- Strict
- Transitional
- Frameset
Aside: HTML vs. XHTML
- Transitional to Strict is a bigger step than HTML
to XHTML
- Until browser manufacturers implement standards
properly, there are no real benefits in using XHTML over HTML
- HTML is Backwards Compatible
- I.E., it should still work in older browsers
- XHTML may not work
The pedant's view
A good web page is made up of layers
- Copy (the text)
- Semantics (
<h1>, <ol>, <p>)
- Structure (
<head>, <body>, <div>)
- Presentation (CSS)
- Behaviour (JavaScript)
The speaker's analogy
- Monotone, mono-rhythmic speech
- Changing tone to indicate meaning
- Changing rhythm/timing to indicate structure
(punctuation)
- Facial expression
- Body language
The real world
- HTML doesn't have an element for everything
- Not everything can be separated
- Diminishing returns
- Many clients/bosses/users are only interested in visual aspects
Mark Pilgrim
In visual browsers it doesn't really matter whether you use
semantically correct markup or generic markup that happens to look the same,
because the meaning of your page is going to be determined by the human being
with eyes who reads it on a screen.
Increasing your HTML vocabulary
"We went to the park. I rode on my bike."
"On Saturday, Dad took me and Oscar to the BMX
track. We rode there on our bikes, but Dad carried Oscar across the road."
Some real examples
<head> elements
<title>, <link>
- Headings
<h1> - <h6>
- Forms
<label>
- Lists
- navigation lists
- Citations and Quotations
<blockquote>, <q>, <cite> and cite attribute
The <title> element
W3C
Authors should use the <title> element to identify the contents of a document.
Since users often consult documents out of context, authors should provide
context-rich titles. Thus, instead of a title such as "Introduction", which
doesn't provide much contextual background, authors should supply a title such
as "Introduction to Medieval Bee-Keeping" instead.
Benefits of a good <title>
- Presentation in search engines
- Most search engines use
<title> element as link text
in search results
- Most search engines give high relevancy to title
text
- Bookmarks/favourites
- Most browsers use the
<title> element for bookmark
text
Examples of the <title> element
The benefit

The <link> Element
W3C
This element defines a link. Unlike A, it may only
appear in the HEAD section of a document, although it may appear any number of
times. Although LINK has no content, it conveys relationship information that
may be rendered by user agents in a variety of ways (e.g., a tool-bar with a
drop-down menu of links).
Benefits of good <link>s
- Some User Agents have navigation bars that use it
- Opera, Firefox (with Extension)
- Non-human users
- Search engines
- Discovery tools
Some examples of the <link> element
- Good: the
W3C, most blog software (WordPress, Moveable Type)
- Not so good: just about everyone else, although it's improving
- Most use
<link> element for stylesheets
Heading elements
W3C
A heading element briefly describes the topic of
the section it introduces. Heading information may be used by user agents, for
example, to construct a table of contents for a document automatically.
There are six levels of headings in HTML with H1 as
the most important and H6 as the least. Visual browsers usually render more
important headings in larger fonts than less important ones.
Benefits of good headings
- TOCs, heading lists (screen readers)
- Search engines give extra weight to headings
- Users "scan" web pages
- Clear hierarchy of information
Some examples of heading elements
The <label> element
W3C
Some form controls automatically have labels associated with them (press
buttons) while most do not (text fields, checkboxes and radio buttons, and
menus).
For those controls that have implicit labels, user agents should use the
value of the value attribute as the label
string.
The <label> element is used to specify labels for controls that do not
have implicit labels
Benefits of <label> element
- Larger "clickable" area (Fitt's law)
- Better for non-visual UAs
Some examples of the <label> element
Lists
- Frequently used in the wrong situation
- Frequently not used where they should be
Incorrect non-use of Lists
Navigation Lists with style
Quotations and Citations
<blockquote> is for larger quotes (block element)
<q> is for smaller, inline quotes (inline element)
<cite> is for a citation or reference to other
sources (inline element)
- The value of
cite attribute is a URI that
designates a source document or message (unique to <blockquote>, <q>, <ins> and
<del>)
<blockquote> != "indent this text"
Examples of Quotations and Citations
The usual method – short quote:
<p>As Bill Gates said, "640K should
be enough for anybody."</p>
Examples of Quotations and Citations
The way W3C intended – short quote:
<p>As <cite>Bill Gates</cite> said,
<q cite="http://tinyurl.com/9dr2t">640K should
be enough for anybody.</q></p>
W3C
Visual user agents must ensure that the content of the <q> element is rendered with delimiting quotation marks.
Examples of Quotations and Citations
Longer Quote
<p>blah…<cite>Bill Gates</cite> said:</p>
<blockquote cite="http://tinyurl.com/b2xzh">
<p>Information technology and business are
becoming inextricably interwoven. I don't think
anybody can talk meaningfully about one without the
talking about the other.</p></blockquote>
Elements without semantics
<div> and <span>
- No semantic meaning, although semantics can be added
to class and id attributes
<br>, <b> and <i>
- No semantic meaning, but do affect presentation in
visual browsers
Use class with Semantics in mind
- Bad names
- white3pxborder, page2bg, left, newstyle
- Good names
- warning, important, alert, submenu
- Describes the content, not the appearance
- A warning will always be a warning, even if its
presentation changes
It's OK to use <b> and <i>
- Sometimes there is not an HTML element for content
that needs presentational styling
- Taxonomical names
- Text in other languages
- She has a je ne sais quoi about her
Summary
- Semantics are determined by the user
- The user is not always human
- HTML does not have an element for everything, but has a lot of elements that are not widely used
- Think about what the content is and why you want it to look a certain way
Finally…
Inline styling hook – which is better:
<span> or <b>?