SUBMIT A FILE TYPE CONTACT US SUPPORT ABOUT US

What Is an MHTML File? A Web Page in One Email Style File, and How It Breaks

An MHTML file is a web page saved in one file, so keep a second copy of any page that matters. Jump to your question below, or work through it in order.

49 min read Updated October 2026 Checked against sources and tests

What Is an MHTML File? A web page and its files in one message, saved as .mhtml or .mht

Short answer

An MHTML file is a web page saved in one file. It is a MIME message of the type multipart/related, built like an email, and it packs the HTML, the images and the style sheets of one page as parts. Its name ends in .mhtml or .mht, and the two endings mean the same.

We read 53 public MHTML files and 22 pages that we saved ourselves. Then we damaged 4 pages in 19 ways to make 132 copies. Chromium 141 showed a blank page for 27 copies, and our 62 line script gave no flag on 25.

To see the parts, go to the parts list. To check an MHTML file, follow the six steps. To fix a file that will not open, read the causes.

A good MHTML file opens in Chrome or Edge as the saved page with its images. Damaged ones can show nothing at all, so keep a second copy of pages that matter.

RFC 2557 from March 1999 describes how to put an HTML page and the files it uses into one email message. It is a Proposed Standard, and the RFC index lists no later RFC that replaces it. The RFC says nothing about file endings or file signatures, so .mht and .mhtml are habits that programs follow.

PRONOM, the format registry of the UK National Archives, lists both endings in one record named MHTML. It says the format was once named Microsoft Web Archive. FileInfo says .mhtml is the more common ending of the two.

Two endings, one format

Chromium treats both endings alike. One line in its source maps multipart/related to mht and mhtml. We renamed our sample to .mht and to .eml, and Chromium 141 opened all three files as the same page, with 5 of 5 images.

Under the ending .html it showed 29,204 characters of header text and no image. Under .txt, or with no ending, it showed the source as text.

So the ending decides which program opens the MHTML file, and the content decides what you see. A file that opens as text or as a jumble can be a good MHTML file under the wrong name, and the causes part shows how to find out.

Where our MHTML files come from

We worked with three sets of MHTML files. The first is 22 test pages that we made, served from a local test site and saved with Chromium 141 through its DevTools command Page.captureSnapshot.

The second is 53 public MHTML files from the test folders of Chromium, WebKit and Apache Tika. They add up to 116,760 bytes. The third is 132 damaged copies of four of our pages.

The public MHTML files come from older tools too, so they show what other programs write. Our 22 pages show what Chromium writes today and what it leaves out.

We read every file with our own scripts, with the file command 5.45 and with Python 3.13. We opened them in Chromium 141 through Playwright, with the network blocked.

We did not test desktop Chrome, Edge, Word, Outlook, Firefox, Safari or the two viewers that this page names. What we say about those programs comes from their makers’ pages and from the sources we link, and we say so every time.

MHTML file facts at a glance

Quick facts about MHTML files
Property Value
Meaning One web page and the files it uses, packed into one MIME message.
Standard RFC 2557 from March 1999. It builds on the MIME standards RFC 2045, 2046, 2387 and 2392.
Endings .mhtml and .mht, which mean the same. PRONOM lists both.
Media type multipart/related. Other pages print other names, and we could not confirm them.
Start Text. An MHTML file from Chromium starts with From: <Saved by Blink>. Other tools start with other lines.
Line ends CRLF. Chromium 141 showed a blank page on all 4 of our copies with LF line ends.
Opens with Chrome and Edge, which use Chromium. We could not confirm native support in Firefox or Safari.
Made by Chromium browsers, old Internet Explorer, Word, the UnMHT extension and other extensions.
Our tests 22 pages we saved, 53 public MHTML files, 132 damaged copies, 62 line check script, 16 line parts script and 24 line extract script.

Wrong page? Look at the EML page for email messages, the MBOX page for mailboxes or the PDF page for documents.

What Is Inside an MHTML File? Main headers, a boundary line and one part for every file the page uses

An MHTML file starts with a few lines of headers. A part for the page follows, and then one for every file the page uses. A line that begins with two hyphens and a long random text starts every part, and the same line with two more hyphens ends the MHTML file.

The figure cuts our 31,267 byte sample into its main headers, its eight parts and its closing line.

The sample is the article page, with two photos, two thumbnails, a mark, a style sheet and a frame. Six notes on the parts follow the figure.

The first 16 lines of the MHTML file follow in the code box.

A strip of one 31,267 byte MHTML file cut into its main headers, eight parts and closing boundary, colored by type, with six notes on the headers, boundary lines, part headers, the page part, image parts and the closing line.
Figure 1. One MHTML file, part by part, colored by type.
The first 16 lines of our MHTML file, shown by head
$ head -n 16 sample.mhtml
From: <Saved by Blink>
Snapshot-Content-Location: http://127.0.0.1:8123/22-article.html
Subject: Article with photos
Date: Tue, 27 Oct 2026 16:18:02 +0530
MIME-Version: 1.0
Content-Type: multipart/related;
	type="text/html";
	boundary="----MultipartBoundary--yKlgBPid1VOkCHuJss8r7ZMSHgsNcEJgalA5tufCny----"


------MultipartBoundary--yKlgBPid1VOkCHuJss8r7ZMSHgsNcEJgalA5tufCny----
Content-Type: text/html
Content-ID: <frame-9873EB7953108F2E1F88170D91441ECD@mhtml.blink>
Content-Transfer-Encoding: quoted-printable
Content-Location: http://127.0.0.1:8123/22-article.html

The main headers

Chromium writes six lines first. From names the program, and ours says Saved by Blink, after the engine in Chromium. Snapshot-Content-Location gives the address of the saved page. Subject is the page title, MIME-Version is 1.0 and Content-Type names multipart/related, the type of the first part and the boundary. Chromium’s source lists the same order.

These lines have the shape of email headers, and that is no accident. The long Content-Type line wraps onto two more lines that start with a tab. RFC 5322 calls this folding. A reader joins the lines again before it reads the value.

The boundary line

Every part starts with a boundary line, which is two hyphens and the boundary text. Our text has 69 characters, and RFC 2046 allows 70. It says the text must not appear inside a part. Chromium builds it from the word MultipartBoundary and 42 random characters.

The MHTML file ends with the boundary and two more hyphens. RFC 2046 says text before the first boundary and text after the closing line are ignored. Our script follows that rule, and a copy with 100 junk lines after the closing line showed the same page as the original.

Part headers and the address of every part

Every part has its own headers. Chromium writes Content-Type, Content-ID, Content-Transfer-Encoding and Content-Location. The location is the address that the page uses to ask for the MHTML file. When the browser meets that address in the HTML, it looks for a part with the same address and shows its bytes, and it starts no download.

Content-ID is a second way to name a part. A page can write cid: and the ID, a form that RFC 2392 defines. In our sample only the two HTML parts, the page and its frame, have an ID. The other six parts have an address and no ID.

The two encodings

Text parts are quoted printable. An equals sign is written as =3D, and a line that ends in = was wrapped at 76 characters.

Images are base64, which writes every 3 bytes as 4 characters, so an image grows by about a third. Our sample has 4 parts of every kind. RFC 2045 lists the encodings and the 76 character limit.

Chromium’s parser decodes base64, quoted printable, 8bit, 7bit and binary. It treats an unknown encoding or a missing one as binary. That is why a damaged encoding line breaks a picture, and the damaged part shows the case.

Relative addresses and the base

RFC 2557 lets an address be absolute or relative. It gives an order for finding the base address. The base is first a base tag in the part. Next comes an absolute location in the part’s own headers, then the headers above it and last the address the MHTML file was fetched from. Chromium writes absolute addresses.

A note in Chromium’s source says relative addresses are not resolved and that Internet Explorer and Firefox appear to write only absolute ones. The public file named relative_url shows the case. Chromium 141 showed both of its images. Our extract script resolves addresses against the address of the part they appear in.

List the parts of an MHTML file

Our 16 line parts script reads an MHTML file with the email package of Python and prints one line for every part. It shows type, size after decoding, encoding and address. The sample has 8 parts and 21,934 bytes after decoding. The check part lists the script.

The parts script on our sample
$ python3 mhtml_parts.py sample.mhtml
main type: multipart/related, subject: Article with photos
 1 text/html            1865 bytes  quoted-printable  http://127.0.0.1:8123/22-article.html
 2 image/svg+xml         170 bytes  quoted-printable  http://127.0.0.1:8123/img/mark.svg
 3 image/png            2240 bytes  base64            http://127.0.0.1:8123/img/thumb5.png
 4 image/png            2570 bytes  base64            http://127.0.0.1:8123/img/thumb2.png
 5 image/jpeg           6615 bytes  base64            http://127.0.0.1:8123/img/photo2.jpg
 6 image/jpeg           7549 bytes  base64            http://127.0.0.1:8123/img/photo1.jpg
 7 text/css              350 bytes  quoted-printable  http://127.0.0.1:8123/css/base.css
 8 text/html             575 bytes  quoted-printable  http://127.0.0.1:8123/19-link-only.html
8 parts, 21934 bytes after decoding

We read this layout from Chromium 141 output and from 53 public MHTML files. We did not read files that Word or Outlook write, so those can look different. RFC 2557 describes the format, and the writers differ in the details.

Which Browsers Open and Save MHTML Files? Chrome and Edge do, and here is what Chromium keeps and leaves out

Chrome and Edge open MHTML files, and both use Chromium. We could not confirm native support in Firefox or Safari. Chromium leaves out script and web fonts when it saves a page, and it reopens the form fields as disabled.

The table sums up what we found, program by program. We tested Chromium 141 only. For every other program the table says what its maker or another source says.

Programs and what they do with MHTML files
Program What we found
Chrome Opens the MHTML file, because Chromium maps .mht and .mhtml to multipart/related. Chromium’s design page says saving as MHTML is disabled by default in the Save Page As box on Windows, macOS and Linux. We tested Chromium 141 and not desktop Chrome.
Edge Opens the MHTML file, because Edge uses Chromium. Microsoft’s WebView2 page lists a save kind that saves a page as MHTML. Eric Lawrence’s post says Edge saves a single file from its Save As box. We did not test Edge.
Firefox No native support that we could confirm. Mozilla’s bug for reading MHTML files is assigned and open, with patches in progress, and the bug for saving them is open. Wikipedia says the extensions for MHTML stopped working at Firefox 57.
Safari No MHTML in Apple’s list. The Safari guide names Web Archive and Page Source as the Save As formats. Wikipedia says Safari 3.1.1 and later ended its MHTML support.
Internet Explorer 11 Support ended on 15 June 2022, says Microsoft. Edge has an Internet Explorer mode, and a policy can send local MHTML files to it.
Word and Excel Both can save a web archive. Microsoft’s Word page lists wdFormatWebArchive as 9, and the Excel page lists xlWebArchive as 45 with the endings .mht and .mhtml. We did not test either program.

Save a page as MHTML

Chromium’s design page lists MHTML as one of three formats for Save Page As. The others are complete HTML and HTML only.

It says MHTML is disabled by default on Windows, macOS and Linux, and that the switch --save-page-as-mhtml enables it for testing.

We found no Google page that names a Chrome version where this changed, so we name none.

Two other routes work in Chromium. An extension can call chrome.pageCapture.saveAsMHTML, which needs the pageCapture permission. A script can send the DevTools command Page.captureSnapshot with the format mhtml, and that is how we saved our 22 pages.

What Chromium keeps and what it leaves out

We saved 20 test pages and reopened every file. Then we compared a full page screenshot of the MHTML file with one of the live page.

15 matched pixel for pixel, 2 differed by 2 or 3 pixels at the corner of a frame and 3 looked different. The figure lists nine things and the fate of every one.

A bar of 20 test pages split by how they looked after Chromium saved and reopened them, and nine rows that say what Chromium kept, rewrote or left out: images, style sheets, script, links, picture sets, frames, web fonts, form fields and video posters.
Figure 2. What Chromium kept, rewrote or left out in 20 saved test pages.

The images came through byte for byte. All 36 image parts matched the original MHTML files. All 25 style sheets differed from the originals in their bytes, and the pages looked the same. The three pages that looked different show the gaps that matter.

A web font is gone The font file is not saved. The icon glyph on our test page was missing after we reopened the MHTML file, although the font had loaded in the live page.
Form fields are disabled Our field showed Ada, and typing did nothing, because the field matched the :disabled rule. Eric Lawrence’s post says Chromium disables form controls in the same way.
A video poster is missing The poster image is not a part of the MHTML file. The video box reopened without it.
Script is gone and its result stays The MHTML file has no script tag. It keeps the text that the script wrote into the page, and that text is there when you read it.

Script in an MHTML file

Eric Lawrence says Chromium leaves script and noscript blocks out of a saved MHTML file, and that a reloaded MHTML file executes no script. We saw the first in our own files.

We also opened three public MHTML files that contain script, and Chromium blocked the script in all three. Its console said the frame is sandboxed and the permission to execute script is missing.

Claims on other pages that we could not confirm

Firefox opens it with an extension The extensions stopped working with Firefox 57, says Wikipedia. The open Mozilla bugs above show that native support is not there yet.
Safari opens it Apple’s Save As list has Web Archive and Page Source and no MHTML.
Internet Explorer is the default opener Microsoft ended support for Internet Explorer 11 on 15 June 2022.
Switch on a flag in the Chrome flags page Two tech blogs from 2019 say Chrome removed that flag. Chromium’s own page now names a command line switch.

FileInfo also lists Firefox with the Mozilla Archive Format as an opener. Its page for .mhtml is dated July 2023, and the extension is older than Firefox 57, so we left it out of the table.

What Do 53 Public MHTML Files Contain? Five named tools, 6 MHTML files without CRLF and 10 that Chromium could not show

We read 53 public MHTML files from the test folders of Chromium, WebKit and Apache Tika. Five named tools and two other groups made them, 6 have no CRLF line ends and Chromium 141 showed nothing for 10. Our script flagged all 10, and it flagged 13 of the 43 that opened.

These are test MHTML files that engineers wrote to check browsers, so some are bad on purpose. They add up to 116,760 bytes, and the largest has 18,105 bytes. They are not a sample of the web. Read them as a picture of what tools write and of what a browser does with it.

Chromium turned 43 of the 53 into a page or an image. For the other 10 it showed nothing at all. The email package of Python read all 53 MHTML files without an error, and it noted a defect on 6 of them. The table lists the tools that wrote the files.

53 public files
116,760 bytes in all
10 showed nothing
13 flagged, but opened
The writers behind the 53 public MHTML files
Writer What we found
UnMHT 21 MHTML files. 4 showed nothing, our script flagged 8 and 2 have LF line ends. Wikipedia lists UnMHT with the extensions that stopped working at Firefox 57.
Internet Explorer 9 MHTML files. 1 showed nothing, 4 were flagged and 1 has LF line ends. One file is a single HTML part with no multipart header.
WebKit 7 MHTML files. 1 showed nothing and 4 were flagged. None has LF line ends.
Blink 6 MHTML files. 2 showed nothing, 4 were flagged and 1 has LF line ends.
No From line 6 MHTML files. 1 is empty and showed nothing, and 2 of the 6 were flagged.
Another start 3 MHTML files that start in another way. All 3 opened, and none was flagged.
Mozilla Archive Format 1 MHTML file of 13,759 bytes. It has LF line ends, and Chromium showed nothing.

What the public MHTML files show

44 of the 53 files name a writer in a From line. 6 have no From line and 3 start another way. A check that looks for the From line would miss 9 MHTML files, and the format part names the rule that PRONOM uses instead.

Six files have no CRLF line ends. Five use LF and one is empty. Chromium showed nothing for all six. We changed the LF in the five files to CRLF with the sed command. Four of them then showed a page or text, and the fifth stayed blank, because its closing line is missing.

The file command said news or mail for 45 of the 53 MHTML files and data for 2. It said empty for 1 and printed MIME text for 5. It named no MHTML type for any file, so it cannot separate a good MHTML file from a bad one.

Why our script flagged 13 MHTML files that Chromium opened

Reasons for the 13 flags on public files that Chromium opened
Reason What we found
A bad quoted printable escape 5 MHTML files. A part has an equals sign that does not start a valid escape. The pages opened, but the part is not valid quoted printable.
The closing line shares a line with the last tag 2 MHTML files. The closing boundary is on the same line as the last HTML tag, so the MHTML file has no closing line of its own.
A part with no address 2 MHTML files from Internet Explorer. A part has no Content-Location and no Content-ID, so nothing can ask for it.
One part and no boundary 1 MHTML file from Internet Explorer. The MHTML file is one HTML part with no multipart header.
The first part is not HTML 3 MHTML files. The header says text/html, and the first part is an image or XML.

The other 30 MHTML files that opened got no flag. We tuned two script rules on these files, the rule for LF line ends and the rule for the first part. So a match on the public MHTML files is not an independent test, and the damaged copies below are the fairer one.

The 132 damaged copies

We took four of our own pages. The mixed page has 8 parts and 24,555 bytes, and the shop page has 11 parts and 59,527 bytes.

The article page has 8 parts and 31,267 bytes, and the gallery has 10 parts and 30,943 bytes. We damaged every page in 19 ways and made 33 copies of every page.

A kind that picks a random part got more copies, so the kinds have 4, 8, 12 or 16 copies. We fixed the random choice by page, kind and copy number, so anyone can make the same copies.

Four test pages saved as MHTML with their size and number of parts, and a bar for every page that splits 33 damaged copies by what Chromium showed and whether our script flagged it.
Figure 3. Four test pages and what 33 damaged copies of every page showed.

Every bar splits the 33 copies of one page into four groups. Green is a copy that looked broken or changed in Chromium and got a flag. Blue looked the same and got a flag.

Red looked broken or changed and got no flag. Gray looked the same and got no flag. The last two columns count flags and blank pages.

Chromium showed nothing for 27 copies Those copies gave a blank page, and our script flagged all 27.
The script flagged 107 of 132 copies 95 of the 107 looked broken or changed in Chromium, and 12 looked the same.
Python read many broken copies The email package read the same parts as in the intact MHTML file on 48 copies. Chromium showed 40 of those 48 as broken or changed.
The file command saw no difference It said news or mail on all 132 copies, and it added the words with CRLF line terminators on 128.

What the numbers do not show about MHTML files

We damaged four pages that we made. Files from the wild have more parts, more frames and other encodings.

We tested Chromium 141 and no other program, so programs with stricter readers can refuse copies that Chromium shows.

The copies show how an MHTML file can fail, and they do not show how common faults are in the wild.

What Happens When an MHTML File Is Damaged? 132 copies, and 25 that got no flag from our script

We damaged 4 pages in 19 ways and opened all 132 copies in Chromium 141. Our script flagged 107 copies and gave no flag on 25. 18 of the 25 looked broken or changed, and 7 looked the same as the original.

We changed one thing in an MHTML file at a time and sorted the 19 kinds into five groups. They cover the main headers, the boundaries and line ends, the parts and their labels, the two encodings and cuts or extra lines at the end.

We read every copy in Chromium 141 with the network blocked. We also read it with our 62 line script, with Python and with the file command.

A flag is any line that the script printed about a fault. Blank means Chromium showed nothing. Changed means the screenshot of the copy differs from the original in pictures, style or text. A name like k12.mhtml in a code box is a copy of kind 12 in the figure.

A grid of 19 kinds of damage in five groups, with a bar for every kind that splits the damaged copies into four outcomes, plus counts of copies with a flag and copies that showed a blank page.
Figure 4. 132 damaged copies in 19 kinds, and what Chromium and our script showed.

Green means the copy looked broken or changed and our script flagged it. Blue means it looked the same and was flagged. Red means it looked broken or changed and the script said nothing. Gray means it looked the same and got no flag. The last two columns count flags and blank pages.

Silent damage in an MHTML file

25 copies got no flag. 18 of them looked broken or changed in Chromium, and 7 looked the same.

The 18 are 8 copies with the encoding line removed from an image part and 6 with one changed character in a JPEG.

The rest are 2 with a style sheet removed, 1 with an image removed and 1 with a soft line break removed.

Our script and the parts script on a copy with the encoding line removed from one image
$ python3 mhtml_check.py k12.mhtml
no problem found
$ python3 mhtml_parts.py k12.mhtml
main type: multipart/related, subject: Article with photos
 1 text/html            1865 bytes  quoted-printable  http://127.0.0.1:8123/22-article.html
 2 image/svg+xml         170 bytes  quoted-printable  http://127.0.0.1:8123/img/mark.svg
 3 image/png            3028 bytes  -                 http://127.0.0.1:8123/img/thumb5.png
 4 image/png            2570 bytes  base64            http://127.0.0.1:8123/img/thumb2.png
 5 image/jpeg           6615 bytes  base64            http://127.0.0.1:8123/img/photo2.jpg
 6 image/jpeg           7549 bytes  base64            http://127.0.0.1:8123/img/photo1.jpg
 7 text/css              350 bytes  quoted-printable  http://127.0.0.1:8123/css/base.css
 8 text/html             575 bytes  quoted-printable  http://127.0.0.1:8123/19-link-only.html
8 parts, 22722 bytes after decoding

The script says no problem found. The parts script shows part 3 with no encoding and 3,028 bytes, where the original has 2,240 bytes in base64. Chromium reads a part with no encoding as raw bytes, so the picture breaks. Our script checks an image only when the part says base64.

Our script, the parts script and a byte comparison on a copy with one changed character
$ python3 mhtml_check.py k16.mhtml
no problem found
$ python3 mhtml_parts.py k16.mhtml
main type: multipart/related, subject: Article with photos
 1 text/html            1865 bytes  quoted-printable  http://127.0.0.1:8123/22-article.html
 2 image/svg+xml         170 bytes  quoted-printable  http://127.0.0.1:8123/img/mark.svg
 3 image/png            2240 bytes  base64            http://127.0.0.1:8123/img/thumb5.png
 4 image/png            2570 bytes  base64            http://127.0.0.1:8123/img/thumb2.png
 5 image/jpeg           6615 bytes  base64            http://127.0.0.1:8123/img/photo2.jpg
 6 image/jpeg           7549 bytes  base64            http://127.0.0.1:8123/img/photo1.jpg
 7 text/css              350 bytes  quoted-printable  http://127.0.0.1:8123/css/base.css
 8 text/html             575 bytes  quoted-printable  http://127.0.0.1:8123/19-link-only.html
8 parts, 21934 bytes after decoding
$ cmp -l sample.mhtml k16.mhtml | wc -l
1
$ sha256sum sample.mhtml k16.mhtml
fd9073e8c029c0806878714536222a6d6cc67da7b44c860f46a7541ce9eb260d  sample.mhtml
51fdf7fd691d5f3ca24997cc3483091dda88ee76bc8ae447c3caa18b8c5c8148  k16.mhtml

The script says no problem found, and the parts script lists the same eight parts and sizes as for the original. The cmp command finds one byte that differs, and the hashes differ.

In the 16 copies of this kind, the script flagged the 10 where the changed character was in a PNG, because a PNG has checksums that it reads. It flagged none of the 6 where the character was in a JPEG. Chromium showed all 16 pages as changed.

The 7 copies that looked the same are 4 with junk lines after the closing line and 3 with a soft line break removed. Both changes leave the parts as they were.

Main header damage in an MHTML file

A missing MIME-Version line changed nothing that Chromium showed. A main type of multipart/mixed changed nothing either. Our script flagged all 8 copies, so they count as false alarms in our grid. Both changes break the standard, and a program that reads more strictly than Chromium can refuse them.

A changed boundary in the main header and no main Content-Type gave a blank page on all 8 copies.

The script on a copy with no MIME-Version line, then the script and the parts script on a copy with a changed boundary
$ python3 mhtml_check.py k01.mhtml
no MIME-Version header

$ python3 mhtml_check.py k03.mhtml
the boundary never appears in the body
$ python3 mhtml_parts.py k03.mhtml
main type: multipart/related, subject: Article with photos
 1 multipart/related    30504 bytes  -                 -
1 parts, 30504 bytes after decoding
the parser noted: StartBoundaryNotFoundDefect, MultipartInvariantViolationDefect

The parts script shows why. The boundary in the header no longer matches the MHTML file, so Python sees one big part and notes two defects. Chromium showed an empty page.

Boundaries and line ends in an MHTML file

A removed closing line, a changed boundary line and LF line ends were flagged on all 16 copies. Chromium showed a blank page on 4 of 4 copies without a closing line and on 4 of 4 with LF line ends.

With one changed boundary line it showed a blank page on 3 of 8 copies and a changed page on the other 5. A removed blank line after the headers of one part was flagged on 8 of 8, and Chromium showed a changed page and no blank one.

The script on a copy with no closing line, then the script, the parts script and the file command on a copy with LF line ends
$ python3 mhtml_check.py k05.mhtml
no final boundary line

$ python3 mhtml_check.py k08.mhtml
the line endings are LF and not CRLF
$ python3 mhtml_parts.py k08.mhtml
main type: multipart/related, subject: Article with photos
 1 text/html            1865 bytes  quoted-printable  http://127.0.0.1:8123/22-article.html
 2 image/svg+xml         170 bytes  quoted-printable  http://127.0.0.1:8123/img/mark.svg
 3 image/png            2240 bytes  base64            http://127.0.0.1:8123/img/thumb5.png
 4 image/png            2570 bytes  base64            http://127.0.0.1:8123/img/thumb2.png
 5 image/jpeg           6615 bytes  base64            http://127.0.0.1:8123/img/photo2.jpg
 6 image/jpeg           7549 bytes  base64            http://127.0.0.1:8123/img/photo1.jpg
 7 text/css              350 bytes  quoted-printable  http://127.0.0.1:8123/css/base.css
 8 text/html             575 bytes  quoted-printable  http://127.0.0.1:8123/19-link-only.html
8 parts, 21934 bytes after decoding
$ file k08.mhtml
k08.mhtml: news or mail, ASCII text

The LF copy shows the gap between tools. Python lists all 8 parts, and Chromium shows an empty page. The file command still says news or mail, and the words with CRLF line terminators are gone. That is the only hint in its output.

The fix is one command. The sed command adds a carriage return to every line, and the result has the same SHA256 hash as the original sample.

Repair of the LF copy, with the check and the hashes
$ sed 's/$/\r/' k08.mhtml > fixed.mhtml
$ python3 mhtml_check.py fixed.mhtml
no problem found
$ sha256sum sample.mhtml fixed.mhtml
fd9073e8c029c0806878714536222a6d6cc67da7b44c860f46a7541ce9eb260d  sample.mhtml
fd9073e8c029c0806878714536222a6d6cc67da7b44c860f46a7541ce9eb260d  fixed.mhtml

Parts and their labels in an MHTML file

A removed Content-Location on an image part was flagged on 16 of 16 copies, and one changed character in a Content-Location on 12 of 12. In both cases the page asks for an address that no part has. Chromium showed the page without that image and gave no error.

The script and the parts script on a copy with the address removed from one image
$ python3 mhtml_check.py k09.mhtml
part 6 has no Content-Location or Content-ID
the page points to http://127.0.0.1:8123/img/photo1.jpg and no part has it
$ python3 mhtml_parts.py k09.mhtml
main type: multipart/related, subject: Article with photos
 1 text/html            1865 bytes  quoted-printable  http://127.0.0.1:8123/22-article.html
 2 image/svg+xml         170 bytes  quoted-printable  http://127.0.0.1:8123/img/mark.svg
 3 image/png            2240 bytes  base64            http://127.0.0.1:8123/img/thumb5.png
 4 image/png            2570 bytes  base64            http://127.0.0.1:8123/img/thumb2.png
 5 image/jpeg           6615 bytes  base64            http://127.0.0.1:8123/img/photo2.jpg
 6 image/jpeg           7549 bytes  base64            -
 7 text/css              350 bytes  quoted-printable  http://127.0.0.1:8123/css/base.css
 8 text/html             575 bytes  quoted-printable  http://127.0.0.1:8123/19-link-only.html
8 parts, 21934 bytes after decoding

A removed image part was flagged on 11 of 12 copies.

The silent copy lost an image that only a style sheet used, and our script reads the src attributes and link tags of the page and not the style sheets.

A removed style sheet was flagged on 2 of 4 copies. The 2 silent copies lost a style sheet that another style sheet imports.

The two encodings in an MHTML file

A broken escape in a quoted printable part was flagged on 8 of 8 copies, and Chromium showed the same page on 4 of them. Those 4 count as false alarms in our grid, although the part is not valid.

A removed soft line break was flagged on none of 4 copies. Chromium showed a changed page on 1 of them and the same page on 3.

Cuts and extra lines in an MHTML file

Cuts at 50 percent and at 10 percent gave a blank page on 8 of 8 copies, and our script flagged all 8.

100 junk lines after the closing line showed the same page on 4 of 4 copies, and the script flagged none. That is right, because RFC 2046 says text after the closing line is ignored.

What our checks catch in an MHTML file

The script flagged 107 of the 132 copies. 95 of the flags were on copies that looked broken or changed. 12 were on copies that looked the same, 4 with a bad quoted printable escape and 8 with a main header that breaks the standard and that Chromium accepts.

The email package of Python read the same parts as the intact MHTML file on 48 copies. Chromium showed 40 of those 48 as broken or changed, 4 of them as blank.

Python raised no error on any of the 132 copies, and it noted a defect on 16. A reader that parses is not a reader that shows the page.

What the groups show

Results by group of damaged MHTML files
Group What we found
A. Main headers (1 to 4) 16 copies, and the script flagged all 16. 8 looked the same, and 8 gave a blank page.
B. Boundaries and layout (5 to 8) 24 copies, and the script flagged all 24. 11 gave a blank page, and the rest looked changed.
C. Parts and their labels (9 to 13) 52 copies. The script flagged 41. The 11 silent copies lost an encoding line, an image or a style sheet.
D. Encoding (14 to 16) 28 copies. The script flagged 18. The 10 silent copies are 6 with a changed JPEG character and 4 with a soft line break removed.
E. Cut or extended (17 to 19) 12 copies. The script flagged the 8 cut copies, and all 8 gave a blank page. It flagged none of the 4 copies with junk lines, and they looked the same.

Read the grid with care. A flag means our script named a fault, not that a program would refuse the copy. We damaged files that were in good shape, and our rules come from the same pages and the public MHTML files. We tested Chromium 141 and no other program.

What Does Our Expert Say About MHTML Files? A note from Neeraj Singh on keeping a second copy

Keep a second copy of any page you need, because one MHTML file breaks easily and is hard to check. In our test one change of line endings gave a blank page, and 25 of 132 damaged copies got no flag from our script.

Neeraj Singh

Expert insight

An MHTML file is an email in disguise, and Chromium reads it with little patience. In our test one change of line endings gave a blank page on 4 of 4 copies, and 25 of 132 damaged copies got no flag from our script. Save a PDF beside any page that matters, and write down the hash of both files.

Neeraj Singh Manager, Tech Support & Operations 19+ years fixing Windows and system errors

Why an MHTML file needs a second copy

People treat an MHTML file as a screenshot that cannot break. It is text with many parts, and every part must match its label and its boundary. Chromium shows a blank page when a line ending or a boundary is off. It shows a page with a missing picture when a label is off.

Saving also drops things. Our test showed that Chromium leaves out script, web fonts and video posters, and that it disables the form fields. If the saved page matters, save a PDF or a folder of files beside it, and write down the SHA256 hash of both.

Keep two formats. Save a PDF with the page, hash both files and open the MHTML file once before you close the live page. A blank page shows at once that the MHTML file is bad.

How Do You Open an MHTML File? Use Chrome or Edge, a text editor, a script or a viewer

Open an MHTML file with Chrome or Edge. A text editor shows its source, and a script can write its parts to a folder. Firefox and Safari have no support that we could confirm, and the two viewers below are vendor claims that we did not test.

We opened MHTML files with Chromium 141, with our own scripts and with Python on Linux. We did not test desktop Chrome, Edge, Word, Outlook or the two viewers. The steps below come from our tests and from the sources that we link.

Open an MHTML file in Chrome or Edge

Chromium maps .mht and .mhtml to the type multipart/related, so a Chromium browser opens the MHTML file as a page. We opened our MHTML files with a file address in Chromium 141, and our test pages came up with their images. We did not test the menus of desktop Chrome or Edge.

  1. Copy the MHTML file and work on the copy.
  2. Check the ending. It must be .mhtml or .mht. A file that ends in .html shows header text and no images.
  3. Open the MHTML file with Chrome or Edge, for example from the Open with list of your file manager.
  4. Look at the page. The images and style should be there. The form fields are disabled, and no script executes.
  5. If the page is blank, go to the cause list.

Open an MHTML file as an email

The Library of Congress says an EML file is formatted much like an MHT file and can open in some browsers after the ending changes to .mht. FileInfo’s entry says the same in the other direction.

In Chromium 141 our sample opened as the same page under .mhtml, .mht and .eml. We did not open it in a mail program.

Read an MHTML file as text

Any text editor shows the source, because the MHTML file is text. Open it, look and save nothing. An editor that changes the line endings can break the MHTML file, and our test shows that LF line ends alone give a blank page. In a terminal, head -n 16 shows the main headers, and grep finds the addresses.

The address, the title and the first part address in our sample
$ grep -a -m 3 -E "^(Snapshot-Content-Location|Subject|Content-Location)" sample.mhtml
Snapshot-Content-Location: http://127.0.0.1:8123/22-article.html
Subject: Article with photos
Content-Location: http://127.0.0.1:8123/22-article.html

Read an MHTML file with Python

The email package of Python reads MHTML files, because they are MIME messages. Call email.message_from_binary_file with policy=email.policy.default. Python’s documentation says to always give the policy. Our three scripts work on Python 3.13, which is the version we tested.

Our 24 line extract script writes every part to a folder and points the page at those files. It names the page index.html and the other parts part01, part02 and so on. The convert part lists it and the results of our tests.

Open an MHTML file with a viewer

Two vendors list viewers for MHT files on Windows. We tested neither, and both pages are vendor claims.

SysTools MHT Viewer

Open MHT and MHTML files on Windows

Freeware, says the page

Freeviewer MHT Viewer

View MHT and MHTML files on Windows

Free version previews only

The SysTools page names the tool MHT Viewer Freeware and says it supports Windows 11 and 10. It says the tool opens MHT and MHTML files saved by Chrome, Internet Explorer and Firefox. It lists a search, a date filter and loading entire folders. The page shows no version, no size and no price.

The Freeviewer page lists version 1.0 and a download of 10.5 MB. It names Windows 10, 8 and 7 and Windows Server 2016, 2012 R2 and 2008, and it needs .NET Framework 4.5 or later. It says the free version previews and that a paid version exists, with no price shown.

It also says the viewer cannot save or convert. The page names a size limit of 100 MB in one place and no limit in another, so read it before you rely on either.

How our tools did on the MHTML files

Every tool gets its own row below. The numbers cover our 22 pages, 53 public MHTML files and 132 damaged copies, and the tools that read files on Linux are the ones we used.

How every tool did on our MHTML files
Tool What we saw
Chromium 141 Opened 43 of the 53 public MHTML files and showed nothing for 10. Showed a blank page for 27 of the 132 damaged copies.
Our 62 line check script Flagged all 10 public MHTML files that showed nothing and 13 of the 43 that opened. Flagged 107 of the 132 copies, and 25 got no flag.
Python email package Read all 53 public MHTML files and all 132 copies without an error. Read the same parts as the intact MHTML file on 48 copies, and Chromium showed 40 of those 48 as broken or changed.
file 5.45 Said news or mail on all 132 copies and on 45 of the 53 public MHTML files.
Edge, Word, Outlook, Firefox and Safari Not tested. The browsers part lists what their makers say.
The two viewers Not tested. The vendor pages list free viewing.

How Do You Check an MHTML File? Six steps and two short scripts

Check an MHTML file in six steps. Hash it, read its first lines, check the line endings, list its parts, use our 62 line script and open it in Chromium. No check proves that every part is right, and our script gave no flag on 25 of the 132 damaged copies.

The six steps to check an MHTML file

  1. Copy the MHTML file, write down its SHA256 hash and work on the copy.
  2. Read the first lines with head -n 16 page.mhtml. They should show From, Snapshot-Content-Location, Subject, Date, MIME-Version and a Content-Type that names multipart/related and a boundary.
  3. Check the line endings with file page.mhtml. An MHTML file from Chromium says with CRLF line terminators. When those words are missing, the MHTML file has LF line ends, and Chromium shows a blank page.
  4. List the parts with the parts script below. Every part after the first needs an address, and the part count and sizes should look right.
  5. Use the check script below. It names the faults that it finds and changes nothing.
  6. Open the MHTML file in Chromium and look at the page. Count the images, and compare with the live page when you still have it.
The hash, the file command, the size and the check script on our sample
$ sha256sum sample.mhtml
fd9073e8c029c0806878714536222a6d6cc67da7b44c860f46a7541ce9eb260d  sample.mhtml
$ file sample.mhtml
sample.mhtml: news or mail, ASCII text, with CRLF line terminators
$ wc -c < sample.mhtml
31267

$ python3 mhtml_check.py sample.mhtml
no problem found

The file command says news or mail for a good MHTML file, because it has no rule for MHTML. The words with CRLF line terminators are the useful part. The hash shows which file you have, and it must match the source before you go on.

The parts script for MHTML files

This 16 line Python script does step 4. It reads the MHTML file with the email package and prints one line for every part. The line shows type, size after decoding, encoding and address. At the end it prints the totals and any defect that the parser noted.

mhtml_parts.py
#!/usr/bin/env python3
"""mhtml_parts.py lists the parts of an MHTML file with the Python email package. It changes no file and starts nothing.
Use: python3 mhtml_parts.py page.mhtml"""
import sys, email
from email import policy

msg = email.message_from_binary_file(open(sys.argv[1], 'rb'), policy=policy.default)
print('main type: %s, subject: %s' % (msg.get_content_type(), msg['Subject']))
parts = [p for p in msg.walk() if not p.is_multipart()]
total = 0
for n, p in enumerate(parts, 1):
    size = len(p.get_payload(decode=True) or b'')
    total += size
    print('%2d %-16s %8d bytes  %-17s %s' % (n, p.get_content_type(), size, p['Content-Transfer-Encoding'] or '-', (p['Content-Location'] or p['Content-ID'] or '-')[:60]))
print('%d parts, %d bytes after decoding' % (len(parts), total))
if msg.defects: print('the parser noted: %s' % ', '.join(type(d).__name__ for d in msg.defects))

On our sample it prints 8 parts and 21,934 bytes after decoding, as the inside part shows. The script changes no file and starts nothing.

The 62 line script that checks MHTML files

This Python script does step 5. It reads the main headers, the boundary, the header of every part, encodings and addresses in the page. It names every fault that it finds, and it changes no file. It follows RFC 2046 and ignores text after the closing line.

It checks the main type, line endings and boundary. For every part it checks the blank line after the headers, the type, the address, base64 and quoted printable text.

For PNG, JPEG and GIF parts it checks the first bytes, and for PNG parts it checks the checksums. It also checks that the address in every src attribute and link tag of the page has a part.

mhtml_check.py
#!/usr/bin/env python3
"""mhtml_check.py lists the faults of an MHTML file that it can see. It changes no file and starts nothing.
Use: python3 mhtml_check.py page.mhtml"""
import re, sys, base64, binascii, zlib

def check(data):
    msgs = []
    m = re.search(rb'\r?\n\r?\n', data)
    head, body = (data[:m.start()], data[m.end():]) if m else (data, b'')
    flat = re.sub(rb'\r?\n[ \t]+', b' ', head)
    if not re.search(rb'(?im)^MIME-Version:', flat): msgs.append('no MIME-Version header')
    if not re.search(rb'(?im)^Content-Type:\s*multipart/related', flat): msgs.append('the main type is not multipart/related')
    if b'\r\n' not in data[:400]: msgs.append('the line endings are LF and not CRLF')
    b = re.search(rb'boundary="?([^";\r\n]+)', flat)
    if not b: return msgs + ['no boundary in the main headers']
    bnd = re.escape(b.group(1))
    if not re.search(rb'(?m)^--' + bnd, body): return msgs + ['the boundary never appears in the body']
    end = re.search(rb'(?m)^--' + bnd + rb'--[ \t]*\r?$', body)
    if end: body = body[:end.end()]
    else: msgs.append('no final boundary line')
    parts = [c for c in re.split(rb'(?m)^--' + bnd + rb'(?:--)?[ \t]*\r?\n?', body)[1:] if c.strip()]
    if not parts: return msgs + ['no parts']
    urls = set(); html = b''
    for i, c in enumerate(parts):
        h, sep, body = c.lstrip(b'\r\n').partition(b'\r\n\r\n')
        if not sep: h, sep, body = c.lstrip(b'\r\n').partition(b'\n\n')
        if not sep: msgs.append('part %d has no blank line after its headers' % (i + 1)); continue
        h = re.sub(rb'\r?\n[ \t]+', b' ', h)
        def hv(n):
            m = re.search(rb'(?im)^' + n + rb':\s*([^\r\n]*)', h); return m.group(1).strip().decode('latin-1') if m else ''
        ctype, cte, loc, cid = hv(b'Content-Type').split(';')[0].lower(), hv(b'Content-Transfer-Encoding').lower(), hv(b'Content-Location'), hv(b'Content-ID')
        if not ctype: msgs.append('part %d has no Content-Type' % (i + 1))
        if i == 0 and ctype and re.search(rb'(?i);\s*type="?text/html', flat) and ctype != 'text/html': msgs.append('the first part is %s and not text/html' % ctype)
        if i and not (loc or cid): msgs.append('part %d has no Content-Location or Content-ID' % (i + 1))
        urls.update(x for x in (loc, cid.strip('<>') and 'cid:' + cid.strip('<>')) if x)
        if cte == 'base64':
            try: raw = base64.b64decode(re.sub(rb'\s+', b'', body), validate=True)
            except (binascii.Error, ValueError): msgs.append('part %d has bad base64' % (i + 1)); continue
        elif cte == 'quoted-printable':
            if re.search(rb'=(?![0-9A-F]{2}|\r?\n|$)', body): msgs.append('part %d has a bad quoted-printable escape' % (i + 1))
            raw = body
        else: raw = body
        if ctype == 'image/png' and cte == 'base64' and not raw.startswith(b'\x89PNG'): msgs.append('part %d is not a PNG' % (i + 1))
        if ctype == 'image/jpeg' and cte == 'base64' and not raw.startswith(b'\xff\xd8'): msgs.append('part %d is not a JPEG' % (i + 1))
        if ctype == 'image/gif' and cte == 'base64' and not raw[:3] == b'GIF': msgs.append('part %d is not a GIF' % (i + 1))
        if ctype == 'image/png' and raw.startswith(b'\x89PNG'):
            p = 8
            while p + 12 <= len(raw):
                n = int.from_bytes(raw[p:p + 4], 'big')
                if zlib.crc32(raw[p + 4:p + 8 + n]) != int.from_bytes(raw[p + 8 + n:p + 12 + n], 'big'): msgs.append('part %d has a bad PNG checksum' % (i + 1)); break
                p += 12 + n
        if i == 0 and ctype == 'text/html' and cte in ('', '7bit', '8bit', 'binary'): html = raw
        elif i == 0 and ctype == 'text/html' and cte == 'quoted-printable':
            import quopri; html = quopri.decodestring(body)
    for u in sorted(set(re.findall(rb'(?:src|<link[^>]* href)="((?:https?:|cid:)[^"]+)"', html))):
        if u.decode('latin-1') not in urls and not u.endswith(b'/'): msgs.append('the page points to %s and no part has it' % u.decode('latin-1')[:60])
    return msgs

if __name__ == '__main__':
    out = check(open(sys.argv[1], 'rb').read())
    print('\n'.join(out) if out else 'no problem found')
    if len(out) > 20: print('... and %d more' % (len(out) - 20))

On our 22 saved pages it printed no problem found for 21. It flagged the srcset page, because the page names a fallback image that Chromium did not save. That page looks right, so the flag is a false alarm. The damaged part shows what the script says about damaged copies.

What the checks cannot see

25 copies passed our script. 18 of them looked broken or changed in Chromium. The script reads only the src attributes and link tags of the page.

So it cannot see an image that only a style sheet uses, or a style sheet that another style sheet imports. It checks a picture only when the part says base64, and it reads no checksum in a JPEG.

A flag is not a verdict either. The script flagged 12 copies that Chromium showed the same as the original, and we tuned two of its rules on the public MHTML files.

Write down the facts of your original MHTML file, which are its size, its SHA256 hash and its part count. A copy that differs in any of them is a different file.

The script never checks that words, numbers or pictures are right. It shows whether the parts agree with their labels, and nothing more.

Want the causes of a blank page? Go to the causes.

Is an MHTML File Safe to Open and Share? Chromium blocks script, and the old Windows handler had flaws

Chromium 141 blocked the script in the public MHTML files that we opened, and Chromium leaves script out when it saves a page. The old Windows MHTML handler had flaws in 2011, and Internet Explorer 11 is out of support. Open files only from sources you trust, and treat every MHTML file as private data.

We scanned no file for malware, and our public MHTML files are test MHTML files. Our network block recorded no request on any copy or any public MHTML file. FileInfo’s page for .mht warns that criminals can use the ending to spread malware.

The 2011 flaws and the 2019 report

Microsoft’s bulletin MS11-026 from 12 April 2011 describes a flaw in how the MHTML handler in Windows processes MIME requests for blocks of content inside a document.

It says an attacker could execute script in the wrong security context, and it has the number CVE-2011-0096. The flaw is in the mhtml: handler that Internet Explorer used, and it is not about opening a saved MHTML file in Chrome.

A 2019 blog post of the security firm 0patch and a Tenable scanner page describe another flaw, in Internet Explorer 11, that a crafted .mht file could trigger.

They say it could send local files to an attacker, and that Microsoft had shipped no fix at the time. We read both pages and did not test the flaw. Support for Internet Explorer 11 ended on 15 June 2022.

What is inside an MHTML file

The text of the page Everything the page showed when you saved it, including text that a script wrote. A page that you saved while signed in can contain your name or account details.
The address of the page The Snapshot-Content-Location line gives it, in the first lines. An address can include names or tokens in its parameters.
The date and the title The Date line gives the time of the save, and the Subject line gives the page title.
Images and styles Every image part matched the original MHTML file byte for byte in our test. A private photo stays private only while you keep the MHTML file to yourself.
The address, the title and the first part address in our sample
$ grep -a -m 3 -E "^(Snapshot-Content-Location|Subject|Content-Location)" sample.mhtml
Snapshot-Content-Location: http://127.0.0.1:8123/22-article.html
Subject: Article with photos
Content-Location: http://127.0.0.1:8123/22-article.html

Before you share an MHTML file

  1. Open the MHTML file in a browser and look at the page as a stranger would. Look for names, account details, messages and addresses.
  2. Read the first lines of the MHTML file for its address and title. If the address includes private data, save the page again from an address without parameters.
  3. Send a PDF if the other side only needs to read the page. We printed our article page to PDF from Chromium, and the PDF kept text as text, plus the images.
  4. Send the MHTML file over a channel you trust, and send its SHA256 hash by another route.
  5. Delete your extra copies when the other side confirms the MHTML file.

Look before you send. A saved page is a snapshot of what was on your screen. Read it before you share it, and remove the names and notes that the other side does not need.

Why Will Your MHTML File Not Open? Eight causes, and what to do about every one

MHTML files fail to open for eight reasons. The ending or line endings can be wrong, and the boundary or closing line can be wrong or gone. The main headers can be damaged, and a part can be missing. A tool can write a file that Chromium reads poorly, or Edge can open it in another mode.

The table lists what we saw in our 132 damaged copies and our 53 public MHTML files. We opened files in Chromium 141 only, so read every fix as a first step and not as a final answer.

Eight causes of MHTML files that will not open
Cause Details and fix
The ending is wrong Under .html our sample showed 29,204 characters of header text and no image, and under .txt it showed the source. Under .mht and .eml it opened as the page. Fix: Rename a copy to .mhtml.
The line endings are LF Chromium 141 showed a blank page on 4 of 4 copies with LF line ends and on 5 of 5 public MHTML files with LF. The file command lost the words with CRLF line terminators. Fix: Add a carriage return to every line, for example with the sed command in the damage results, and compare the hash with the source.
The boundary does not match A changed boundary in the main header gave a blank page on 4 of 4 copies. A changed boundary line gave a blank page on 3 of 8 copies and a changed page on the other 5. Fix: Compare the boundary in the main header with the boundary lines in the MHTML file.
The closing line is gone A missing closing line gave a blank page on 4 of 4 copies, and cuts at 50 and 10 percent gave one on 8 of 8. Our script said no final boundary line. Fix: Copy or download the MHTML file again from its source.
The main headers are damaged No main Content-Type gave a blank page on 4 of 4 copies. A missing MIME-Version line changed nothing that Chromium showed, and neither did a main type of multipart/mixed. Fix: Compare the first lines with a good MHTML file from the same tool.
A part is missing A removed address, image part or style sheet gave a page without that part and no error. Our script named all of them except an image that only a style sheet uses. Fix: List the parts and look for a part with no address or a part that is missing.
The tool wrote a bad file Chromium showed nothing for 10 of the 53 public MHTML files. They are 5 with LF line ends, an empty file and an MHTML file whose first part is JavaScript. The other three have a boundary that is not in the body, no parts or no closing line. A Microsoft Q&A answer says Chromium’s support for files from other tools is limited. Fix: Try Python or the extract script, and save the page again with Chromium.
Edge opens it in another mode Edge has an Internet Explorer mode. Microsoft’s page names a policy that lets local MHTML files open in that mode. We did not test it. Fix: Ask your administrator which mode opens the MHTML file, and test the MHTML file in Chrome.

When the script is the problem and not the MHTML file

Our script gave no flag on 25 damaged copies, and it flagged 12 copies that looked the same as the original.

A report with no flag does not prove that an MHTML file is good, and a flag does not prove that it is bad.

Test with a second tool before you call an MHTML file good or bad.

Fix an MHTML file in seven steps

  1. Copy the MHTML file, write down its SHA256 hash and work on the copy.
  2. Check the ending, and rename a copy to .mhtml when it ends in .html or .txt.
  3. Check the line endings with the file command. When the words with CRLF line terminators are missing, add a carriage return to every line.
  4. Read the first lines and compare the boundary in the main header with boundary lines in the MHTML file.
  5. List the parts with the parts script, and use the check script. Note every fault that it names.
  6. Read the MHTML file with a second tool, for example Python or the extract script. Python read the same parts as the intact MHTML file on 48 copies where Chromium showed 40 as broken or changed.
  7. If the MHTML file is cut or parts are missing, get it again from its source. We tested no repair of files from other people, so none is promised here.

A file that passes our scripts can still fail in another program. A file that our script flags can still open in Chromium. Only the program that you use shows what it accepts.

What to send when you ask for help

If a forum or a support team asks about your MHTML file, send these lines. They show what the MHTML file is and where the tools stopped, and they save rounds of questions. Remove names and private data first.

A message that gets an answer
Subject: MHTML file will not open
File: name, size in bytes and SHA256 hash
Made by: the program and its version, if you know them
First lines: the output of head -n 16 page.mhtml
Line ends: the output of the file command
Parts: the output of mhtml_parts.py
Check: the output of mhtml_check.py
Browser: its name and version, and what you see
History: where the file came from and what changed

Not an error, but a question about similar files? Go to the versus part.

How Do You Save, Extract or Convert an MHTML File? Save with a script, extract the parts or print to PDF

You can save a page as MHTML with a script, write the parts of an MHTML file to a folder and print a reopened file to PDF. Renaming converts nothing. We tested the save, the extract and the print in Chromium 141, and we tested no converter.

This part reports what we tested. A converter reads the MHTML file and writes new files, and it leaves the original unchanged.

Save a page as MHTML with a script

This short Playwright script is how we saved our 22 pages. It opens a page, waits for the network to settle and sends the DevTools command Page.captureSnapshot with the format mhtml. On our article page it wrote 31,267 bytes, the size of our sample file.

save.js, the script that saved our pages
const { chromium } = require('playwright');
const fs = require('fs');

(async () => {
  const browser = await chromium.launch();
  const page = await browser.newPage();
  await page.goto('http://127.0.0.1:8123/22-article.html', { waitUntil: 'networkidle' });
  const cdp = await page.context().newCDPSession(page);
  const { data } = await cdp.send('Page.captureSnapshot', { format: 'mhtml' });
  fs.writeFileSync('article.mhtml', data);
  await browser.close();
})();

Extract the parts of an MHTML file to a folder

Our 24 line extract script writes every part to a folder and rewrites the addresses in the text parts to the new file names. It resolves a relative address against the address of its own part, and it names the page index.html. Open that file in a browser, and the page needs no MHTML reader.

mhtml_extract.py
#!/usr/bin/env python3
"""mhtml_extract.py writes every part of an MHTML file into a folder and points the page at those files.
Use: python3 mhtml_extract.py page.mhtml folder"""
import email, email.policy, mimetypes, os, re, sys
from urllib.parse import urljoin

msg = email.message_from_binary_file(open(sys.argv[1], 'rb'), policy=email.policy.default)
out = sys.argv[2]
os.makedirs(out, exist_ok=True)
parts = [p for p in msg.walk() if not p.is_multipart()]
files, names = [], {}
for i, p in enumerate(parts):
    ext = mimetypes.guess_extension(p.get_content_type()) or '.bin'
    files.append('index.html' if i == 0 else 'part%02d%s' % (i, ext))
    for ref in (p.get('Content-Location'), p.get('Content-ID') and 'cid:' + p['Content-ID'].strip('<>')):
        if ref: names[ref] = files[i]
for p, name in zip(parts, files):
    data = p.get_payload(decode=True) or b''
    if p.get_content_maintype() == 'text':
        cs, here = p.get_content_charset() or 'latin-1', p.get('Content-Location') or ''
        text = re.sub(r'[\w./:%~+@-]+', lambda m: names.get(urljoin(here, m.group()), m.group()), data.decode(cs, 'replace'))
        data = text.encode(cs, 'replace')
    open(os.path.join(out, name), 'wb').write(data)
print('wrote %d files to %s' % (len(parts), out))
The extract script on our sample
$ mkdir -p site
$ python3 mhtml_extract.py sample.mhtml site
wrote 8 files to site
$ wc -c site/*
 1670 site/index.html
  170 site/part01.svg
 2240 site/part02.png
 2570 site/part03.png
 6615 site/part04.jpg
 7549 site/part05.jpg
  350 site/part06.css
  551 site/part07.html
21715 total

We used the script on our 22 pages. We opened every original MHTML file and every extracted index.html in Chromium 141 with the network blocked, and we compared full page screenshots. 21 pairs matched pixel for pixel.

The form page differed, because Chromium disables the fields of an MHTML file and the extracted page has working fields. We tested files from Chromium only, and files from other tools can use other encodings.

Print an MHTML file to PDF

We opened our article page in Chromium 141 and printed it to PDF on A4 paper with a script. The PDF has 2 pages. Its text stays text, and the four raster images are in it.

The two JPEG images have the same sizes as their parts, 7,549 and 6,615 bytes. A PDF fixes the page as it looked, and it loses the HTML, so keep the MHTML file too.

What you cannot convert by renaming an MHTML file

Renaming changes only the name. We renamed our sample to .eml, and its SHA256 hash stayed the same. The file command still said news or mail. Chromium 141 opened the .eml copy as the same page, and we did not open it in a mail program.

Our sample before and after the rename
$ sha256sum sample.mhtml sample-renamed.eml
fd9073e8c029c0806878714536222a6d6cc67da7b44c860f46a7541ce9eb260d  sample.mhtml
fd9073e8c029c0806878714536222a6d6cc67da7b44c860f46a7541ce9eb260d  sample-renamed.eml
$ file sample-renamed.eml
sample-renamed.eml: news or mail, ASCII text, with CRLF line terminators
Conversions and how much we know
Task What we know
Save a page as MHTML Tested. A DevTools command in Chromium 141 saved our 22 pages.
MHTML to HTML and a folder Tested. Our extract script gave 21 identical pages out of 22.
MHTML to PDF Tested. Chromium 141 printed our article page to 2 A4 pages with text and images.
MHTML to EML by renaming Changes only the name. The hash did not change, and Chromium opened the copy as a page.
MHTML to Word Not tested. Microsoft lists a web archive save format for Word, and we did not use it.
MHTML to another format with a viewer Not tested. The Freeviewer page says its viewer cannot save or convert.

How Does an MHTML File Differ From HTML, EML, WEBARCHIVE, WARC and PDF Files? One page in one file, a message, two archives and a document

An MHTML file packs a page and its files in one email style file. An HTML file is only the page, and an EML file is an email message. A WEBARCHIVE file is the archive of Safari, and a WARC file is the archive of a crawler. A PDF file is a document.

People mix these types up because all of them can save a web page or a message. The table sorts them by what they pack and by who writes them.

MHTML files next to similar files
Type What it is
HTML One page as text. Images, styles and script are separate files that the page names by address. We renamed an MHTML file to .html and saw header text and no images.
MHT and MHTML One file with the page and the files it uses as MIME parts. Chromium opens it, and this page covers it.
EML An email message. The Library of Congress page says it is formatted much like an MHT file. Our guide to EML files covers it.
WEBARCHIVE The archive of Safari. Wikipedia says it is a binary property list, and that Safari does not support the other archive formats.
WARC A web archive that crawlers write. Library of Congress notes describes the format and gives it the type application/warc.
PDF A document with a fixed layout. Chromium printed our MHTML page to a PDF with text that stays text. Our guide to PDF files covers it.

An MHTML file and an EML file share their structure, and Chromium 141 opened our sample under both names. A WEBARCHIVE file does not share it, because Safari writes it as a binary file. A viewer for one format does not read the others in general, so check the first lines before you install a tool.

What Is the MHTML File Format Made Of? The facts we could check, and where they came from

An MHTML file is a MIME message that packs a page and its files. RFC 2557 and the MIME RFCs describe it, and they name no file ending and no signature. The facts below come from those RFCs, PRONOM, the source of Chromium and our checks of 22 pages, 53 public MHTML files and 132 copies.

Facts about the MHTML file format
Part What we checked
Name MHTML. PRONOM lists it as MHTML, formerly Microsoft Web Archive, with the endings .mht and .mhtml. (PRONOM)
Specification RFC 2557 from March 1999, a Proposed Standard that obsoletes RFC 2110. It builds on RFC 2045, 2046, 2387 and 2392. (RFC Editor)
Media type multipart/related, which RFC 2387 defines and PRONOM and Chromium name. Other pages print application/x-mimearchive and message/rfc822. The second is the type of an EML file, and we could not check the first in the IANA registry. (RFC 2387, PRONOM, Chromium)
Signature The RFCs define none. PRONOM matches the lines MIME-Version 1.0 and Content-Type multipart/related within the first 2,048 bytes. An MHTML file from Chromium starts with From: <Saved by Blink>, and only 6 of our 53 public MHTML files start that way. (PRONOM, our MHTML files)
Line ends CRLF, as in email. Chromium 141 showed a blank page for 4 of 4 copies with LF. (RFC 2046, our copies)
Main headers From, Snapshot-Content-Location, Subject, Date, MIME-Version and Content-Type, in that order, in files from Chromium. (Chromium source, our MHTML files)
Boundary From 1 to 70 characters. Ours has 69. A boundary line is two hyphens and the text, and the closing line has two more hyphens. (RFC 2046, our MHTML files)
Part headers Content-Type, Content-ID, Content-Transfer-Encoding and Content-Location in files from Chromium. A part is found by its Content-Location or its Content-ID. (RFC 2557, RFC 2392, Chromium source)
Encodings 7bit, 8bit, binary, quoted printable and base64, with a limit of 76 characters on an encoded line. In our MHTML files from Chromium, text parts are quoted printable and images are base64. (RFC 2045, our MHTML files)
Base address A base tag first, then an absolute Content-Location in the headers, then the address that the MHTML file came from. (RFC 2557)
Script Chromium leaves script and noscript out when it saves, and it blocks script when it opens an MHTML file. (Eric Lawrence, our tests)
Our counts 22 pages we saved, 53 public MHTML files, 132 damaged copies, 62 line check script, 16 line parts script and 24 line extract script.

About the values we list

Rules about messages come from the MHTML RFC, the MIME bodies RFC, the MIME types RFC, RFC 2387 and the cid URL RFC. The registry facts come from PRONOM. What Chromium writes comes from its source and from our MHTML files. Where sources disagree or say nothing, we say so.

What we left out

We damaged 4 pages, and every test changed one thing. A page with many frames, large images or other encodings can fail in other ways. We read files from Chromium and from the test folders of three projects, and we did not read a file that Word, Outlook or Safari wrote.

We did not test desktop Chrome, Edge, Firefox, Safari, Word, Outlook or the two viewers. We could not read the IANA entries for multipart/related and message/rfc822, so we make no claim about registration. We found no Chrome version where saving as MHTML became the default, so we name none.

The public MHTML files are small test MHTML files and not saved pages from live sites. We did not measure speed, and we did not test MHTML files with encodings that our pages do not use.

Sources checked

For the format, see the RFCs above and PRONOM’s record for MHTML. For the endings, see FileInfo’s page for .mhtml and Wikipedia’s page on MHTML.

For browsers, see Chromium’s design page for Save Page As, the Chromium parser source, Lawrence’s post and Apple’s Safari guide. For other types, see the Library of Congress page on WARC. Every count came from files and scripts in our research folder.

Frequently Asked Questions About MHTML Files

What is an MHTML file?

An MHTML file is a web page saved in one file. It is a MIME message of the type multipart/related, built like an email, and it packs the HTML, the images and the style sheets as parts. RFC 2557 describes it, and its name ends in .mhtml or .mht.

What is the difference between MHT and MHTML?

Nothing in the format. PRONOM lists both endings in one record, and FileInfo says .mhtml is the more common one. Chromium maps both to multipart/related, and our sample opened as the same page under .mht and .mhtml.

How do I open an MHTML file?

Open it with Chrome or Edge, which use Chromium. A text editor shows the source, and a script can write the parts to a folder. We tested Chromium 141 and our own scripts, and we did not test desktop Chrome, Edge, Word or Outlook.

Does Firefox open MHTML files?

We could not confirm native support. Mozilla has an open bug for reading MHTML files, assigned with patches in progress, and one for saving them. Wikipedia says the extensions for MHTML stopped working at Firefox 57.

Does Safari open MHTML files?

We found no support. Apple’s Safari guide lists Web Archive and Page Source as the Save As formats and names no MHTML. Wikipedia says Safari 3.1.1 and later ended its MHTML support.

Is an MHTML file safe to open?

Chromium 141 blocked the script in the public MHTML files that we opened, and Chromium leaves script out when it saves. The old Windows MHTML handler had flaws in 2011, and Internet Explorer 11 is out of support. Open files from sources you trust.

How do I save a web page as MHTML?

Chromium lists MHTML as a Save Page As format that is disabled by default on Windows, macOS and Linux, and a command line switch enables it. An extension can use pageCapture, and a script can send Page.captureSnapshot, which is how we saved our 22 pages.

How do I convert an MHTML file to HTML or PDF?

Write the parts to a folder with a script, or print the page from Chromium. Our 24 line script gave 21 identical pages out of 22, and a printed PDF kept text as text. Renaming converts nothing, because the SHA256 hash stays the same.

Why does my MHTML file show a blank page?

A blank page points to LF line endings, a boundary that does not match or a closing line that is gone. In our test Chromium 141 showed a blank page on 27 of 132 damaged copies, and on 4 of 4 copies with LF line ends. The file command shows the line endings.

What is the difference between MHTML and EML?

An EML file is an email message, and an MHTML file is a page packed in the same kind of message. The Library of Congress says an EML file is formatted much like MHT. Chromium 141 opened our sample under .mhtml, .mht and .eml.

Does an MHTML file have a signature?

The RFCs define none. PRONOM matches MIME-Version 1.0 and Content-Type multipart/related within the first 2,048 bytes. An MHTML file from Chromium starts with a From line that names Saved by Blink in angle brackets, and only 6 of our 53 public MHTML files start that way.

What does an MHTML file look like inside?

It is text. A few email style headers come first, then a part for the page and one for every file it uses. Every part starts with a boundary line, and a boundary line with two more hyphens ends the MHTML file. Images are base64 and text is quoted printable.

Still Stuck With an MHTML File? Two routes out, and where to look next

Your MHTML file shows a blank page

Check the ending and the line endings, and follow the seven steps. The cause table lists what to try in order.

You do not know what it contains

Look at how an MHTML file is built, and then start our check script.

Is it an email message? An EML file is an email message, and Chromium opened our MHTML sample under that name too. Our page on EML files covers it, and the versus part shows how the two differ.

Is it a mailbox? An MBOX file stores many messages in one file, and an EMLX file is the message format of Apple Mail. Our page on MBOX files and our page on EMLX files cover the two formats.

Do you need a document? A PDF keeps the page as it looked, and our test printed an MHTML page to PDF with text that stays text. Our page on PDF files covers the format.

Is the data unknown? Our page on DAT files covers files with no clear type, and the file extension resource library lists many more.

Is your type missing? Send it on the submit a file type page.