Canvas for Three.js Projects

Is it really necessary to use the html Element canvas for a Three.Js Project?

  <style>
        body {
            margin:0;
        }
        canvas {
            width:100%;
            height: 100%;
        }
    </style>

On the website https://threejs.org/docs/index.html#manual/en/introduction/Creating-a-scene is it included, but in the examples I can not see the use of canvas …

Thanks for your replies
Mario

A canvas is giving the actual WebGL context, you can’t use it without, there is a canvas in every example.

2 Likes

When you instantiate WebGLRenderer, you can pass in a canvas dom element. But if you don’t, it will be created automatically, then you must attach it to an element of the dom (document.body generally) :

renderer = new THREE.WebGLRenderer();
document.body.appendChild( renderer.domElement );
1 Like

Oh, I see. Now I understand!
Thanks a lot!!