css inline:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<canvas width="600px" height="400px"></canvas>
<script src="main.js"></script>
</body>
</html>
agora com css externo:
canvas{
width: 600px;
height: 400px;
border: 1px solid black;
}
js:
var tela = document.querySelector('canvas');
var pincel = tela.getContext('2d');
pincel.fillStyle = 'grey';
pincel.fillRect(0, 0, 600, 400);
pincel.fillStyle = 'green';
pincel.fillRect(0, 0, 200, 400);