HTML5 Code Injection

You can inject custom HTML into your game's index.html file through extensions. This is done by clicking on "HTML5" under "Platform Settings" in an extension's editor:

Insertion Tags

In the "Code Injection" window, you can add custom HTML for your index.html file. Such HTML is inserted into different parts of the index.html file by using the following tags:

TagDescription
GM_HTML5_PreHeadHTML is inserted after the <head> tag
GM_HTML5_PostHeadHTML is inserted after the </head> tag
GM_HTML5_PreStyleHTML is inserted inside <head> </head>, but before <style>
GM_HTML5_PostStyleHTML is inserted inside <head> </head>, but after </style>
GM_HTML5_PreBodyHTML is inserted before the <body> tag
GM_HTML5_PostBodyHTML is inserted after the </body> tag

Here is an example of HTML code injected into some of the above tags:

Multiple extensions may inject code into the same tag, however the order of their insertions into the final HTML file cannot be guaranteed.

Variables

Within your injected HTML5 code, you may use variables that GameMaker provides. You can see such variables in the example above, wrapped inside ${ }.

You can also read your custom extension options by using the ${YYEXTOPT_HTML5Injection_OPTIONNAME} syntax.

The following built-in variables can be used with the ${VARIABLE} syntax:

VariableDescription
GM_HTML5_BrowserTitleThe title of the browser window
GM_HTML5_BackgroundColourThe background colour of the page
GM_HTML5_GameWidthThe width of the game's canvas (in pixels)
GM_HTML5_GameHeightThe height of the game's canvas (in pixels)
GM_HTML5_GameFolderThe name of the folder containing the HTML file
GM_HTML5_GameFilenameThe name of the HTML file
GM_HTML5_CacheBustA random value used for cache-busting; can be added as a URL parameter in custom links to prevent the browser from getting the cached version of a file

Template HTML File

You can get the template index.html file from the runtime directory, under runtime-[version]/html5/index.html. Here you can view the template file to understand where the tags are inserted. You can make a modified copy and use it for your game instead of the default file, by adding it as an Included File and selecting it in the HTML5 Game Options.

The template HTML file will contain some tags starting with GM_HTML5_Inject*. These are used by GameMaker to inject values from the HTML5 Game Options, and as such can't be used for inserting custom code.