SVGLineElement: x1 property
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The x1 read-only property of the SVGLineElement interface describes the start of the SVG line along the x-axis as an SVGAnimatedLength. It reflects the <line> element's x1 geometric attribute.
The attribute value is a <length>, <percentage>, or <number>. The numeric value of the SVGAnimatedLength.baseVal is that start position as a length along the x-axis in user coordinate system units.
Value
Example
Given the following SVG:
html
<svg viewBox="0 0 300 200" xmlns="http://www.w3.org/2000/svg">
<line x1="20" y1="30" x2="40" y2="50" stroke="blue" stroke-width="2" />
<line x1="15%" y1="0" x2="30%" y2="60" stroke="red" stroke-width="4" />
</svg>
We can access the computed values of the x1 attributes:
js
const lines = document.querySelectorAll("line");
const x1Pos0 = lines[0].x1;
const x1Pos1 = lines[1].x1;
console.dir(x1Pos0.baseVal.value); // output: 20 (the value of `x1`)
console.dir(x1Pos1.baseVal.value); // output: 45 (15% of 300)
Specifications
| Specification |
|---|
| Scalable Vector Graphics (SVG) 2> # __svg__SVGLineElement__x1> |
Browser compatibility
Loading…