Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions files/en-us/web/api/canvas_api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ This simple example draws a green rectangle onto a canvas.
### HTML

```html
<canvas id="canvas"></canvas>
<canvas id="drawingCanvas"></canvas>
```
Use a descriptive ID to make it clear what the canvas element is used for.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mdn-linter] reported by reviewdog 🐶

Suggested change
Use a descriptive ID to make it clear what the canvas element is used for.
Use a descriptive ID to make it clear what the canvas element is used for.


### JavaScript

The {{domxref("Document.getElementById()")}} method gets a reference to the HTML `<canvas>` element. Next, the {{domxref("HTMLCanvasElement.getContext()")}} method gets that element's context—the thing onto which the drawing will be rendered.

The actual drawing is done using the {{domxref("CanvasRenderingContext2D")}} interface. The {{domxref("CanvasRenderingContext2D.fillStyle", "fillStyle")}} property makes the rectangle green. The {{domxref("CanvasRenderingContext2D.fillRect()", "fillRect()")}} method places its top-left corner at (10, 10), and gives it a size of 150 units wide by 100 tall.


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mdn-linter] reported by reviewdog 🐶

Suggested change

```js
const canvas = document.getElementById("canvas");
const canvas = document.getElementById("drawingCanvas");
const ctx = canvas.getContext("2d");

ctx.fillStyle = "green";
Expand Down
Loading