Which is faster canvas or div? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Which is faster canvas or div?

I have heard a lot of people say that moving div elements around is a lot faster than using a canvas. I have been developing games and I wanted to make sure this was true before continuing to use divs. Divs seem to be a lot easier to use since I can also use css to style them. I am using pure JavaScript and would like to know the differences in speed. I am currently using window.getAnimationFrame for my game . I need a way to use css to style my game objects.

1st Nov 2021, 5:37 PM
hg0428
hg0428 - avatar
3 Answers
+ 2
Canvas is used as a container for graphics and Javascript is usually used with it. So you should probably keep using your engine.
3rd Nov 2021, 2:03 PM
Lebi
+ 1
<div> is a container like <article> and <canvas> is a 2d graphic creation tag like <svg>. <canvas> is the one that is usually used in games because of its specificities. If you want more info on the topic you should take the HTML course (this will be covered in the HTML5 module).
1st Nov 2021, 7:43 PM
Lebi
+ 1
@lebi I need a way to use css to style my game objects. I have already built a full game engine using divs, so I dont know why I should turn back now. It's also much easier (and potentially faster) than canvas, I am using the window.requestAnimationFrame. Can I use CSS to style objects in canvas or svg?
3rd Nov 2021, 1:39 PM
hg0428
hg0428 - avatar