Open In App

How to set the SVG background color ?

There are two types of images that can be used in the background and in both cases you can change the background color of the image.

The SVG stands for Scalable Vector Graphics. The SVG background is used to draw any kind of shape, set any color you want by the set property. The below examples illustrates the concept of SVG set background-color more specifically. The SVG allowed the CSS background sizing, position, and much more complex property.



Example: The cx and cy attributes define the x and y coordinates of the center of the circle. If cx and cy are omitted, then it sets the center of the circle to (0, 0). The r attribute defines the radius of the circle. To set the background color to this SVG, there are two ways.




<!DOCTYPE html>
<html>
  
<head>
    <title>
        SVG set Background Color
    </title>
</head>
  
<body>
    <center>
        <h1 style="color:green;">GeeksforGeeks</h1>
        <h4>SVG set Background Color</h4>
  
        <svg height="100" width="100">
            <circle cx="50" cy="50" r="40" stroke="black" 
                    stroke-width="3" fill="red" />
        </svg>
    </center>
</body>
  
</html>


Output:


To set the background color of the SVG body, background can be done in two ways:

HTML is the foundation of webpages, is used for webpage development by structuring websites and web apps.You can learn HTML from the ground up by following this HTML Tutorial and HTML Examples.


Article Tags :