Add css linear-gradient background image to canvas background

So I have a background gradient style

background-image: linear-gradient(to top, #1c1d22, #28292e, #34353a, #404247, #4d4f54);

I also have a canvas element I wish too use that gradient as the background.

I know you can draw an image as a background on the canvas ::

var background = new Image();
background.src = "http://www.example.com/image.jpb";

^ similar above, but I don’t know how to set the linear-gradient style I have for my div background in css as the background for my canvas.

I’ve tried making the background of the canvas transparent and the div behind the style, but was unable too.

I tried Canvas background transparent and background div having the background.