Canvas

  • Revision slug: HTML/Canvas
  • Revision title: Canvas
  • Revision id: 295873
  • Created:
  • Creator: ethertank
  • Is current revision? No
  • Comment

Revision Content

The {{ HTMLElement("canvas") }} element is an HTML element which can be used to draw graphics via scripting (usually JavaScript). For example, it can be used to draw graphs, make photo compositions, create animations or even do real-time video processing.

Mozilla applications gained support for <canvas> starting with Gecko 1.8 (i.e. Firefox 1.5). The element was originally introduced by Apple for the OS X Dashboard and Safari. Internet Explorer supports <canvas> from version 9 onwards; for earlier versions of IE, a page can effectively add support for <canvas> by including a script from Google's Explorer Canvas project. Google Chrome and Opera 9 also support <canvas>.

The <canvas> element is also used by WebGL to do hardware-accelerated 3D graphics on web pages.

Documentation

Specification
The <canvas> element is part of the WhatWG Web applications 1.0 specification, also known as HTML 5.
Drawing Graphics with Canvas
A one-page introduction to <canvas>.
Canvas tutorial
A comprehensive tutorial covering both the basic usage of <canvas> and its advanced features.
Code snippets:Canvas
Some extension developer-oriented code snippets involving <canvas>.
Canvas examples
A few <canvas> demos.
Drawing text using a canvas
Documentation for the textual <canvas> feature available from {{ Gecko("1.9") }}.
Drawing DOM objects into a canvas
How to draw DOM content, such as HTML elements, into a canvas.
A basic raycaster
A demo of ray-tracing animation using canvas.
Canvas DOM interfaces
Canvas DOM interfaces on Gecko.

View All...

Community

* View Mozilla forums... {{ DiscussionList("dev-tech-html", "mozilla.dev.tech.html") }}

Resources

Libraries

  • libCanvas is powerful and lightweight canvas framework
  • Processing.js is a port of the Processing visualization language
  • EaselJS is a library with a Flash-like API
  • PlotKit is a charting and graphing library
  • Rekapi is an animation keyframing API for Canvas
  • PhiloGL is a WebGL framework for data visualization, creative coding and game development.
  • JavaScript InfoVis Toolkit creates interactive 2D Canvas data visualizations for the Web.
HTML, JavaScript, CSS, AJAX, DOM, SVG, WebGL
{{ HTML5ArticleTOC() }}

Revision Source

<p>The {{ HTMLElement("canvas") }} element is an <a href="/en-US/docs/HTML" title="en-US/docs/HTML">HTML</a> element which can be used to draw graphics via scripting (usually <a href="/en-US/docs/JavaScript" title="en-US/docs/JavaScript">JavaScript</a>). For example, it can be used to draw graphs, make photo compositions, create animations or even do real-time video processing.</p>
<p>Mozilla applications gained support for <code>&lt;canvas&gt;</code> starting with Gecko 1.8 (i.e. <a href="/en-US/docs/Firefox_1.5_for_developers" title="en-US/docs/Firefox_1.5_for_developers">Firefox 1.5</a>). The element was originally introduced by Apple for the OS X <a class="external" href="http://www.apple.com/macosx/features/dashboard/">Dashboard</a> and Safari. Internet Explorer supports <code>&lt;canvas&gt;</code> from version 9 onwards; for earlier versions of IE, a page can effectively add support for <code>&lt;canvas&gt;</code> by including a script from Google's <a class="external" href="http://excanvas.sourceforge.net/">Explorer Canvas</a> project. Google Chrome and Opera 9 also support <code>&lt;canvas&gt;</code>.</p>
<p>The <code>&lt;canvas&gt;</code> element is also used by <a href="/en-US/docs/WebGL" title="en-US/docs/WebGL">WebGL</a> to do hardware-accelerated 3D graphics on web pages.</p>
<table class="topicpage-table">
  <tbody>
    <tr>
      <td>
        <h2 class="Documentation" id="Documentation" name="Documentation"><a href="/en-US/docs/tag/HTML:Canvas" title="/en-US/docs/tag/HTML:Canvas">Documentation</a></h2>
        <dl>
          <dt>
            <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#the-canvas-element" title="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#the-canvas-element">Specification</a></dt>
          <dd>
            <small>The <code>&lt;canvas&gt;</code> element is part of the WhatWG Web applications 1.0 specification, also known as HTML 5.</small></dd>
          <dt>
            <a href="/en-US/docs/Drawing_Graphics_with_Canvas" title="en-US/docs/Drawing_Graphics_with_Canvas">Drawing Graphics with Canvas</a></dt>
          <dd>
            <small>A one-page introduction to <code>&lt;canvas&gt;</code>.</small></dd>
          <dt>
            <a href="/en-US/docs/Canvas_tutorial" title="en-US/docs/Canvas_tutorial">Canvas tutorial</a></dt>
          <dd>
            <small>A comprehensive tutorial covering both the basic usage of <code>&lt;canvas&gt;</code> and its advanced features.</small></dd>
          <dt>
            <a href="/en-US/docs/Code_snippets/Canvas" title="en-US/docs/Code_snippets/Canvas">Code snippets:Canvas</a></dt>
          <dd>
            <small>Some extension developer-oriented code snippets involving <code>&lt;canvas&gt;</code>.</small></dd>
          <dt>
            <a href="/en-US/docs/tag/Canvas_examples" title="/en-US/docs/tag/Canvas_examples">Canvas examples</a></dt>
          <dd>
            <small>A few <code>&lt;canvas&gt;</code> demos.</small></dd>
          <dt>
            <a href="/en-US/docs/Drawing_text_using_a_canvas" title="en-US/docs/Drawing_text_using_a_canvas">Drawing text using a canvas</a></dt>
          <dd>
            <small>Documentation for the textual <code>&lt;canvas&gt;</code> feature available from {{ Gecko("1.9") }}.</small></dd>
          <dt>
            <a href="/en-US/docs/HTML/Canvas/Drawing_DOM_objects_into_a_canvas" title="en-US/docs/HTML/Canvas/Drawing DOM objects into a canvas">Drawing DOM objects into a canvas</a></dt>
          <dd>
            <small>How to draw DOM content, such as HTML elements, into a canvas.</small></dd>
          <dt>
            <a href="/en-US/docs/A_Basic_RayCaster" title="A Basic RayCaster">A basic raycaster</a></dt>
          <dd>
            <small>A demo of ray-tracing animation using canvas.</small></dd>
          <dt>
            <a href="/en-US/docs/Gecko_DOM_Reference#Canvas_interfaces" title="/en-US/docs/Gecko_DOM_Reference#Canvas_interfaces">Canvas DOM interfaces</a></dt>
          <dd>Canvas DOM interfaces on Gecko.</dd>
        </dl>
        <p><span class="alllinks"><a href="/en-US/docs/tag/HTML:Canvas" title="/en-US/docs/tag/HTML:Canvas">View All...</a></span></p>
      </td>
      <td>
        <h2 class="Community" id="Community">Community</h2>
        <p><span>* View Mozilla forums... {{ DiscussionList("dev-tech-html", "mozilla.dev.tech.html") }}</span></p>
        <ul>
          <li><a class="external" href="http://groups.yahoo.com/group/canvas-developers/">Canvas-Developers Yahoo Group</a></li>
        </ul>
        <h2 class="Resources" id="Resources" name="Resources">Resources</h2>
        <ul>
          <li><a class="external" href="http://projects.joshy.org/presentations/HTML/CanvasDeepDive/presentation.html" title="http://projects.joshy.org/presentations/HTML/CanvasDeepDive/presentation.html">HTML5 Canvas Deep Dive</a></li>
          <li><a class="external" href="http://blog.nihilogic.dk/2009/02/html5-canvas-cheat-sheet.html" title="http://blog.nihilogic.dk/2009/02/html5-canvas-cheat-sheet.html">Canvas cheat sheet</a> (<a href="http://www.nihilogic.dk/labs/canvas_sheet/HTML5_Canvas_Cheat_Sheet.png" title="HTML5_Canvas_Cheat_Sheet.png (1388×1027)">PNG</a> / <a href="http://www.nihilogic.dk/labs/canvas_sheet/HTML5_Canvas_Cheat_Sheet.pdf" title="http://www.nihilogic.dk/labs/canvas_sheet/HTML5_Canvas_Cheat_Sheet.pdf">PDF</a>)</li>
        </ul>
        <h2 class="Libraries" id="Libraries" name="Libraries">Libraries</h2>
        <ul>
          <li><a class="external" href="http://libcanvas.github.com/" title="http://libcanvas.github.com/">libCanvas</a> is powerful and lightweight canvas framework</li>
          <li><a class="external" href="http://processingjs.org" title="http://processingjs.org/">Processing.js</a> is a port of the Processing visualization language</li>
          <li><a class="external" href="http://easeljs.com/" title="http://easeljs.com/">EaselJS</a> is a library with a Flash-like API</li>
          <li><a class="external" href="http://www.liquidx.net/plotkit/" title="http://www.liquidx.net/plotkit/">PlotKit</a> is a charting and graphing library</li>
          <li><a class="link-https" href="https://github.com/jeremyckahn/rekapi" title="https://github.com/jeremyckahn/rekapi">Rekapi</a> is an animation keyframing API for Canvas</li>
          <li><a class="external" href="http://senchalabs.github.com/philogl/" title="http://senchalabs.github.com/philogl/">PhiloGL</a> is a WebGL framework for data visualization, creative coding and game development.</li>
          <li><a class="external" href="http://thejit.org/" title="http://thejit.org/">JavaScript InfoVis Toolkit</a> creates interactive 2D Canvas data visualizations for the Web.</li>
        </ul>
        <h2 class="Related_Topics" id="Related_Topics" name="Related_Topics">Related Topics</h2>
        <dl>
          <dd>
            <a href="/en-US/docs/HTML" title="en-US/docs/HTML">HTML</a>, <a href="/en-US/docs/JavaScript" title="en-US/docs/JavaScript">JavaScript</a>, <a href="/en-US/docs/CSS" title="en-US/docs/CSS">CSS</a>, <a href="/en-US/docs/AJAX" title="en-US/docs/AJAX">AJAX</a>, <a href="/en-US/docs/DOM" title="en-US/docs/DOM">DOM</a>, <a href="/en-US/docs/SVG" title="en-US/docs/SVG">SVG</a>, <a href="/en-US/docs/WebGL" title="en-US/docs/WebGL">WebGL</a></dd>
        </dl>
      </td>
    </tr>
  </tbody>
</table>
<div>
  {{ HTML5ArticleTOC() }}</div>
Revert to this revision