1.仕様
CANVAS要素は、
ビットマップキャンバスを
スクリプトに提供します。
CANVAS - - (%Transparent) -- Provides a bitmap canvas to a script. (Normal elements.) [Flow
- canvas
-
ビットマップキャンバスをスクリプトに提供 (Provides a bitmap canvas to a script)
- 種類
-
通常要素
- カテゴリ
-
- フロー
コンテンツ - フレージング
コンテンツ - エンベデッド
コンテンツ - パルパブル
コンテンツ
- フロー
- 使用できるコンテキスト
-
エンベデッド
コンテンツ を受け入れる要素エンベデッド
コンテンツ を受け入れる要素のコンテンツとして、使用できます。エンベデッド
コンテンツ を受け入れる要素は、<body>要素 , <section>要素 , <nav>要素 , <aside>要素 , <article>要素 , <header>要素 , <footer>要素 , <main>要素 , <address>要素 , <li>要素 , <dt>要素 , <dd>要素 , <caption>要素 , <th>要素 , <td>要素 , <form>要素 , <fieldset>要素 , <search>要素 , <blockquote>要素 , <figure>要素 , <figcaption>要素 , <div>要素 , <dialog>要素 , <h1>要素 , <h2>要素 , <h3>要素 , <h4>要素 , <h5>要素 , <h6>要素 , <p>要素 , <pre>要素 , <output>要素 , <progress>要素 , <meter>要素 , <datalist>要素 , <abbr>要素 , <b>要素 , <bdi>要素 , <bdo>要素 , <cite>要素 , <code>要素 , <data>要素 , <dfn>要素 , <em>要素 , <i>要素 , <kbd>要素 , <mark>要素 , <q>要素 , <s>要素 , <samp>要素 , <small>要素 , <span>要素 , <strong>要素 , <sub>要素 , <sup>要素 , <u>要素 , <var>要素 です。 - コンテンツモデル
-
透過的コンテンツ
一部の要素は透明であると説明されており、そのコンテンツモデルの説明には「transparent」がある。透明な要素のコンテンツモデルは、その親要素のコンテンツモデルから派生します。「transparent」であるコンテンツモデルの部分で要求される要素は、透明な要素がそれ自身を見つける透明な要素の親のコンテンツモデルの部分で要求される要素と同じ要素です。
透過的コンテンツですが、a要素, usemap属性を持つ img要素, button要素, type属性が Checkbox または Radio Button 状態である input要素, ボタンである input要素, および multiple属性または 1 より大きい表示サイズを持つ select要素を除いて、インタラクティブなコンテンツの子孫はありません。
- タグの省略
-
どちらのタグも省略できません。
- DOM インターフェイス
-
HTMLCanvasElement
[Exposed=Window]
interface HTMLCanvasElement : HTMLElement {
[HTMLConstructor] constructor();
[CEReactions] attribute unsigned long width;
[CEReactions] attribute unsigned long height;
RenderingContext? getContext(DOMString contextId, optional any options = null);
USVString toDataURL(optional DOMString type = "image/png", optional any quality);
undefined toBlob(BlobCallback _callback, optional DOMString type = "image/png", optional any quality);
OffscreenCanvas transferControlToOffscreen();
};
HTMLElement
[Exposed=Window]
interface HTMLElement : Element {
[HTMLConstructor] constructor();
// metadata attributes
[CEReactions] attribute DOMString title;
[CEReactions] attribute DOMString lang;
[CEReactions] attribute boolean translate;
[CEReactions] attribute DOMString dir;
// user interaction
[CEReactions] attribute (boolean or unrestricted double or DOMString)? hidden;
[CEReactions] attribute DOMString inert;
undefined click();
[CEReactions] attribute DOMString accessKey;
readonly attribute DOMString accessKeyLabel;
[CEReactions] attribute boolean draggable;
[CEReactions] attribute boolean spellcheck;
[CEReactions] attribute DOMString writingSuggestions;
[CEReactions] attribute DOMString autocapitalize;
[CEReactions] attribute [LegacyNullToEmptyString] DOMString innerText;
[CEReactions] attribute [LegacyNullToEmptyString] DOMString outerText;
ElementInternals attachInternals();
// The popover API
undefined showPopover();
undefined hidePopover();
boolean togglePopover(optional boolean force);
[CEReactions] attribute DOMString? popover;
};
HTMLElement includes GlobalEventHandlers;
HTMLElement includes ElementContentEditable;
HTMLElement includes HTMLOrSVGElement;
Element
[Exposed=Window]
interface Element : Node {
readonly attribute DOMString? namespaceURI;
readonly attribute DOMString? prefix;
readonly attribute DOMString localName;
readonly attribute DOMString tagName;
[CEReactions] attribute DOMString id;
[CEReactions] attribute DOMString className;
[SameObject, PutForwards=value] readonly attribute DOMTokenList classList;
[CEReactions, Unscopable] attribute DOMString slot;
boolean hasAttributes();
[SameObject] readonly attribute NamedNodeMap attributes;
sequence<DOMString> getAttributeNames();
DOMString? getAttribute(DOMString qualifiedName);
DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
[CEReactions] undefined setAttribute(DOMString qualifiedName, DOMString value);
[CEReactions] undefined setAttributeNS(DOMString? namespace, DOMString qualifiedName, DOMString value);
[CEReactions] undefined removeAttribute(DOMString qualifiedName);
[CEReactions] undefined removeAttributeNS(DOMString? namespace, DOMString localName);
[CEReactions] boolean toggleAttribute(DOMString qualifiedName, optional boolean force);
boolean hasAttribute(DOMString qualifiedName);
boolean hasAttributeNS(DOMString? namespace, DOMString localName);
Attr? getAttributeNode(DOMString qualifiedName);
Attr? getAttributeNodeNS(DOMString? namespace, DOMString localName);
[CEReactions] Attr? setAttributeNode(Attr attr);
[CEReactions] Attr? setAttributeNodeNS(Attr attr);
[CEReactions] Attr removeAttributeNode(Attr attr);
ShadowRoot attachShadow(ShadowRootInit init);
readonly attribute ShadowRoot? shadowRoot;
Element? closest(DOMString selectors);
boolean matches(DOMString selectors);
boolean webkitMatchesSelector(DOMString selectors); // legacy alias of .matches
HTMLCollection getElementsByTagName(DOMString qualifiedName);
HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
HTMLCollection getElementsByClassName(DOMString classNames);
[CEReactions] Element? insertAdjacentElement(DOMString where, Element element); // legacy
undefined insertAdjacentText(DOMString where, DOMString data); // legacy
};
GlobalEventHandlers
interface mixin GlobalEventHandlers {
attribute EventHandler onabort;
attribute EventHandler onauxclick;
attribute EventHandler onbeforeinput;
attribute EventHandler onbeforematch;
attribute EventHandler onbeforetoggle;
attribute EventHandler onblur;
attribute EventHandler oncancel;
attribute EventHandler oncanplay;
attribute EventHandler oncanplaythrough;
attribute EventHandler onchange;
attribute EventHandler onclick;
attribute EventHandler onclose;
attribute EventHandler oncontextlost;
attribute EventHandler oncontextmenu;
attribute EventHandler oncontextrestored;
attribute EventHandler oncopy;
attribute EventHandler oncuechange;
attribute EventHandler oncut;
attribute EventHandler ondblclick;
attribute EventHandler ondrag;
attribute EventHandler ondragend;
attribute EventHandler ondragenter;
attribute EventHandler ondragleave;
attribute EventHandler ondragover;
attribute EventHandler ondragstart;
attribute EventHandler ondrop;
attribute EventHandler ondurationchange;
attribute EventHandler onemptied;
attribute EventHandler onended;
attribute OnErrorEventHandler onerror;
attribute EventHandler onfocus;
attribute EventHandler onformdata;
attribute EventHandler oninput;
attribute EventHandler oninvalid;
attribute EventHandler onkeydown;
attribute EventHandler onkeypress;
attribute EventHandler onkeyup;
attribute EventHandler onload;
attribute EventHandler onloadeddata;
attribute EventHandler onloadedmetadata;
attribute EventHandler onloadstart;
attribute EventHandler onmousedown;
[LegacyLenientThis] attribute EventHandler onmouseenter;
[LegacyLenientThis] attribute EventHandler onmouseleave;
attribute EventHandler onmousemove;
attribute EventHandler onmouseout;
attribute EventHandler onmouseover;
attribute EventHandler onmouseup;
attribute EventHandler onpaste;
attribute EventHandler onpause;
attribute EventHandler onplay;
attribute EventHandler onplaying;
attribute EventHandler onprogress;
attribute EventHandler onratechange;
attribute EventHandler onreset;
attribute EventHandler onresize;
attribute EventHandler onscroll;
attribute EventHandler onscrollend;
attribute EventHandler onsecuritypolicyviolation;
attribute EventHandler onseeked;
attribute EventHandler onseeking;
attribute EventHandler onselect;
attribute EventHandler onslotchange;
attribute EventHandler onstalled;
attribute EventHandler onsubmit;
attribute EventHandler onsuspend;
attribute EventHandler ontimeupdate;
attribute EventHandler ontoggle;
attribute EventHandler onvolumechange;
attribute EventHandler onwaiting;
attribute EventHandler onwebkitanimationend;
attribute EventHandler onwebkitanimationiteration;
attribute EventHandler onwebkitanimationstart;
attribute EventHandler onwebkittransitionend;
attribute EventHandler onwheel;
};
ElementContentEditable
interface mixin ElementContentEditable {
[CEReactions] attribute DOMString contentEditable;
[CEReactions] attribute DOMString enterKeyHint;
readonly attribute boolean isContentEditable;
[CEReactions] attribute DOMString inputMode;
};
HTMLOrSVGElement
interface mixin HTMLOrSVGElement {
[SameObject] readonly attribute DOMStringMap dataset;
attribute DOMString nonce; // intentionally no [CEReactions]
[CEReactions] attribute boolean autofocus;
[CEReactions] attribute long tabIndex;
undefined focus(optional FocusOptions options = {});
undefined blur();
};
- ARIA in HTML
-
暗黙的="
No
" ARIAロール="任意" aria-* 属性="GlobalAny
"暗黙的な ARIAセマンティクスがありませんが、意味はあり、この意味は、ARIA によって提供されず、ARIA のユーザーに公開されていないロール、状態、プロパティで表現される可能性があります。
要素で任意の role 値を使用できます。ただし、作成者が要素の暗黙的なロール, 汎用ロール, または ARIA によって非推奨となったロールをこれらの要素に対して指定することは推奨されません。
グローバル aria-* 属性と、許可されたロールに適用される任意の aria-* 属性が記述できます。
- レンダリング
- 特になし
CSS を大雑把に読むと、 特に指定はされていません。既定値から、フローレイアウトに配置されたときにインラインレベルのボックス(インラインボックス)を生成すると思われます。 などになります。
- 説明
-
canvas
要素 は、ビットマップキャンバスをスクリプトに提供します。canvas
要素 は、解像度に依存するビットマップキャンバスをスクリプトに提供します。これを使用して、グラフ, ゲームグラフィック, アート, またはその他の視覚イメージを即座にレンダリングできます。<!DOCTYPE html>
<html lang=
"ja"> <head>
<meta charset=
"utf-8"> <title>
canvas要素の例 - (Example of canvas element) | 離珠のHTMLでしぃ!</title> <meta name=
"author" content= "コータン (KOUTAN)"> <script>
document
.addEventListener( "DOMContentLoaded", function() { const _coJsCanvas = document
.getElementById( "JCV001"); const _coJsContext = _coJsCanvas
.getContext( "2d"); _coJsContext
.fillStyle = "green"; _coJsContext
.fillRect( 10, 10, 100, 100); });
</script>
<link rel=
"icon" href= "../favicon.ico" type= "image/vnd.microsoft.icon"> </head>
<body>
<h1>
canvas要素の例</h1> <canvas id=
"JCV001" width= "300" height= "300"> canvas要素に対してのスクリプトでの描画に失敗した時の為の、代替テキストコンテンツです。</canvas> </body>
</html>
このサンプルへのリンクです。
(./excanvas.htm) - 参照元
-
参照元
- HTML Living Standard. 4.12.5 The canvas element (最終更新日 2025年8月5日)
- HTML Living Standard. 15 Rendering 15.4.1 Embedded content (最終更新日 2025年8月5日)
- HTML 5.3 W3C 初公開ワーキングドラフト. 4.12.4 The canvas element (W3Cワーキングドラフト、2017年12月14日)
- HTML 5.3 W3C 初公開ワーキングドラフト. 10. Rendering 10.4.1. Embedded content (W3Cワーキングドラフト、2017年12月14日)
- HTML 5.2 W3C 勧告. 4.12.4. The canvas element (W3C勧告、2017年12月14日)
- HTML 5.2 W3C 勧告. 10. Rendering 10.4.1. Embedded content (W3C勧告、2017年12月14日)
- HTML 5.1 W3C 勧告. 4.12.4. The canvas element (W3C勧告、2016年11月1日)
- HTML 5.1 W3C 勧告. 10. Rendering 10.4.1. Embedded content (W3C勧告、2016年11月1日)
- HTML 5 W3C 勧告. 4.11.4 The canvas element (W3C勧告、2014年10月28日)
- HTML 5 W3C 勧告. 10. Rendering 10.4.1. Embedded content (W3C勧告、2014年10月28日)
- MDN Web Docs. HTML <canvas>: グラフィックキャンバス要素
- JSONデータ
-
JSON形式での、データのイメージです。
{
"canvas": {
"check": "2025-08-10",
"group": "Scripting",
"element": "- - (%Transparent) -- Provides a bitmap canvas to a script. (Normal elements.) [Flow|Phrasing|Embedded|Palpable] --",
"attlist": {
"%Global;": "",
"width": "%Length; #IMPLIED -- Horizontal dimension --",
"height": "%Length; #IMPLIED -- Vertical dimension --",
},
"summary": "ビットマップキャンバスをスクリプトに提供 (Provides a bitmap canvas to a script)",
"point": "ビットマップキャンバスをスクリプトに提供します。",
"description": "解像度に依存するビットマップキャンバスをスクリプトに提供します。これを使用して、グラフ, ゲームグラフィック, アート, またはその他の視覚イメージを即座にレンダリングできます。",
"elementKind": "Normal",
"categories": [
"Flow",
"Phrasing",
"Embedded",
"Palpable",
],
"canUsedContexts": "parent %Embedded",
"contentModel": "%Transparent",
"contentmodelsupplement": "透過的コンテンツですが、a要素, usemap属性を持つ img要素, button要素, type属性が Checkbox または Radio Button 状態である input要素, ボタンである input要素, および multiple属性または 1 より大きい表示サイズを持つ select要素を除いて、インタラクティブなコンテンツの子孫はありません。",
"tagOmission": [
"-",
"-",
],
"rendering": "None",
"domInterface": "HTMLCanvasElement",
"contentAttributes": {
"width": "水平寸法",
"height": "垂直寸法",
},
"reference": [
{
"title": "HTML Living Standard. 4.12.5 The canvas element. Last Updated 5 August 2025",
"href": "https://html.spec.whatwg.org/multipage/canvas.html#the-canvas-element",
"heading": "HTML Living Standard. 4.12.5 The canvas element",
"sub": "最終更新日 2025年8月5日",
},
{
"title": "HTML Living Standard. 15 Rendering 15.4.1 Embedded content. Last Updated 5 August 2025",
"href": "https://html.spec.whatwg.org/multipage/rendering.html#embedded-content-rendering-rules",
"heading": "HTML Living Standard. 15 Rendering 15.4.1 Embedded content",
"sub": "最終更新日 2025年8月5日",
},
{
"title": "HTML 5.3 W3C Working Draft. 4.12.4 The canvas element. W3C First Public Working Draft, 14 December 2017",
"href": "https://www.w3.org/TR/2017/WD-html53-20171214/semantics-scripting.html#the-canvas-element",
"heading": "HTML 5.3 W3C 初公開ワーキングドラフト. 4.12.4 The canvas element",
"sub": "W3Cワーキングドラフト、2017年12月14日",
},
{
"title": "HTML 5.3 W3C Working Draft. 10.4.1. Embedded content. W3C First Public Working Draft, 14 December 2017",
"href": "https://www.w3.org/TR/2017/WD-html53-20171214/rendering.html#replaced-elements-embedded-content",
"heading": "HTML 5.3 W3C 初公開ワーキングドラフト. 10. Rendering 10.4.1. Embedded content",
"sub": "W3Cワーキングドラフト、2017年12月14日",
},
{
"title": "HTML 5.2 W3C Recommendation. 4.12.4. The canvas element. W3C Recommendation, 14 December 2017.",
"href": "https://www.w3.org/TR/2017/REC-html52-20171214/semantics-scripting.html#the-canvas-element",
"heading": "HTML 5.2 W3C 勧告. 4.12.4. The canvas element",
"sub": "W3C勧告、2017年12月14日",
},
{
"title": "HTML 5.2 W3C Recommendation. 10.4.1. Embedded content.",
"href": "https://www.w3.org/TR/2017/REC-html52-20171214/rendering.html#replaced-elements-embedded-content",
"heading": "HTML 5.2 W3C 勧告. 10. Rendering 10.4.1. Embedded content",
"sub": "W3C勧告、2017年12月14日",
},
{
"title": "HTML 5.1 W3C Recommendation. 4.12.4. The canvas element. W3C Recommendation, 1 November 2016.",
"href": "https://www.w3.org/TR/2016/REC-html51-20161101/semantics-scripting.html#the-canvas-element",
"heading": "HTML 5.1 W3C 勧告. 4.12.4. The canvas element",
"sub": "W3C勧告、2016年11月1日",
},
{
"title": "HTML 5.1 W3C Recommendation. 10.4.1. Embedded content. W3C Recommendation, 1 November 2016.",
"href": "https://www.w3.org/TR/2016/REC-html51-20161101/rendering.html#replaced-elements-embedded-content",
"heading": "HTML 5.1 W3C 勧告. 10. Rendering 10.4.1. Embedded content",
"sub": "W3C勧告、2016年11月1日",
},
{
"title": "HTML 5 W3C Recommendation. 4.11.4 The canvas element. W3C Recommendation, 28 October 2014.",
"href": "https://www.w3.org/TR/2014/REC-html5-20141028/scripting-1.html#the-canvas-element",
"heading": "HTML 5 W3C 勧告. 4.11.4 The canvas element",
"sub": "W3C勧告、2014年10月28日",
},
{
"title": "HTML 5 W3C Recommendation. 10.4.1. Embedded content. W3C Recommendation, 28 October 2014.",
"href": "https://www.w3.org/TR/2014/REC-html5-20141028/rendering.html#embedded-content-1",
"heading": "HTML 5 W3C 勧告. 10. Rendering 10.4.1. Embedded content",
"sub": "W3C勧告、2014年10月28日",
},
{
"title": "MDN Web Docs. HTML <canvas>: The Graphics Canvas element.",
"href": "https://developer.mozilla.org/ja/docs/Web/HTML/Element/canvas",
"heading": "MDN Web Docs. HTML <canvas>: グラフィックキャンバス要素",
},
],
"version": {
"first": "HTML5",
"latest": "HTML Living Standard",
},
}
}
注意: 簡易に描画する為に、各項目の後ろに
,
を付与しています。JSON の形式では、末尾の項目の後には,
は付けません。 - 最終確認日
-
2025-08-10
2.使用できるコンテキスト
canvas要素は、
エンベデッドコンテンツを
受け入れる要素に
配置できます。
<canvas>
エンベデッド
- <body>
要素 - <section>
要素 - <nav>
要素 - <aside>
要素 - <article>
要素 - <header>
要素 - <footer>
要素 - <main>
要素 - <address>
要素 - <li>
要素 - <dt>
要素 - <dd>
要素 - <caption>
要素 - <th>
要素 - <td>
要素 - <form>
要素 - <fieldset>
要素 - <search>
要素 - <blockquote>
要素 - <figure>
要素 - <figcaption>
要素 - <div>
要素 - <dialog>
要素 - <h1>
要素 - <h2>
要素 - <h3>
要素 - <h4>
要素 - <h5>
要素 - <h6>
要素 - <p>
要素 - <pre>
要素 - <output>
要素 - <progress>
要素 - <meter>
要素 - <datalist>
要素 - <abbr>
要素 - <b>
要素 - <bdi>
要素 - <bdo>
要素 - <cite>
要素 - <code>
要素 - <data>
要素 - <dfn>
要素 - <em>
要素 - <i>
要素 - <kbd>
要素 - <mark>
要素 - <q>
要素 - <s>
要素 - <samp>
要素 - <small>
要素 - <span>
要素 - <strong>
要素 - <sub>
要素 - <sup>
要素 - <u>
要素 - <var>
要素
<p>
<canvas id=
"JCV201" width= "300" height= "300"> </canvas> </p>
<canvas>
<canvas>
3.コンテンツモデル
canvas要素は、
親要素の内容として
適切なコンテンツが
配置できます。
<canvas>
別の言い方で細かく言うと、<canvas>
コンテンツモデルで「透過的」(transparent) とは、その透明な要素のコンテンツモデルは、その透明な要素の親要素のコンテンツモデルから派生するという事です。つまり、「透明」であるコンテンツモデルの部分に必要な要素は、透明な要素が含まれる透明な要素の親のコンテンツモデルの部分に必要な要素と同じです。
<canvas>
4.コンテンツ属性
canvas要素は、
グローバル属性と、
width属性,
height属性 を
配置できます。
width属性
<canvas id=
"JCV401" width= "300" height="300"> </canvas>
width
height属性
<canvas id=
"JCV402" width= "300" height= "300" ></canvas>
height
5.DOM インターフェイス
canvas要素を、
直接表す
プロパティは
ありません。
<canvas>document
のgetElementById()メソッドを用いてid
<canvas id=
"JCV501" width= "50" height= "60"> </canvas> <script>
document
.addEventListener( "DOMContentLoaded", function() { const _coJsContext = document
.getElementById( "JCV501") .getContext( "2d"); _coJsContext
.fillStyle = "green"; _coJsContext
.fillRect( 10, 10, 100, 100); });
</script>
<canvas>
6.アクセシビリティ
canvas要素の
暗黙的な
ARIAセマンティクスは
ありません。
<canvas>No corresponding role
とマークされている要素は、ARIAの暗黙的なセマンティクスを持ちませんが、意味を持ちます。この意味は、ARIAでは提供されていないロール、ステート、プロパティで表現され、アクセシビリティ
作成者が<canvas>Any role
(任意の役割) です。要素に任意のロール値を使用できることを表します。ただし、作成者が要素の暗黙的な
ARIA の状態とプロパティについては、すべての要素で使用できるグローバル
つまり、<canvas>
7.レンダリング
canvas要素の
レンダリングの
CSSでの指定は
ありません。
<canvas>
埋め込みコンテンツを表す<canvas>
8.気を付ける点
何故、canvas要素を用いるのか
意図を理解して
記述しましょう
<canvas>
<canvas>