# EPUBCheck OPF-004: malformed prefix attribute, how to fix it

Source: https://epubcc.com/epubcheck/opf-004/ (updated 2026-11-04)

EPUBCheck OPF-004 is a warning message: “Invalid prefix declaration: leading or trailing whitespace is not allowed.” The prefix attribute on the package element is not written in the syntax EPUB requires. That attribute maps short prefixes (such as ibooks) to vocabulary URIs, and EPUBCheck reports each kind of syntax mistake with its own variant of OPF-004.

- Official message (EPUBCheck 5.4.0): Invalid prefix declaration: leading or trailing whitespace is not allowed.
- Default severity: Warning

## Typical causes

- OPF-004: spaces or line breaks at the start or end of the attribute value; OPF-004a: an empty prefix, a colon with no name before it.
- OPF-004b: a prefix name that is not a valid XML name (NCName), for example one starting with a digit or containing a slash; OPF-004c: a space between the name and its colon, as in "ibooks : http://…".
- OPF-004d: no space between the colon and the URI, as in "ibooks:http://…"; OPF-004e: a tab, line break or other illegal whitespace between the prefix and the URI.
- OPF-004f: mappings separated by something other than plain whitespace, or run together.

## How to fix it

1. Find the prefix attribute on the package element of the .opf file.
2. Write each mapping as the prefix name, a colon, one space and the vocabulary URI, and separate mappings with whitespace, for example prefix="ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/ foaf: http://xmlns.com/foaf/spec/".
3. Remove whitespace at the start and end of the value, give every mapping a name that starts with a letter (letters, digits, hyphens and underscores only), and put the colon right after the name.
4. Reserved prefixes such as dcterms, rendition and schema need no declaration, so you can often delete the attribute entirely if it only maps those.

## When it's not this

If the syntax is right but a prefix has no URI or an invalid one, that is OPF-005 or OPF-006.

## Sources

- EPUB 3.3, §D.1.4 The prefix attribute: https://www.w3.org/TR/epub-33/#sec-prefix-attr (read 2026-11-04)

Message text and severity: EPUBCheck (W3C, BSD-3-Clause). Explanation: EpubCC.
