An example of the HTML5 canvas path functions: lineTo() example

This draws a simple line from the bottom left of the canvas to the top right.

[No canvas support]
<script>
    context = document.getElementById('cvs').getContext('2d');
    
    context.beginPath();
        context.lineWidth = 5;
        context.lineCap = 'round'; // This determines the style that the ends of the line will use
        context.strokeStyle = 'red';
        context.moveTo(50,200);
        context.lineTo(550,50);
    context.stroke();
</script>

« Back to article