ImageToSVG

SVG isPointInStroke() Method

isPointInStroke() tests whether a given point lies on a shape's stroke, enabling hit detection specifically on outlines and lines.

Preset:
Colors:
VTracer vectorization + SVGO optimizationPrivacy protected

Testing Whether a Point Is on a Stroke

Calling isPointInStroke(point) on an SVG geometry element returns true if the given SVGPoint lies on the element's stroke, accounting for the stroke's width, which enables precise hit detection specifically for line-based or outline-based interactive elements where the fill isn't the relevant clickable area.

  • isPointInStroke(point) returns true if the point lies on the shape's stroke
  • Accounts for the actual stroke width in the hit test calculation
  • Enables precise hit detection for line-based or outline interactive elements

Practical Uses for Stroke Hit Testing

isPointInStroke() is particularly useful for interactive diagrams where the connecting lines between nodes should be clickable (like selecting an edge in a network graph), for interactive path-based drawings where only the outline matters, or for making thin decorative strokes easier to click by testing against their actual stroke width rather than a hairline geometry.

  • Makes connecting lines between diagram nodes reliably clickable
  • Enables selecting an edge in an interactive network graph
  • Makes thin strokes easier to click by testing their actual rendered width

Frequently Asked Questions

Does isPointInStroke() account for stroke-dasharray gaps?

Behavior with dashed strokes can vary, so for a dashed line the point might not register on a gap between dashes — testing the specific behavior in your target browsers is worthwhile if dashed-stroke hit testing matters.

Can I use both isPointInFill() and isPointInStroke() together on one shape?

Yes, combining both lets you distinguish whether a click landed on a shape's interior fill versus its outline stroke, useful for interactions that treat those two regions differently.

Related guides

Ready to Convert Your Image to SVG?

Free online converter — no sign-up, no watermarks, results in under 3 seconds.

Try It Free — Convert Image to SVG