Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

SVG x2 Attribute

  • Last Updated : 15 Oct, 2020

The x2 attribute is used to specify the first x-coordinate for drawing an SVG element that requires more than one coordinate.

Elements that are using this attribute:

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

Syntax:

x2 = "x2-coordinate"

Attribute Values:



  • length: Length at which we want to set the x2-coordinate.
  • percentage: Percentage at which we want to set the x2-coordinate.

We will use the x2 attribute for setting the x2-coordinate.

Example 1: In this example we will use the length value.




<!DOCTYPE html>
<html>
  
<body>
    <svg viewBox="0 0 70 70" 
        xmlns="http://www.w3.org/2000/svg">
          
        <line x1="7" x2="3" y1="1" 
            y2="9" stroke="red" />
          
        <line x1="7" x2="7" y1="1" 
            y2="9" stroke="green" />
          
        <line x1="7" x2="11" y1="1" 
            y2="9" stroke="blue" />
    </svg>
</body>
  
</html>

Output:

Example 2: In this example we will use the percentage value. 




<!DOCTYPE html>
<html>
  
<body>
    <svg viewBox="0 0 70 70" 
        xmlns="http://www.w3.org/2000/svg">
          
        <line x1="21%" x2="9%" y1="1" 
                y2="9" stroke="red" />
          
        <line x1="21%" x2="21%" y1="1" 
                y2="9" stroke="green" />
          
        <line x1="21%" x2="33%" y1="1" 
                y2="9" stroke="blue" />
    </svg>
</body>
  
</html>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :