General XHTML Patterns
This section covers general patterns used when producing XHTML that are not specific to ebooks.
id
attributes
id
attributes of <section>
and <article>
elements
Each
<section>
and<article>
element has anid
attribute.<section>
or<article>
elements that are direct children of the<body>
element have anid
attribute identical to the filename containing that<section>
or<article>
, without the trailing extension.In files containing multiple
<section>
or<article>
elements, each of those elements has anid
attribute identical to what the filename would be if the section was in an individual file, without the trailing extension.
id
attributes of other elements
id
attributes are generally used to identify parts of the document that a reader may wish to navigate to using a hash in the URL. That generally means major structural divisions. Therefore, elements that are not<section>
or<article>
elements do not have anid
attribute, unless a part of the ebook, like an endnote, refers to a specific point in the book, and a direct link is desirable.id
attributes are not used as hooks for CSS styling.If an element that is not a
<section>
or<article>
requires anid
attribute, the attribute’s value is the name of the element followed by-N
, whereN
is the sequence number of the element start at1
.
class
attributes
Classes denote a group of elements sharing a similar style.
Classes are not used as single-use style hooks. There is almost always a way to compose a CSS selector to select a single element without the use of a one-off class.
Classes are used to style a recurring class of elements, i.e. a class of element that appears more than once in an ebook.
Class names describe what they are styling semantically, not the actual style the class is applying.
xml:lang
attributes
When words are required to be pronounced in a language other than English, the
xml:lang
attribute is used to indicate the IETF language tag in use.The
xml:lang
attribute is used even if a word is not required to be italicized. This allows screen readers to understand that a particular word or phrase should be pronounced in a certain way. A<span xml:lang="TAG">
element is used to wrap text that has non-English pronunciation but that does not need further visual styling.The
xml:lang
attribute is included in any word that requires special pronunciation, including names of places and titles of books.
The
xml:lang
attribute is applied to the highest-level element possible. If italics are required and moving thexml:lang
attribute would also remove an<i>
element, the parent element can be styled withbody [xml|lang]{ font-style: italic; }
.
The <title>
element
The
<title>
element contains an appropriate description of the local file only. It does not contain the book title.
Titles of files that are an individual chapter or part division
Convert chapter or part numbers that are in Roman numerals to decimal numbers. Do not convert other Roman numerals that may be in the chapter title.
If a chapter or part is only an ordinal and has no title or subtitle, the
<title>
element isChapter
followed by the chapter number.If a chapter or part has a title or subtitle, the
<title>
element isChapter
, followed by the chapter number in decimal, followed by a colon and a single space, followed by the title or subtitle.
Titles of files that are not chapter or part divisions
Files that are not a chapter or a part division, like a preface, introduction, or epigraph, have a
<title>
element that contains the complete title of the section.If a file contains a section with a title or subtitle, the
<title>
element contains the title, followed by a colon and a single space, followed by the title or subtitle.
Headers
<header>
elements have at least one direct child block-level element. This is usually a<p>
element, but not necessarily.
Ordered/numbered and unordered lists
All
<li>
children of<ol>
and<ul>
elements have at least one direct child block-level element. This is usually a<p>
element, but not necessarily; for example, a<blockquote>
element might also be appropriate.
Tables
<table>
elements have a direct child<tbody>
element.<table>
elements may have an optional direct child<thead>
element, if a table heading is desired.<th>
elements are used in<thead>
elements, instead of<td>
.<th>
elements only appear in<thead>
elements, unless they contain thescope
attribute set to eitherrow
orrowspan
. Thescope
attribute set to those values may be used to semantically identify a table header which applies to a horizontal row instead of a vertical column.
<table>
elements that are used to display tabular numerical data, for example columns of sums, have CSS styling for tabular numbers:{ font-variant-numeric: tabular-nums; }
.
Blockquotes
<blockquote>
elements must contain at least one block-level child, like<p>
.Blockquotes that have a citation include the citation as a direct child
<cite>
element.
Definition lists
Definition lists, i.e. combinations of the <dl>
, <dt>
, and <dd>
elements, are often found in glossaries.
<dd>
elements have at least one direct child block-level element. This is usually a<p>
element, but not necessarily.