The Wayback Machine - https://web.archive.org/web/20240709175813/https://www.geeksforgeeks.org/svg-use-element/
Open In App

SVG <use> Element

Last Updated : 16 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

SVG stands for Scalable Vector Graphic. It can be used to make graphics and animations like in HTML canvas.

The SVG <use> element takes nodes from within the SVG document and duplicates them somewhere else.

Syntax:

<use href="" >
    Subtext
</use>

Attribute:

  • x: x-axis coordinates the positioning of the image.
  • y: y-axis coordinates the positioning of the image.
  • width: Width of the image.
  • height: Height of the image.
  • href: The source of the image.
  • Global Attributes: Some global attributes used like core attributes and styling attributes, etc.

Example 1: 

html




<!DOCTYPE html>
<html>
 
<body>
    <svg width="400" height="200"
        xmlns="http://www.w3.org/2000/svg">      
        <circle id="gfg"
                cx="100"
                cy="100"
                r="40"
                fill="green"/>
         
        <use href="#gfg" x="110"></use>
    </svg>
</body>
 
</html>


Output:

 

Example 2: 

html




<!DOCTYPE html>
<html>
 
<body>
    <svg width="400" height="200"
        xmlns="http://www.w3.org/2000/svg"> 
        <a href="https://ide.geeksforgeeks.org"
           id="gfg">     
            <text x="50"
                  y="90"
                  text-anchor="middle">
                Click Here
            </text>
        </a>
        <use href="#gfg"
             y="110"></use>
    </svg>
</body>
 
</html>


Output:

Supported Browsers:

  • Chrome 22 and above
  • Edge 12 and above
  • Firefox 4 and above
  • Safari 3 and above
  • Internet Explorer
  • Opera 11.5 and above


Previous Article
Next Article

Similar Reads

SVG &lt;svg&gt; Element
SVG stands for Scalable Vector Graphic. It can be used to make graphics and animations like in HTML canvas. SVG graphics are supported by the &lt;svg&gt; element in HTML. SVG graphics feature a container in which we can create a variety of shapes such as boxes, pathways, text, graphic images, and circles. Syntax: &lt;svg width="x" height="y"&gt; sh
2 min read
How to use drop-shadow on SVG element using CSS3 ?
SVG is used for creating images that can be scaled without losing resolution. CSS3 offers to style and animate SVG graphics. We can apply drop shadow using the 'filter' property. The 'filter' property allows us to apply visual effects to SVG elements. To add a drop shadow to an SVG, we can use the 'drop-shadow()' function. The 'drop-shadow()' funct
2 min read
How to use SVG with :before or :after pseudo element ?
Using SVG with :before or :after pseudo-elements in CSS allows for the dynamic insertion of vector graphics into HTML elements. This technique enhances design flexibility by leveraging SVG's scalability and interactivity while maintaining a clean HTML structure and reducing HTTP requests for image assets.: Table of Content Using the background-imag
3 min read
How to use SVG Patterns as the background ?
The SVG Pattern element in HTML is used for drawing the different graphical designs or patterns. The patterns represent a graphical object which is used to redraw the same object repeatedly at x and y co-ordinate intervals to cover an area. Advantages of using SVG Patterns as background: It is easy to implement in code and easy to maintain.They are
3 min read
How to use z-index in svg elements ?
The z-index only works on the complete content. This is because the HTML rendered controls the positioning before handing off to the SVG rendered to place the internal SVG contents. So, basically there is no z-index for SVG, it uses the painters model. Painter's model: According to this model, paint is applied in successive operations onto some are
3 min read
Should I use &lt;img&gt;, &lt;object&gt;, or &lt;embed&gt; for SVG files ?
In this article, we will see how to use the &lt;img&gt;, &lt;object&gt;, or &lt;embed&gt; tags with SVG files, along with understanding the basic syntax for implementing it. Prerequisites: Introduction to HTML All three tags &lt;img&gt;,&lt;object&gt;, and &lt;embed&gt; are basically used to display SVG(Scaler Vector Graphics) files on a webpage, a
3 min read
How to Use CSS and SVG Clipping and Masking Techniques?
In web development, visual design is crucial in grabbing users' attention and improving their experience. CSS and SVG (Scalable Vector Graphics) provide many ways to change and improve how things look on websites. Among these methods, clipping and masking are standout tools for creating detailed designs and effects. These are the following approach
3 min read
How to use SVG Images in CSS & HTML?
SVG, or Scalable Vector Graphics, is a unique image format for vector-based graphics. Reasons to use SVG images include maintaining quality when zoomed, easy editing, accessibility, small file size, scalability, and searchability. There are several ways to use SVG images in CSS and HTML. Table of Content Using SVG as an Using SVG as a CSS backgroun
2 min read
SVG &lt;linearGradient&gt; Element
SVG &lt;linearGradient&gt; Element allows the developer to define linear gradients to apply SVG elements. It allows a smooth transition from one color to another. This is the most reliable technique. Linear gradients can be defined as vertical, angular gradients or horizontal: Vertical gradients are created when x1 and x2 are equal and y1 and y2 di
3 min read
SVG pattern Element
SVG (Scalable Vector Graphic) pattern is an element which defines the pattern in graphics using HTML. To work with create SVG pattern you have to define a &lt;pattern&gt; inside in an SVG after that, you can define the shapes inside of that &lt;pattern&gt;. Now have to define shapes area by specifying its color, borders, etc. Syntax of Declaration:
3 min read
three90RightbarBannerImg