Course contentsShow
← Web Development
Lesson 2620 of 2,98247. Data VisualizationFree lesson

Line Styles and Properties

Customizing line appearance with lineWidth, lineCap, lineJoin, and miterLimit properties.

Line Styles and Properties

You'll learn how to fine-tune the appearance of lines on HTML Canvas using lineWidth, lineCap, lineJoin, and miterLimit properties.

When drawing paths on Canvas, you're not limited to basic strokes. Canvas gives you precise control over how lines look—their thickness, how their ends appear, and how corners connect. Think of it like choosing between a calligraphy pen, a chisel-tip marker, or a round brush; each creates distinctly different line qualities.

The Four Key Properties

lineWidth controls the thickness of your strokes, measured in pixels. A lineWidth of 1 creates a hairline, while 10 produces a bold stroke. This is your "pen thickness" control.

lineCap determines how line endpoints appear. It accepts three values:

  • 'butt' (default): flat edges precisely at endpoints
  • 'round': rounded caps extending half the lineWidth beyond endpoints
  • 'square': squared caps extending half the lineWidth beyond endpoints

lineJoin controls how path segments connect at corners:

  • 'miter' (default): sharp, pointed corners
  • 'round': smoothly rounded corners
  • 'bevel': flattened, cut-off corners

miterLimit works with miter joins to prevent excessively long spikes at sharp angles. When the miter length exceeds this ratio (default 10), Canvas automatically switches to a bevel join. Think of it as a safety valve for extreme angles.

These properties work together to create professional-looking charts and visualizations. A line chart might use rounded caps and joins for a softer feel, while architectural diagrams might prefer sharp miters for precision.

Key Takeaway: Canvas line properties—lineWidth, lineCap, lineJoin, and miterLimit—give you fine-grained control over stroke appearance, essential for creating polished data visualizations and custom graphics.