To calculate text width using Javascript, You need to use the canvas.measureText() method.

Demo : calculate text width Try it Yourself »