Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Tuesday, September 19, 2023

Creating HTML with Google Apps Script(createTemplateFromFile)

This is an example of code that creates a simple HTML page with Google Apps Script's HtmlService.createTemplateFromFile().

HtmlService.createTemplateFromFile() allows you to manage CSS and JavaScript files separately from index.html.

The output HTML page will be as follows.

The script editor will look like this:

We can create a .html file by clicking the Plus icon to the right of Files and selecting HTML.
function doGet() {
return HtmlService.createTemplateFromFile('index')

function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename).getContent();

<!DOCTYPE html>
<?!= include('css'); ?>
<?!= include('javascript'); ?>

textarea {
width: 80vw;
height: 80vh;
font-size: 15px;

function myFunction() {
console.log("This is a log message.");

Related pages

Latest post

Creating a template copier app in Google Apps Script

Introduction This article will show you a template copier application in Google Apps Script.  This application will automatically copy a t...