The SVG <line> element draws a straight segment between two points: start (x1, y1) and end (x2, y2). Place it inside an <svg>.
A line has no fill area — it is pure stroke. Style with stroke, stroke-width, and related properties from SVG stroke. For chains of segments, use <polyline>.
Baseline · Widely available.
<line> is a stable SVG basic shape across modern browsers since about July 2015.
No stroke = invisible.
If you omit stroke (or set stroke-width to 0), the line does not show — even when coordinates are correct.
Most missing-line bugs are stroke, zero width, or viewport clipping.
stroke
Stroke is required
Default stroke is none for teaching purposes in practice — always set stroke and a positive stroke-width.
viewBox
Stay inside the viewBox
Endpoints outside the SVG box are clipped. Size the graphic to fit both points plus half the stroke width.
fill
Fill does nothing useful
<line> has no interior. Changing fill will not paint the segment — use stroke properties.
choice
One segment only
Need corners or many points? Prefer <polyline> or <path> instead of stacking many lines.
Compatibility
Browser Support
The SVG <line> element is supported in every modern browser.
✓ Baseline · Widely available
SVG <line>
Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support line geometry and stroke presentation attributes. Internet Explorer 9+ supports basic SVG lines.
98%Global support (approx.)
Google ChromeAll modern
Full support
Mozilla FirefoxAll modern
Full support
Apple SafariAll modern
Full support
Microsoft EdgeAll modern
Full support
OperaAll modern
Full support
Samsung InternetAll modern
Full support
Internet Explorer9+
Supported
<line>Widely supported
Bottom line: Safe for production charts, icons, and UI guides. Always set stroke explicitly in examples and production markup.
Remember
Key Takeaways
Geometry:x1, y1, x2, y2.
Paint:stroke + stroke-width (not fill).
Style: caps and stroke-dasharray.
Many points? Use polyline or path.
One line: two points + stroke inside an <svg>.
UA style
Default CSS Settings
Conceptual SVG presentation defaults for lines:
defaults.css
/* Conceptual SVG defaults */
line {
fill: none; /* lines are stroked, not filled */
stroke: none; /* set stroke yourself or nothing shows */
stroke-width: 1;
stroke-linecap: butt;
}
Always set stroke explicitly in tutorials and production markup.
Frequently Asked Questions
Put a <line> inside an <svg>. Set x1,y1 for the start and x2,y2 for the end, then set stroke and stroke-width.
Lines have no fill. Without stroke (or with stroke-width 0), nothing shows. Also check the viewBox and SVG size.
Use stroke-dasharray, for example stroke-dasharray="8 6" for dash 8 and gap 6.
It shapes the ends: butt (flat), round, or square (extends past the endpoints).
Use line for one straight segment. Use polyline for connected segments, and path for curves or mixed commands.
Yes. Set stroke, stroke-width, stroke-linecap, and stroke-dasharray as attributes or CSS.