I am developing a module and I have this HTML markup.

<canvas id="cnv" name="cnv" width="500" height="100"></canvas>

I want to add it in a form. Looking at the Form API reference documentation page, I don't see any canvas form element.

What should I instead use?

2 Answers 2


The form api does not support every tag in HTML. For special cases use a form key of #markup to embed raw HTML. Scan the form APIs for that keyword for examples.


This document page might help you.

Here is a sample code that I wrote to create a canvas in my form in Drupal 8.

      '#type' => 'html_tag',
      '#tag' => 'canvas',
      '#attributes' => array(
                    'style'=>'border: 1px solid #000000;
                              width: 200;
                              height: 100;'

Your Answer

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