HTML Service Stay organized with collections Save and categorize content based on your preferences.
Page Summary
The HTML service in Apps Script allows applications to return HTML, typically for user interfaces.
Key classes for working with HTML in Apps Script include HtmlOutput, HtmlService, and HtmlTemplate.
HtmlOutput objects represent HTML content that can be served from a script and offer methods for managing content, meta tags, and display properties.
HtmlService is the main service for creating and managing HtmlOutput and HtmlTemplate objects.
HtmlTemplate allows for dynamically constructing HTML content before evaluating it to an HtmlOutput object.
This service allows Apps Script applications to return HTML, usually as a user interface. If you're new to using this class, we recommend you also see theguide to Html Service
.Classes
| Name | Brief description |
|---|---|
Html | AnHtml object that can be served from a script. |
Html | An object that represents a meta tag added to the page by callingHtml. |
Html | Service for returning HTML and other text content from a script. |
Html | A template object for dynamically constructing HTML. |
Sandbox | An enum representing the sandbox modes that can be used for client-sideHtmlscripts. |
XFrameOptionsMode | An enum representing theX-Frame-Options modes that can be used for client-sideHtml scripts. |
HtmlOutput
Methods
| Method | Return type | Brief description |
|---|---|---|
add | Html | Adds a meta tag to the page. |
append(addedContent) | Html | Appends new content to the content of thisHtml. |
append | Html | Appends new content to the content of thisHtml, using contextual escaping. |
as | Html | Returns anHtml backed by thisHtml. |
clear() | Html | Clears the current content. |
get | Blob | Return the data inside this object as a blob converted to the specified content type. |
get | Blob | Return the data inside this object as a blob. |
get | String | Gets the content of thisHtml. |
get | String | Gets the URL for a favicon link tag added to the page by callingset. |
get | Integer | Gets the initial height of thecustom dialog in GoogleDocs, Sheets, or Forms. |
get | Html | Gets an array of objects that represent meta tags added to the page by callingadd. |
get | String | Gets the title of the output page. |
get | Integer | Gets the initial width of thecustom dialog in GoogleDocs, Sheets, or Forms. |
set | Html | Sets the content of thisHtml. |
set | Html | Adds a link tag for a favicon to the page. |
set | Html | Sets the initial height of thecustom dialog in GoogleDocs, Sheets, or Forms. |
set | Html | This method now has no effect — previously it set thesandboxmode used for client-side scripts. |
set | Html | Sets the title of the output page. |
set | Html | Sets the initial width of acustom dialog in GoogleDocs, Sheets, or Forms. |
set | Html | Sets the state of the page'sX-Frame-Options header, which controls clickjackingprevention. |
HtmlOutputMetaTag
Methods
| Method | Return type | Brief description |
|---|---|---|
get | String | Gets the content of this meta tag. |
get | String | Gets the name of thisHtml. |
HtmlService
Properties
| Property | Type | Description |
|---|---|---|
Sandbox | Sandbox | An enum representing the sandbox modes that can be used for client-sideHtmlscripts. |
XFrameOptionsMode | XFrameOptionsMode | An enum representing theX-Frame-Options modes that can be used for client-sideHtml scripts. |
Methods
| Method | Return type | Brief description |
|---|---|---|
create | Html | Creates a newHtml object that can be returned from the script. |
create | Html | Creates a newHtml object from aBlob resource. |
create | Html | Creates a newHtml object that can be returned from the script. |
create | Html | Creates a newHtml object from a file in the code editor. |
create | Html | Creates a newHtml object from aBlob resource. |
create | Html | Creates a newHtml object that can be returned from the script. |
create | Html | Creates a newHtml object from a file in the code editor. |
get | String | Gets the user-agent string for the current browser. |
HtmlTemplate
Methods
| Method | Return type | Brief description |
|---|---|---|
evaluate() | Html | Evaluates this template and returns anHtml object. |
get | String | Generates a string of JavaScript code, based on the template file, that can be evaluated. |
get | String | Generates a string of JavaScript code that can be evaluated, with each line of the codecontaining the original line from the template as a comment. |
get | String | Returns the unprocessed content of this template. |
SandboxMode
Properties
| Property | Type | Description |
|---|---|---|
EMULATED | Enum | A legacy sandbox mode that emulates ECMAScript 5 strict mode using only the features availablein ECMAScript 3. |
IFRAME | Enum | A sandbox mode that uses iframe sandboxing instead of the Caja sandbox technology used by theEMULATED andNATIVE modes. |
NATIVE | Enum | A sandbox mode that is built on top of ECMAScript 5 strict mode. |
XFrameOptionsMode
Properties
| Property | Type | Description |
|---|---|---|
ALLOWALL | Enum | NoX-Frame-Options header will be set. |
DEFAULT | Enum | Sets the default value for theX-Frame-Options header, which preserves normal securityassumptions. |
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.