How to position Path2D SVG element in canvas?

Use the transform to move the path Using CanvasRenderingContext2D.translate const canvas = document.getElementById(‘canvas’); const ctx = canvas.getContext(‘2d’); let p = new Path2D(‘M10 10 h 80 v 80 h -80 Z’); ctx.translate(100, 100); ctx.fill(p); or using CanvasRenderingContext2D.setTransform let p = new Path2D(‘M10 10 h 80 v 80 h -80 Z’); ctx.setTransform(1, 0, 0, 1, 100, 100); … Read more