--- title: HTMLCanvasElement.width slug: Web/API/HTMLCanvasElement/width translation_of: Web/API/HTMLCanvasElement/width --- <div> <div> <div>{{APIRef("Canvas API")}}</div> <div> </div> <div> <p>Własność <strong><code>HTMLCanvasElement.width </code></strong>wyrażana jest w dodatniej <code>liczbie całkowitej </code>odpowiada za atrybut {{htmlattrxref("width", "canvas")}} elemetu HTML {{HTMLElement("canvas")}} i jest interpretowana w pikselach CSS. Jeśli atrybut nie został określony, lub została przypisana do niego nieprawidłowa wartość, np. negatywna, zostanie użyta domyślna wartość <code>300</code>.</p> <p>To jedna z dwóch własności kontrolujących wielkość {{HTMLElement("canvas")}}, druga z nich to {{domxref("HTMLCanvasElement.height")}}.</p> </div> </div> </div> <h2 id="Syntax" name="Syntax">Składnia</h2> <pre class="syntaxbox"><var>var <em>pxl</em> = <em>canvas</em></var>.width; <em>canvas</em>.width = <em>pxl</em>; </pre> <h2 id="Przykłady">Przykłady</h2> <p>Wykorzystując element {{HTMLElement("canvas")}}:</p> <pre class="brush: html"><canvas id="canvas" width="300" height="300"></canvas> </pre> <p>You can get the width of the canvas with the following code:</p> <p>Informacje o szerokości {{HTMLElement("canvas")}} można uzyskać za pomocą kodu:</p> <pre class="brush: js">var canvas = document.getElementById('canvas'); console.log(canvas.width); // 300 </pre> <h2 id="Specyfikacja">Specyfikacja</h2> <table class="standard-table"> <tbody> <tr> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> <tr> <td>{{SpecName('HTML WHATWG', "scripting.html#attr-canvas-width", "HTMLCanvasElement.width")}}</td> <td>{{Spec2('HTML WHATWG')}}</td> <td>Brak zmian od ostatniego snapshota, {{SpecName('HTML5 W3C')}}</td> </tr> <tr> <td>{{SpecName('HTML5.1', "scripting-1.html#attr-canvas-width", "HTMLCanvasElement.width")}}</td> <td>{{Spec2('HTML5.1')}}</td> <td> </td> </tr> <tr> <td>{{SpecName('HTML5 W3C', "scripting-1.html#attr-canvas-width", "HTMLCanvasElement.width")}}</td> <td>{{Spec2('HTML5 W3C')}}</td> <td>Snapshot {{SpecName('HTML WHATWG')}} zawierający początkową definicje.</td> </tr> </tbody> </table> <h2 id="Zgodność_przegladarek">Zgodność przegladarek</h2> <p>{{Compat("api.HTMLCanvasElement.width")}}</p> <h2 id="See_Also" name="See_Also">Zobacz też</h2> <ul> <li>Interfejs definiujący tą własność, {{domxref("HTMLCanvasElement")}}.</li> <li>Inna własność kontrolujaca wielkość {{HTMLElement("canvas")}}, {{domxref("HTMLCanvasElement.height")}}.</li> </ul>