After Build and Run webgl html only shows text of html

Like the title says after clicking build and run the html document that gets created ends up showing just the text from the html file itself. I have a custom html document that I am using along with some custom css in an assets folder. The html file is named index and is in a folder called WebGLTemplates.

After the build finishes successfully the page is served with whatever server Unity builds. Using dev-tools I inspect the html docs to see the whole html document gets added into a pre tag so only the text from the tag is displayed.

Just a note the project is built successfully, and when just using build and hosting on my hosting service the project page looks as it should with the canvas element displaying as expected. I am unsure how I should approach even addressing this issue.

I just ran into this issue. For me, it was that my index.html file was not encoding as UTF-8. Somehow when editing it, the encoding changed to UTF-8 BOM. I opened the file in notepad ++, and then select “Encoding” → UTF-8 to change the encoding back and it worked for me. This one was a head scratcher.