Summary

Ensuring all identifiers are unique prevents problems navigating and accessing the content.

Techniques

Examples

Example 1 — Using UUIDs for uniqueness

A UUID is used in the id attribute because it has a very high probability of being unique. In (X)HTML5 the UUID can start with a letter or number, but in XML formats it must start with a letter.

<section id="fad1bb2a-ecdc-4cb5-886f-aedbd7cb2adb">
Example 2 — Using mnemonics

A mnemonic is a naming convention that helps identify the content. In this case, c01 is used for "Chapter 1". Mnemonics are often a bad choice, as they have to be updated whenever content is shifted or remixed.

<section id="c01">
   <h2>Chapter 1</h2>

Explanation

If all the id attributes in a document are not unique, the user agent will not understand which one is being referred to. For example, if a user is trying to navigate to a specific section, the user agent will not be able to determine which one to go to. It might take the user to the first section with the identifier, or it might leave the user at the top of document.

Other than being unique, the only requirement for identifiers in (X)HTML5 is that they not contain spaces.

Identifiers do not have to be unique across documents, although it is good practice to ensure uniqueness of all identifiers.

EPUB

Although (X)HTML5 allows any character string as an identifier, XML and XHTML 1.1 rules are stricter rules (e.g., identifiers cannot start with a number or include colons). Invalid identifiers in these cases, such as in EPUB 2 publications, cause XML errors that may lead to errors being display instead of content.

Related Links