Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
const ctx = canvas.getContext("2d"); ctx.font = "bold 32px Arial"; ctx.fillStyle = "#333"; ctx.textAlign = "center"; ctx.fillText("Hello Canvas", canvas.width / 2, 60); // Outlined text ctx.font = "48px Georgia"; ctx.strokeStyle = "#007bff"; ctx.lineWidth = 2; ctx.strokeText("Outlined", 200, 150); // Measure text width const metrics = ctx.measureText("Hello"); console.log(metrics.width);
Result
Open