Use File → Download → Web Page (.html, zipped), or call the Drive API’s files.export on the document ID. Do not use the Apps Script snippet shown below — it never converts anything.
Table of Contents
Why Apps Script getText() does not give you HTML
This Apps Script snippet does not export HTML:
var doc = DocumentApp.openById(docId);
var content = doc.getBody().getText();
var blob = Utilities.newBlob(content, 'text/html', 'output.html');
DriveApp.createFile(blob);
getBody().getText() returns plain text. Google’s own reference for it says “Retrieves the contents of the element as a text string”. Labelling that string text/html and naming the file .html changes the file name and nothing else: every heading, list, link and image is already gone by the time the blob is created. Running it grants the script write access to your entire Drive and gives you back a stripped text file.
There is no fix inside DocumentApp, because it has no HTML-producing method. Document.getAs() names its complete supported set: “‘application/pdf’ and ‘text/markdown’ are supported”. To get HTML from Apps Script you have to go out to the Drive API, which Google documents as UrlFetchApp.fetch against the export endpoint with ScriptApp.getOAuthToken() — its sample exports PDF, and the MIME type is a parameter.
What the export formats actually are
Google’s export-formats table (the page carries “Last updated 2026-07-22”) lists one HTML row for Documents, and its MIME type is application/zip, not text/html:
Web Page (HTML) application/zip .zip
Markdown text/markdown .md
Plain Text text/plain .txt
PDF application/pdf .pdf
Microsoft Word application/vnd.openxmlformats-officedocument.wordprocessingml.document
A text/html row existed in that table as recently as November 2022 and is no longer there. Whether the API still accepts it is a separate question, and one this page cannot answer: an unauthenticated request to the endpoint is rejected before the MIME type is looked at.
curl -s -w "HTTP %{http_code}\n" \
"https://www.googleapis.com/drive/v3/files/<ID>/export?mimeType=application%2Fzip"
HTTP 403
{ "error": { "code": 403, "message": "The request is missing a valid API key." } }
Identical response for mimeType=text%2Fhtml. Use application/zip, which is what the current documentation supports. Also note the cap Google states twice: “the exported content is limited to 10 MB”. Above that you need files.download or a different route, and a long document with images will hit it.
If what you want is clean, structured output rather than HTML specifically, export Markdown. It is a documented export format, it is one of the two types getAs() supports, and it arrives without any of the cleanup below.
Cleaning the exported HTML
Google documents the format, the MIME type and the file extension of the HTML export. It documents nothing about the shape of the markup — no statement about class names, inline styles, the images folder, or how links are written. That is worth knowing before you build anything on top of it: an undocumented output format is an unversioned one, and it can change without an announcement.
The fragment below is constructed to exercise the patterns people report — generated class names, a <style> block, inline sizing, and links written through google.com/url?q=. It is not a real export and is not presented as one. The cleaner is real, is standard-library Python (html.parser), and drops class, style and id, deletes <style> blocks, unwraps <span> and <div> elements left with no attributes, and rewrites redirect-wrapped hrefs back to their target. Run on that fragment:
attributes removed: 17 elements unwrapped: 7 bytes: 805 -> 224
<p>Quarterly report</p>
<p>Revenue rose in Q3, driven by <a href="https://example.org/data">this dataset</a>.</p>
<ul><li>First point</li>
<li>Second point</li></ul>
<p><img alt="chart" src="images/image1.png" title=""></p>
One thing that output makes obvious and a description would hide: “Q3” was bold in the input, expressed as a CSS class, and stripping classes threw the emphasis away. Any cleaner that removes classes wholesale does this. If bold and italic matter, map the handful of weight and style classes to <strong> and <em> before you strip, or export Markdown and skip the problem.
What was and was not tested
Executed here: the two curl probes above, and the cleaner, on the constructed fragment, on macOS 26.6 (arm64) with CPython 3.9.6; the cleaned output was re-parsed with xmllint --html to confirm it is still well-formed. Not tested here, and not claimed: the File → Download menu path and its exact label, the contents of a real export zip, whether text/html still works as an export MIME type, and any behaviour of Apps Script — none of which can be run without a Google account. The menu label is also not in Google’s help documentation; the help article says only “click File Download… Choose a file type”, so treat the exact wording as what the product shows rather than as documentation. For a different Google Docs formatting task, see adding a background to a Google Doc.