A .docx file is a ZIP archive that follows the Open Packaging Conventions
(OPC), Part 2 of ECMA-376 and ISO/IEC 29500. Each ZIP member is a part. Parts do
not find each other by name: a part’s relationships say which others it uses, and
[Content_Types].xml says what each part is.
Parts and part names
A part name is the member’s path with a leading /, such as
/word/document.xml. Part names are compared without regard to the case of
ASCII letters, and may contain percent-encoded characters. ZIP folders have no meaning in
a package: only the parts do.
Word keeps a conventional layout, but other writers may use other names, so a reader finds the parts through the relationships and not by name. The usual parts of a document are:
| Part | Holds |
|---|---|
[Content_Types].xml | The media type of every other part. |
_rels/.rels | The package’s relationships: the main document and the properties. |
word/document.xml | The main document: text, tables, section properties. See document.xml. |
word/_rels/document.xml.rels | The main document’s relationships. |
word/styles.xml | Styles. |
word/numbering.xml | Numbering definitions for lists and headings. |
word/settings.xml, word/webSettings.xml, word/fontTable.xml, word/theme/theme1.xml | Settings, fonts and the theme. |
word/footnotes.xml, word/endnotes.xml | Footnotes and endnotes. |
word/comments.xml | Comments. |
word/header1.xml, word/footer1.xml | Headers and footers. |
word/media/ | Pictures and other media. |
word/embeddings/ | Embedded files: other Office documents and OLE objects. |
word/vbaProject.bin | The macro project of a .docm or .dotm file. |
word/glossary/document.xml | Building blocks: reusable pieces of content, with its own styles, settings and fonts. |
customXml/item1.xml | XML data stored with the document, often for content controls. |
docProps/core.xml, docProps/app.xml, docProps/custom.xml | Document properties. |
docProps/thumbnail.jpeg | A small picture of the first page, when one was saved. |
[Content_Types].xml
This part, at the root of the archive, gives the media type of every part. A
Default element gives the type for an extension. An Override
gives the type of one part and takes priority over a Default.
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
<Default Extension="xml" ContentType="application/xml"/>
<Default Extension="png" ContentType="image/png"/>
<Override PartName="/word/document.xml"
ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
<Override PartName="/word/styles.xml"
ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/>
</Types>
The main part’s content type tells the four kinds of Word file apart:
| Extension | Main part content type |
|---|---|
.docx | application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml |
.docm | application/vnd.ms-word.document.macroEnabled.main+xml |
.dotx | application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml |
.dotm | application/vnd.ms-word.template.macroEnabledTemplate.main+xml |
Other WordprocessingML parts have types of the form
application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml:
styles, settings, webSettings,
fontTable, numbering, footnotes,
endnotes, comments, header and
footer. The glossary document is
…wordprocessingml.document.glossary+xml.
Relationships
A part’s relationships are in a part beside it: the relationships of
/word/document.xml are in /word/_rels/document.xml.rels. Those
of the package itself are in /_rels/.rels.
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"
Target="styles.xml"/>
<Relationship Id="rId2"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
Target="https://www.example.com/" TargetMode="External"/>
</Relationships>
| Attribute | Meaning |
|---|---|
Id | Unique within this relationships part. XML in the source part refers to it, as r:id="rId1". |
Type | A URI naming the kind of relationship. |
Target | The target part, relative to the source part’s folder, or absolute if it starts with /. For an external target, a URI. |
TargetMode | Internal (the default) or External: the target is outside the package. |
The relationship types used in Word files, all with the prefix
http://schemas.openxmlformats.org/officeDocument/2006/relationships/
unless shown otherwise:
| Type | From | To |
|---|---|---|
officeDocument | Package | The main document. |
http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties | Package | Core properties. |
extended-properties | Package | Application properties. |
custom-properties | Package | Custom properties. |
http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail | Package | Thumbnail image. |
styles, numbering, settings, webSettings, fontTable, theme | Main document | The part of that kind. |
header, footer | Main document | One header or footer. |
footnotes, endnotes, comments | Main document | The notes or comments part. |
image | Any part with text | A picture. May be external. |
hyperlink | Any part with text | A link target, usually external. |
oleObject, package | Any part with text | An embedded object or embedded Office file. |
customXml | Main document | A custom XML data part. |
glossaryDocument | Main document | The building blocks document. |
attachedTemplate | Settings | The template the document was based on, usually external. |
http://schemas.microsoft.com/office/2006/relationships/vbaProject | Main document | The macro project. |
Because the target of a relationship can be any URI, a document can point outside itself: a linked picture, a remote template. The viewer on this site lists such targets and never fetches them.
Reading a package
- Read the ZIP central directory and find
[Content_Types].xml. - Read
_rels/.relsand follow theofficeDocumentrelationship to the main part. - Check that part’s content type, and that its root element is
w:document. - Read the main part’s relationships for its styles, numbering, headers, pictures and so on, and follow only those it uses.
Members of a package are normally Deflate-compressed or stored, and the package format
does not encrypt anything. A password-protected Word file is not a ZIP archive at all: it
is a Compound File that holds the encrypted package in a stream named
EncryptedPackage.
The ZIP structure itself is described on the ZIP archive pages.