Code
Execute
<!DOCTYPE html> <html> <head> <title>wikitechy measuretext()method</title> </head> <body> <h1>wikitechy measuretext()method</h1> <canvas id="wikitechyCanvas" width="300" height="150" style="border:1px solid #d3d3d3;"> </canvas> <script> var canvas = document.getElementById("wikitechyCanvas"); var context = canvas.getContext("2d"); context.font = "25px Times new Roman"; var txt = "wikitechy world"; context.fillText("width:" + context.measureText(txt).width, 10, 50); context.fillText(txt, 10, 100); </script> </body> </html>
Result