HTML (HyperText Markup Language) is the standard markup language for creating web pages and web applications. It is used to structure and present content on the World Wide Web. SVG (Scalable Vector Graphics) is a language for describing two-dimensional graphics and graphical applications in XML. It is used to create and display vector graphics on the web, and it is supported by all modern web browsers. The combination of HTML and SVG can be used to create complex graphics and animations on the web.
In this tutorial, we will learn how to set color with SVG in HTML. Color is an important part of any design, and is one of the most powerful tools in a designer’s toolbox. We will use the SVG
Creating a Simple Rectangle with SVG
The The fill attribute is used to set the color of the interior of the rectangle. It takes a color value as its value. The color can be specified as a named color, an RGB value, or a hex value. The following code sets the fill attribute to red:
The fill attribute can also be used to set the opacity of the fill color. This is done by using the rgba() function. This function takes four parameters: the red, green, and blue values, and the opacity. The following code sets the fill color to red with an opacity of 0.5:
The stroke attribute is used to set the color of the border of the rectangle. It takes a color value as its value. The color can be specified as a named color, an RGB value, or a hex value. The following code sets the stroke attribute to blue:
The stroke attribute can also be used to set the width of the border. This is done by using the stroke-width attribute. The following code sets the width of the border to 5 pixels:
In addition to setting a solid color, the fill attribute can also be used to set a gradient fill. The The gradient is then set as the value of the fill attribute:
In this tutorial, we have learned how to set color with SVG in HTML. We have used the fill and stroke attributes to set the fill and stroke color, respectively. We have also seen how to create a linear gradient with the Setting Color with the fill Attribute
Setting Color with the Stroke Attribute
Creating a Gradient Fill with SVG
Conclusion