What’s causing the Invalid HTML, CSS, or Javascript found in template error

It should not come as a big surprise to people reading this that this error is almost always due to a formatting problem. The part that trips people up is that this often occurs in Google Tag Manager when someone is copy/pasting code from one system to the next, so nothing is being edited and people wonder how the formatting could possibly be wrong. First, let’s make sure this is the right thread for you, then we’ll get the solution and root cause so you can:

  1. Fix your current problem
  2. Know when it will occur in the future so you can avoid it

This is the error we’re specifically focusing on:

Now if you’re a marketer and don’t know javascript or HTML, you’ll probably run into this error and freeze. A seasoned developer would probably spot the problem pretty quickly. Every time I have run into this it’s because we were copying code sent to us from a vendor in excel, where it was formatted properly, then pasting into Google Tag Manager. In that process, double quotations were added to the code. Look closely and you’ll see the extra quotations.

You can easily fix this by deleting the extra quotations so it matches the original code. Once you do, hit save, then publish, and voila! Your work here is done.

If you’re looking at your code and you can’t see the difference, there’s a really clever little tool that will make your life so much easier called DiffChecker. It’s 100% free. Just copy/paste your original code from excel into one side of diffchecker, then copy/paste your code that you just copied into Google Tag Manager and hit “Find Difference”. Even if your formatting error was not caused by an excel copy/paste this tool will still help you find any errors, so you can narrow down the root cause.

Contact Us