Why can't I change the background of my canvas?

Muhammad

New Member
#1
So, I want to make a snake game as a beginner project to get myself into game-making, which is the main reason why I want to code in the first place.

I made my canvas and, after a while, I got it to show up with the border. However, the background of my canvas won't change and I'm not sure why.

I tried using JSHint but it wasn't very helpful.
Mã:
<canvas id="gameCanvas" width="700" height="600" backgroundColor="yellow" style="border:4px solid black;">Good morning</canvas>
 

Admin

Administrator
Thành viên BQT
#2
You need to specify the background colour in the style attribute, like this:
Mã:
style="border:4px solid black; background-color: yellow"
See demo below:
Mã:
<canvas id="gameCanvas" width="700" height="600" style="border:4px solid black; background-color: yellow">Good morning</canvas>
 
Top