The Wayback Machine - https://web.archive.org/web/20240624194400/https://www.geeksforgeeks.org/svg-fill-attribute/
Open In App

SVG fill Attribute

Last Updated : 31 Mar, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The fill attribute can be used in two things. For shapes and text, it’s a presentation attribute that defines the color used to paint the element. For animation it defines the final state of the animation.

Syntax:

fill= "colour"

Attribute Values:

  • paint: The color in which we want to paint the element.

We will use the fill attribute for setting the color of the element.

Example 1: In this example, we will use the fill attribute for setting the color of rect element.




<!DOCTYPE html>
<html>
  
<body>
    <svg viewBox="0 0 700 350" 
        xmlns="http://www.w3.org/2000/svg">
          
        <rect height="70" width="60" 
                fill="green" />
    </svg>
</body>
  
</html>


Output:

Example 2: In this example, we will use the fill attribute for setting the color of circle element.




<html>
  
<body>
    <svg viewBox="0 0 700 350" 
        xmlns="http://www.w3.org/2000/svg">
          
        <circle cx="50" cy="50" 
            r="40" fill="green" />
    </svg>
</body>
  
</html>


Output:



Previous Article
Next Article

Similar Reads

SVG fill-opacity Attribute
The fill-opacity attribute is a presentation attribute defining the opacity of the paint applied to a shape. Syntax: fill-opacity="colour" Attribute Values: decimal: Decimal value at which we want to make our element opaque.percentage: Percentage at which we want to set the fill-opacity attribute. We will use the fill-opacity attribute for setting
1 min read
How to resize SVG to fill its container in ReactJS?
We can resize SVG to fill its container in ReactJS using the type props. We can add the following style to the SVG CSS Syntax: svg { width: inherit; height: inherit; } React Syntax: &lt;svg style = {{ width: "inherit", height:"inherit"}} // Child elements &lt;/svg&gt;Creating React Application: Step 1: Create a React application using the following
2 min read
How to Modify the Fill Color of an SVG Image when being Served as Background Image ?
In this article, we will see how to modify the fill color of an SVG image when being served as a background image. SVGs also known as scalable vector images, While being served as a background image we can change their background color easily. It has a number of approaches like using HTML only or using CSS or JavaScript. For starters let's look at
5 min read
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
SVG from Attribute
The from attribute indicates the initial value of an attribute, it is used with to attribute. Syntax: from="number" Attribute Values: number: number at which we want to set from attributeWe will use the from attribute for setting the initial value. Example 1: C/C++ Code &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;svg viewBox=&quot;0 0 1000
1 min read
SVG viewBox Attribute
The viewBox is an attribute of the SVG element in HTML. It is used to scale the SVG element that means we can set the coordinates as well as width and height. Syntax: viewBox = "min-x min-y width height" Attribute Values: min-x: It is used to set the horizontal axis. It is used to make the SVG move on a horizontal axis (i.e Left and Right).min-y: I
4 min read
SVG y Attribute
The y attribute defines the y-axis coordinate in the user coordinate system. Syntax: y = "y-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 y attribute for setting the y coordinate for the elements. Example 1: Group of rectangle elements with
1 min read
SVG x Attribute
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-
1 min read
SVG rx Attribute
The rx attribute defines a radius on the x-axis. Elements that are using this attribute: &lt;ellipse&gt; &lt;rect&gt; Syntax: rx = "x-radius" Attribute Values: length: Length at which we want to set the x-radius.percentage: Percentage at which we want to set the x-radius.We will use the rx attribute for setting the radius on the x-axis. Example 1:
1 min read
SVG width Attribute
The width attribute defines the vertical length of an element. Syntax: width= "width" Attribute Values: length: Length at which we want to set the width attribute. percentage: Percentage at which we want to set the width attribute. We will use the width attribute for setting the width of the element. Example 1: In this example we will use the width
1 min read
three90RightbarBannerImg