Google Docs can export a document as an HTML page for use outside the editor. The manual download includes a ZIP archive; an Apps Script export can also create an HTML file in Drive.
Download HTML manually
- Open the Google document you are permitted to export.
- Select File > Download > Web page (.html, zipped).
- Extract the downloaded ZIP file.
- Open the HTML file in a browser and check its layout and images.
- Keep any accompanying assets in the expected relative locations when moving or publishing the page.
Exported HTML may need accessibility and layout adjustments before use on a website. Review the output rather than assuming it matches the site’s styles.
Export with Google Apps Script
For a repeatable export, create a project in Apps Script and use the following function. Replace the document ID with the value between /d/ and /edit in its Google Docs URL:
function exportDocToHtml() {
const documentId = 'REPLACE_WITH_DOCUMENT_ID';
const source = DriveApp.getFileById(documentId);
const url = 'https://www.googleapis.com/drive/v3/files/' +
encodeURIComponent(documentId) + '/export?mimeType=text%2Fhtml';
const response = UrlFetchApp.fetch(url, {
headers: { Authorization: 'Bearer ' + ScriptApp.getOAuthToken() },
muteHttpExceptions: true
});
if (response.getResponseCode() !== 200) {
throw new Error('Export failed with HTTP ' + response.getResponseCode());
}
DriveApp.createFile(response.getBlob().setName(source.getName() + '.html'));
}Save the project, select exportDocToHtml and run it. Review Google’s requested permissions and authorise only a project you trust. You need access to the source document and permission to create the output file. Your organisation may restrict this operation or require the Drive API to be enabled for the script’s project.
Find the new HTML file in Drive, download it and inspect the result. Each run creates another file. The Drive export API limits exported content to 10 MB; if it fails, check the permissions and export limits rather than assuming a file was created.
For a page whose images need to move with it, the manual ZIP export is usually easier to inspect and keep together. Exporting a document does not automatically publish it as a website.