Related Articles

Related Articles

SVG x Attribute
  • Last Updated : 15 Oct, 2020

The x attribute defines an x-axis coordinate in the user coordinate system.

Syntax:

x = "x-coordinate"

Attribute Values:

  • length: Length at which we want to set the x-axis.
  • percentage: Percentage at which we want to set the x-axis.

We will use the x attribute for setting x coordinate for the elements.

Example 1: Rectangle element with the different x-axis.



filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<body>
    <svg width="200" height="200" 
            viewBox="0 0 300 300">
  
        <rect x="20" y="20" width="60" 
            height="60" fill="green" />
  
        <rect x="120" y="20" width="60" 
            height="60" fill="green" />
              
        <rect x="220" y="20" width="60" 
            height="60" fill="green" />
    </svg>
</body>
  
</html>

chevron_right


Output:
 

Example 2: Rectangle element with the same x-axis.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<body>
    <svg width="200" height="200" 
            viewBox="0 0 300 300">
  
        <rect x="20" y="20" width="60" 
            height="60" fill="green" />
  
        <rect x="20" y="120" width="60" 
            height="60" fill="green" />
  
        <rect x="20" y="120" width="60" 
            height="60" fill="green" />
    </svg>
</body>
  
</html>

chevron_right


Output:

Example 3: Use percentage value.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<body>
    <svg width="200" height="200" 
            viewBox="0 0 300 300">
              
        <rect x="30%" y="30%" width="60" 
            height="60" fill="green" />
    </svg>
</body>
  
</html>

chevron_right


Output:

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :