CHM (Microsoft Compiled HTML Help)
| Full name | Microsoft Compiled HTML Help |
|---|---|
| Extensions | .chm |
| MIME type | application/vnd.ms-htmlhelp |
| Type | archive of HTML pages, images and indexes, compressed with LZX |
| Starts with | 49 54 53 46 (ITSF), then version 03 00 00 00 |
| Specification | none published by Microsoft; reverse-engineered specification |
| Maintained by | Microsoft (HTML Help 1.4, no longer developed) |
| License | proprietary format; free open-source readers exist |
A CHM file packs a website (HTML pages, CSS, images, scripts) into one compressed file, together with a table of contents, a keyword index and a full-text search index. It was the help format of Windows programs from Windows 98 on, and is still used for software documentation and SDK references and for some e-books, especially Chinese ones.
On Windows, CHM files open in the built-in HTML Help viewer (hh.exe), which renders pages with the old Internet Explorer engine. Because CHM pages can run scripts, CHM files are a common way to deliver malware, and Windows blocks content of CHM files downloaded from the internet.
When to use CHM#
- Use only when you must ship offline help for older Windows software that calls the HTML Help API (
HtmlHelp()). - Avoid for new documentation: use a static HTML website, PDF or EPUB. CHM depends on an Internet Explorer engine and doesn’t work natively on macOS, Linux or mobile.
- Avoid sending CHM files by email or download: Windows blocks them by default and security tools flag them.
File structure#
A CHM file is a small file system: a header, a directory of named files and the file data, most of it in one LZX-compressed stream. All integers are little-endian.
49 54 53 46 "ITSF" signature
03 00 00 00 version 3
60 00 00 00 header length (0x60)
01 00 00 00 unknown, always 1
xx xx xx xx timestamp
09 04 00 00 language ID 0x0409 (English, US)
10 FD 01 7C AA 7B D0 11 GUID {7C01FD10-7BAA-11D0-9E0C-00A0C922E6EC}
9E 0C 00 A0 C9 22 E6 EC
11 FD 01 7C ... GUID {7C01FD11-7BAA-11D0-9E0C-00A0C922E6EC}
... offsets and lengths of the 2 header sections, offset of content
| Part | Contents |
|---|---|
ITSF header |
signature, version, language ID, then a table pointing to 2 header sections and to the content |
| Header section 0 | the total file size |
Header section 1 (ITSP) |
the directory: a B-tree of 4 KB chunks. PMGL chunks list files sorted by name; PMGI chunks index them |
| Content section 0 | uncompressed data: small internal files, and the compressed stream of section 1 |
Content section 1 (MSCompressed) |
most files, compressed together with LZX in blocks (usually 32 KB windows with periodic resets for random access) |
Each directory entry has a name (UTF-8), a content section number, an offset and a length, all stored as variable-length integers (7 bits per byte, high bit means “more bytes follow”). Offsets refer to the uncompressed content of the section. A reset table (::DataSpace/Storage/MSCompressed/Transform/.../ResetTable) lists where LZX resets happen, so a reader can decompress a file without decompressing everything before it.
Files inside a CHM#
| Name | Contents |
|---|---|
/index.html, /images/... |
the help pages and their resources, as authored |
*.hhc |
table of contents: an HTML page with nested <ul> lists of <object type="text/sitemap"> items |
*.hhk |
keyword index, same sitemap syntax |
/#SYSTEM |
settings: title, default page, .hhc and .hhk names, language, compiler version |
/#TOPICS, /#URLTBL, /#URLSTR, /#STRINGS |
tables of topics, URLs and strings used by the index and search |
/#WINDOWS |
window definitions (size, buttons, default pane) |
/#IDXHDR |
index header |
/$FIftiMain |
full-text search index |
::DataSpace/NameList, ::DataSpace/Storage/... |
names of the content sections, the LZX control data, reset table and compressed stream |
Names starting with / are user files; names starting with :: describe the container. Pages link to each other with relative URLs; from outside, Windows addresses them as mk:@MSITStore:C:\path\help.chm::/page.html or ms-its:help.chm::/page.html.
Working with CHM files#
- Unblock a downloaded CHM: if pages show “This page can’t be displayed”, right-click the file in Explorer, choose Properties and check Unblock, or run
Unblock-File help.chmin PowerShell. - Extract all files:
hh.exe -decompile outdir help.chmon Windows,7z x help.chmwith 7-Zip, orextract_chmLib help.chm outdirfrom CHMLib on Linux. - Convert to other formats: Calibre converts CHM to EPUB, MOBI or PDF (
ebook-convert help.chm help.epub). archmage converts CHM to HTML or PDF. - Create CHM: Microsoft HTML Help Workshop (
hhc.exe) compiles an.hhpproject file with HTML pages,.hhcand.hhk. Documentation generators such as Doxygen and Sphinx produce the project files; HelpNDoc is a commercial authoring tool.
Specifications and documentation#
- Unofficial (Preliminary) HTML Help Specification: the most complete description of the container, internal files and search index
- Microsoft’s HTML Help (.chm) format by Matthew T. Russotto: the original reverse-engineered description of the container
- libmspack CHM API documentation: CHM and LZX decompression
- Microsoft HTML Help 1.4 SDK: official documentation of authoring, the viewer and the HTML Help API (archived)
- IANA registration of application/vnd.ms-htmlhelp
- CHM on Wikipedia
Software that opens CHM files#
| Software | Windows | macOS | Linux | Web | Can | Notes |
|---|---|---|---|---|---|---|
| SumatraPDF | ✓ | view | free, open source; table of contents and search, without the IE security prompts | |||
| Microsoft HTML Help (hh.exe) | ✓ | view | built into Windows; Internet Explorer engine | |||
| xCHM | ✓ | ✓ | ✓ | view | free, open source, CHMLib-based | |
| uChmViewer | ✓ | ✓ | ✓ | view | free, open source; fork of KchmViewer, also opens EPUB | |
| KchmViewer | ✓ | ✓ | ✓ | view | free, open source, Qt | |
| iChm | ✓ | view | free, open source macOS viewer | |||
| Calibre | ✓ | ✓ | ✓ | view, convert | converts CHM to EPUB, MOBI, PDF | |
| 7-Zip | ✓ | ✓ | convert | extracts all files from a CHM | ||
| archmage | ✓ | ✓ | convert | CHM to HTML or PDF, command line, Python | ||
| HelpNDoc | ✓ | create | help authoring tool, free for personal use |
Libraries#
Open-source libraries that read CHM files. See all CHM libraries for a comparison.
| C/C++ | CHMLib, libmspack |
|---|---|
| Java | jchmlib |
| Python | pychm |
| Rust | libchm |
| PHP | chm-lib |