On my WordPress blog in default mode I have a <canvas> where I draw a chart with ChartJS. I've just downloaded the AMP plugin, run the Google AMP Test tool, and it says:

Fix the following issue
Prohibited or invalid use of HTML Tag
The tag 'canvas' is disallowed.

How do you go about fixing this? Is there any way to do JavaScript with AMP?

1 Answer 1


You can't run your own JavaScript when using AMP, that defeats the purpose of AMP. Instead, you can iframe your external content using the amp-iframe element.

  1. Add the amp-iframe JS to the head.

    <script async custom-element="amp-iframe"
  2. Add the amp-iframe element where you want your iframe to go.

    <amp-iframe width="200" height="100"
      sandbox="allow-scripts allow-same-origin" layout="responsive"

A full guide to using amp-iframe is available at:

  • AMP sounds awful. Commented Jun 23, 2017 at 19:07
  • Unfortunately, my blog does not support https, which Google requires for AMP, but fortunately my chart is inserted via a custom [graph] tag, and it has fallback functionality for <noscript> and sharing tools, so I've tweaked the code to always output the static JPG (drawn using an ancient PHP library) when rendering to AMP, so now we cleanly pass the Google check.
    – Ken Y-N
    Commented Jun 25, 2017 at 23:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.