VOOZH about

URL: https://www.geeksforgeeks.org/html/how-to-use-svg-images-in-css-html/

⇱ How to use SVG Images in HTML? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to use SVG Images in HTML?

Last Updated : 23 Jul, 2025

SVG images are special graphics used in HTML that doesn’t lose quality when resized. They are great for icons, logos, and shapes because they stay clear at any size. To use SVG images in HTML, add them with <img src=" image.svg"> or paste SVG code directly with <SVG>.

1. Using SVG Image with <img> Tag

The <img> tag is used to include SVG images in your HTML, just like any other image format. You specify the image file using the src attribute. If you don’t set a specific size, the SVG will appear at its original size. To change the size, you can use the width and height attributes or style it with CSS.

Output

👁 Output
Svg Images

2. Using SVG Image with CSS background-image Property

To use an SVG image as a background in CSS, you can set the image URL in a class using background-image. The .mySVG class in the example below adds the SVG as a background, makes sure it doesn’t repeat, and sets the height to 200px.

Output

👁 Output

3. How to use an SVG as an <object>

The <object> tag allows you to embed an external SVG file directly into your webpage. This method displays the SVG inline, and you can manipulate it with CSS or JavaScript.

Output

👁 svgobj
Using SVG as an object
Comment
Article Tags:
Article Tags: