Canvas

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

Revision Content

Added in HTML5, the HTML {{HTMLElement("canvas")}} element is an 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 or rendering.

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 HTML5.
HTMLCanvasElement
The HTMLCanvasElement interface provides properties and methods for manipulating the layout and presentation of canvas elements. The HTMLCanvasElement interface also inherits the properties and methods of the HTMLElement interface.
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 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.

View All...

Community

Resources

Libraries

  • Paper.js is an open source vector graphics scripting framework that runs on top of the HTML5 Canvas
  • 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.
  • Frame-Engine is a framework for developping applications and games
{{HTML5ArticleTOC}}

Revision Source

<p>Added in <a href="/en-US/docs/HTML/HTML5">HTML5</a>, the <strong>HTML {{HTMLElement("canvas")}} element</strong> is an element which can be used to draw graphics via scripting (usually <a href="/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 or rendering.</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">Firefox 1.5</a>). The element was originally introduced by Apple for the OS X <a 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 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">WebGL</a> to do hardware-accelerated 3D graphics on web pages.</p>


<div class="row topicpage-table">
  <div class="section">
    <h2 class="Documentation" id="Documentation" name="Documentation">Documentation</h2>
    <dl>
      <dt><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#the-canvas-element">Specification</a></dt>
      <dd>The <code>&lt;canvas&gt;</code> element is part of the WhatWG Web applications 1.0 specification, also known as HTML5.</dd>
      <dt><a href="/en-US/docs/Web/API/HTMLCanvasElement">HTMLCanvasElement</a></dt>
      <dd>The <strong><code><span>HTMLCanvasElement</span></code></strong> interface provides properties and methods for manipulating the layout and presentation of canvas elements. The <code>HTMLCanvasElement</code> interface also inherits the properties and methods of the <a href="/en-US/docs/Web/API/HTMLElement"><code>HTMLElement</code></a> interface.</dd>
      <dt><a href="/en-US/docs/Web/HTML/Canvas/Tutorial">Canvas tutorial</a></dt>
      <dd>A comprehensive tutorial covering both the basic usage of <code>&lt;canvas&gt;</code> and its advanced features.</dd>
      <dt><a href="/en-US/docs/Code_snippets/Canvas">Code snippets:Canvas</a></dt>
      <dd>Some extension developer-oriented code snippets involving <code>&lt;canvas&gt;</code>.</dd>
      <dt><a href="/en-US/docs/tag/Canvas_examples">Canvas examples</a></dt>
      <dd>A few <code>&lt;canvas&gt;</code> demos.</dd>
      <dt><a href="/en-US/docs/HTML/Canvas/Drawing_DOM_objects_into_a_canvas">Drawing DOM objects into a canvas</a></dt>
      <dd>How to draw DOM content, such as HTML elements, into a canvas.</dd>
      <dt><a href="/en-US/docs/HTML/Canvas/A_Basic_RayCaster">A basic raycaster</a></dt>
      <dd>A demo of ray-tracing animation using canvas.</dd>
      <dt><a href="/en-US/docs/DOM/DOM_Reference#HTML_element_interfaces">Canvas DOM interfaces</a></dt>
      <dd>Canvas DOM interfaces.</dd>
    </dl>
    <p><span class="alllinks"><a href="/en-US/docs/tag/HTML:Canvas">View All...</a></span></p>
  </div>
  <div class="section">
    <h2 class="Community" id="Community">Community</h2>
    <ul>
      <li>View Mozilla forums... {{DiscussionList("dev-tech-html","mozilla.dev.tech.html")}}</li>
      <li><a 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 href="http://joshondesign.com/p/books/canvasdeepdive/title.html">HTML5 Canvas Deep Dive</a></li>
      <li><a href="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">PNG</a> / <a href="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 href="http://paperjs.org/">Paper.js</a> is an open source vector graphics scripting framework that runs on top of the HTML5 Canvas</li>
      <li><a href="http://libcanvas.github.com/">libCanvas</a> is powerful and lightweight canvas framework</li>
      <li><a href="http://processingjs.org">Processing.js</a> is a port of the Processing visualization language</li>
      <li><a href="http://easeljs.com/">EaselJS</a> is a library with a Flash-like API</li>
      <li><a href="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">Rekapi</a> is an animation keyframing API for Canvas</li>
      <li><a href="http://senchalabs.github.com/philogl/">PhiloGL</a> is a WebGL framework for data visualization, creative coding and game development.</li>
      <li><a href="http://thejit.org/">JavaScript InfoVis Toolkit</a> creates interactive 2D Canvas data visualizations for the Web.</li>
      <li><a href="http://www.frame-engine.com">Frame-Engine</a> is a framework for developping applications and games</li>
    </ul>
    <h2 class="Related_Topics" id="Related_Topics" name="Related_Topics">Related Topics</h2>
    <ul>
      <li><a href="/en-US/docs/HTML">HTML</a>, <a href="/en-US/docs/JavaScript">JavaScript</a>, <a href="/en-US/docs/CSS">CSS</a>, <a href="/en-US/docs/AJAX">AJAX</a>, <a href="/en-US/docs/DOM">DOM</a>, <a href="/en-US/docs/SVG">SVG</a>, <a href="/en-US/docs/WebGL">WebGL</a></li>
    </ul>
  </div>
</div>


<div>{{HTML5ArticleTOC}}</div>
Revert to this revision