Answers.Body: <p>The files and directory structure of the EPUB files is specified in the OCF (OpenContainerFormat). There are two versions are most interesting: <a href="http://idpf.org/epub/20/spec/OCF_2.0.1_draft.doc" rel="noreferrer">2.0.1</a> and <a href="http://www.idpf.org/epub/301/spec/epub-ocf.html" rel="noreferrer">3.0.1</a>. Both specify only <strong>one</strong> required file in a specific subdirectory, and that is:</p>
  
  <pre><code>META-INF/container.xml
  </code></pre>
  
  <p>There are some optional files that can go in that directory as well (<code>signatures.xml</code>, <code>encrytpion.xml</code>, <code>metadata.xml</code>, <code>rights.xml</code>) and a file named <code>manifest.xml</code> is allowed there as well.</p>
  
  <p>The <code>container.xml</code> refers to the full path of one or more files, which names are essentially free and the directory structure as well.</p>
  
  <p>Of course some programs generate EPUB files always with the same structure. That is why it might seem that you need a <code>content.opf</code> in the root of the EPUB (zip) file structure, but that is only a valid name in any particular EPUB if and only if it is named in a <code>&lt;rootfile&gt;</code> element in the <code>container.xml</code>.</p>
  
  <p>The contents file (with references to the individual) HTML files which together form the e-book could be:</p>
  
  <pre><code>TOC/TableOfContents.opf
  </code></pre>
  
  <p>and the HTML files could be</p>
  
  <pre><code>LOTR/The_Fellowship_of_the_Ring.htm
  LOTR/The_Two_Towers.htm
  LOTR/The_Return_of_the_King.htm
  </code></pre>
  
  <p>as long as the paths of files, specified internally starting from <code>container.xml</code> are correct.</p>
  
  <p>As Mark pointed out a <code>mimetype</code> file needs to be present. Actually according to the <a href="http://idpf.org/epub/20/spec/OCF_2.0.1_draft.doc" rel="noreferrer">2.0.1</a> spec (page 7, bottom) that file has to be the first file in the EPUB file's ZIP structure. </p>
  
  <p>The only names in the root directory reserved by the <a href="http://idpf.org/epub/20/spec/OCF_2.0.1_draft.doc" rel="noreferrer">2.0.1</a> are <code>mimetype</code> and <code>META-INF</code>. The use of a specific folder (<code>LOTR</code> in the example) is recommended (to prevent collisions when there are multiple renditions), but not required.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2013-12-22T23:19:14.220Z
Answers.Text: The OCF also requires the file mimetype in the root as far as I can see
Answers.UserDisplayName: mmmmmm
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2013-12-20T15:20:01.603Z
Answers.LastActivityDate: 2013-12-23T05:18:42.433Z
Answers.LastEditDate: 2013-12-23T05:18:42.433Z
Answers.UserDisplayName: Anthon
Answers.Body: <p>An EPUB file is just a zip file. Copy mybook.epub to mybook.zip, and use your favorite zip tool to open the zip file. You should see some XHTML files and images somewhere in there, along with an OPF file, manifest, and some other control files. Windows 7+ natively treats zip files as a folder. </p>
  
  <p>XHTML is similar to HTML but is more strict, and the bold and italic tags are different.</p>
  
  <p>Below is a screen shot of a test2.epub I copied to test2.zip. The screenshot only shows the root dir of the epub.
  <a href="https://i.sstatic.net/O4RQi.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/O4RQi.jpg" alt="enter image description here"></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-09T10:50:40.903Z
Answers.LastActivityDate: 2018-07-09T10:55:42.357Z
Answers.LastEditDate: 2018-07-09T10:55:42.357Z
Answers.UserDisplayName: Bulrush
Answers.Body: <p>EPUB is an open format so you can find the <a href="http://www.idpf.org/epub/30/spec/epub30-overview.html">standard specifications online.</a> Wikipedia has a good <a href="http://en.wikipedia.org/wiki/EPUB">article</a> on the EPUB format. </p>
  
  <p>If you want a brief description of the characteristics you just mentioned you can find in <a href="http://www.hxa.name/articles/content/epub-guide_hxa7241_2007.html">this article here</a>.</p>
  
  <p>Directory structure:</p>
  
  <pre><code>EpubFolderYouWant
     META-INF
        container.xml
     mimetype
     content.opf
     toc.ncx
  </code></pre>
  
  <p>Needed files:</p>
  
  <pre><code>mimetype
  container.xml
  content.opf
  toc.ncx
  </code></pre>
  
  <p>And which information is contained in each file is described in the <a href="http://www.hxa.name/articles/content/epub-guide_hxa7241_2007.html#packageandcontainerfiles">above mentioned article</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2013-12-20T15:22:14.753Z
Answers.Text: I have hundreds of EPUB files that do not have an `content.opf` file nor a `toc.ncx`. I am pretty sure those are not needed.
Answers.UserDisplayName: Anthon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2013-12-20T15:33:08.400Z
Answers.Text: @Anthon They are not needed for personal use but some retailers require a standard and use IDPF as the base of said standard, as posted above, so in a way the `.opf` is required but `.ncx` file is required for ePub 2.0.
Answers.UserDisplayName: DᴀʀᴛʜVᴀᴅᴇʀ
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2013-12-20T15:48:23.040Z
Answers.Text: @Matt_2.0 I might miss something but I only see the need for a file with `id="ncx"`, that might be often have a path `toc.ncx` but AFAIK any path can be specified in the `href` of that item. Relying on the extended navigation center to be in `toc.ncx` is as dangerous and unnecessary as relying on "the" `opf` file to be called `content.opf`. That some retailers use specific names and `container.xml` contents to accommodate their software or their work-flow does, IMHO, not make make that an EPUB standard the OP asked about.
Answers.UserDisplayName: Anthon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2013-12-20T16:14:16.263Z
Answers.Text: I think I am miss understanding your comment but an `.opf` file or a `.ncx` file can be titled anything as long as they are present.  A `.ncx` file, per ePub 2.0 complacency requires it to be present to be validated.  To be a valid ePub 3.0 or 2.0 `.opf` with a correct `mimetype`; `doctype`, `<metadata>`, `<manifest>` and `<spine>` must be present within the `.opf` file and the `.ncx` was replaced with the `toc.xhtml` but the `.ncx` is optional.
Answers.UserDisplayName: DᴀʀᴛʜVᴀᴅᴇʀ
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2013-12-20T13:06:01.250Z
Answers.LastActivityDate: 2013-12-20T13:19:57.077Z
Answers.LastEditDate: 2013-12-20T13:19:57.077Z
Answers.UserDisplayName: Eduard Florinescu
Body: <p>I know from sources I do not remember anymore, that an epub file is a valid zip file containing (among other files) chapters as <code>*.xhtml</code> files, a manifest file <code>content.opf</code> and a table of contents file <code>toc.ncx</code>.</p>
  
  <ul>
  <li>What is the file and directory structure of an unpacked epub?</li>
  <li>Which files must be there (with fixed names?) and are there optional files?</li>
  <li>What information is stored in the single files?</li>
  </ul>
  
  <p>I am asking for a very basic epub file, so the version should not matter, but assume epub2 in case it makes a difference for you.</p>
  
  <p>PS: I will probably ask for the content and structure of those files later, but for now I only want to know about which files are mandatory or optional and an overview what they contain, to keep the question more specific and answers short.</p>
  
Tags: <epub><file-format><editing>
Title: How is an epub structured internally?
UserDisplayName: Tim
ThreadText: # How is an epub structured internally?
  
  (Asked by: username_0 on 2013-12-20)
  
  I know from sources I do not remember anymore, that an epub file is a valid zip file containing (among other files) chapters as `*.xhtml` files, a manifest file `content.opf` and a table of contents file `toc.ncx`.
  
  * What is the file and directory structure of an unpacked epub?
  * Which files must be there (with fixed names?) and are there optional files?
  * What information is stored in the single files?
  
  I am asking for a very basic epub file, so the version should not matter, but assume epub2 in case it makes a difference for you.
  
  PS: I will probably ask for the content and structure of those files later, but for now I only want to know about which files are mandatory or optional and an overview what they contain, to keep the question more specific and answers short.
  
  **Tags:** epub, file-format, editing
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_4 on 2013-12-20. Score: 13 | Accepted answer
  
  EPUB is an open format so you can find the [standard specifications online.](http://www.idpf.org/epub/30/spec/epub30-overview.html) Wikipedia has a good [article](http://en.wikipedia.org/wiki/EPUB) on the EPUB format.
  
  If you want a brief description of the characteristics you just mentioned you can find in [this article here](http://www.hxa.name/articles/content/epub-guide_hxa7241_2007.html).
  
  Directory structure:
  
  ```
  EpubFolderYouWant
     META-INF
        container.xml
     mimetype
     content.opf
     toc.ncx
  
  ```
  
  Needed files:
  
  ```
  mimetype
  container.xml
  content.opf
  toc.ncx
  
  ```
  
  And which information is contained in each file is described in the [above mentioned article](http://www.hxa.name/articles/content/epub-guide_hxa7241_2007.html#packageandcontainerfiles).
  
  > **Comments:**
  > **username_1**: I have hundreds of EPUB files that do not have an `content.opf` file nor a `toc.ncx`. I am pretty sure those are not needed.  
  > **username_5**: @username_1 They are not needed for personal use but some retailers require a standard and use IDPF as the base of said standard, as posted above, so in a way the `.opf` is required but `.ncx` file is required for ePub 2.0.  
  > **username_1**: @Matt_2.0 I might miss something but I only see the need for a file with `id="ncx"`, that might be often have a path `toc.ncx` but AFAIK any path can be specified in the `href` of that item. Relying on the extended navigation center to be in `toc.ncx` is as dangerous and unnecessary as relying on "the" `opf` file to be called `content.opf`. That some retailers use specific names and `container.xml` contents to accommodate their software or their work-flow does, IMHO, not make make that an EPUB standard the OP asked about.  
  > **username_5**: I think I am miss understanding your comment but an `.opf` file or a `.ncx` file can be titled anything as long as they are present.  A `.ncx` file, per ePub 2.0 complacency requires it to be present to be validated.  To be a valid ePub 3.0 or 2.0 `.opf` with a correct `mimetype`; `doctype`, `<metadata>`, `<manifest>` and `<spine>` must be present within the `.opf` file and the `.ncx` was replaced with the `toc.xhtml` but the `.ncx` is optional.  
  
  ---
  
  ### Answer by username_1 on 2013-12-20. Score: 7
  
  The files and directory structure of the EPUB files is specified in the OCF (OpenContainerFormat). There are two versions are most interesting: [2.0.1](http://idpf.org/epub/20/spec/OCF_2.0.1_draft.doc) and [3.0.1](http://www.idpf.org/epub/301/spec/epub-ocf.html). Both specify only **one** required file in a specific subdirectory, and that is:
  
  ```
  META-INF/container.xml
  
  ```
  
  There are some optional files that can go in that directory as well (`signatures.xml`, `encrytpion.xml`, `metadata.xml`, `rights.xml`) and a file named `manifest.xml` is allowed there as well.
  
  The `container.xml` refers to the full path of one or more files, which names are essentially free and the directory structure as well.
  
  Of course some programs generate EPUB files always with the same structure. That is why it might seem that you need a `content.opf` in the root of the EPUB (zip) file structure, but that is only a valid name in any particular EPUB if and only if it is named in a `<rootfile>` element in the `container.xml`.
  
  The contents file (with references to the individual) HTML files which together form the e-book could be:
  
  ```
  TOC/TableOfContents.opf
  
  ```
  
  and the HTML files could be
  
  ```
  LOTR/The_Fellowship_of_the_Ring.htm
  LOTR/The_Two_Towers.htm
  LOTR/The_Return_of_the_King.htm
  
  ```
  
  as long as the paths of files, specified internally starting from `container.xml` are correct.
  
  As Mark pointed out a `mimetype` file needs to be present. Actually according to the [2.0.1](http://idpf.org/epub/20/spec/OCF_2.0.1_draft.doc) spec (page 7, bottom) that file has to be the first file in the EPUB file's ZIP structure.
  
  The only names in the root directory reserved by the [2.0.1](http://idpf.org/epub/20/spec/OCF_2.0.1_draft.doc) are `mimetype` and `META-INF`. The use of a specific folder (`LOTR` in the example) is recommended (to prevent collisions when there are multiple renditions), but not required.
  
  > **Comments:**
  > **username_2**: The OCF also requires the file mimetype in the root as far as I can see  
  
  ---
  
  ### Answer by username_3 on 2018-07-09. Score: -1
  
  An EPUB file is just a zip file. Copy mybook.epub to mybook.zip, and use your favorite zip tool to open the zip file. You should see some XHTML files and images somewhere in there, along with an OPF file, manifest, and some other control files. Windows 7+ natively treats zip files as a folder.
  
  XHTML is similar to HTML but is more strict, and the bold and italic tags are different.
  
  Below is a screen shot of a test2.epub I copied to test2.zip. The screenshot only shows the root dir of the epub.
  [![enter image description here](https://i.sstatic.net/O4RQi.jpg)](https://i.sstatic.net/O4RQi.jpg)
  
  
  ---
  
  