SVG, the "Scalable Vector graphics" Scalable vector graphic, based on Extensible Markup Language, is used to describe a graphic format for two-dimensional vector graphics.
SVG is purely XML and can be inserted into HTML using the following methods:
- Using
<iframe> elements to embed SVG images
- Using
elements to embed SVG images
- Embed an SVG image as a background image
- Using
<svg> elements directly
- Using
<embed> elements to embed SVG images
- Using
<object> elements to embed SVG images
Suppose you have an SVG file, named Test.svg, as shown below.
<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE svg public '-//w3c//dtd svg 1.1//en ' http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd '><svgwidth= "$"Height= "$"xmlns= "Http://www.w3.org/2000/svg">//Here xmlns is necessary<rectwidth= "100%"Height= "100%"style= "Fill:cornflowerblue" /></svg>
The xmlns declaration space for SVG must be specified, otherwise it will not be parsed as an SVG tag.
Write an HTML file that reads as follows
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>Document</title></Head><Body> <imgsrc= "Test.svg"></Body></HTML>
The results are as follows
You can also use SVG tags directly in the HTML5 document, as shown below
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>Document</title></Head><Body> <svgwidth= "$"Height= "$"> <CircleCX= "+"Cy= "+"R= " the"style= "Fill:url (#orange_red)" /> <defs> <lineargradientID= "Orange_red"X1= "0%"Y1= "0%"X2= "100%"y2= "0%"> <StopOffset= "20%"style= "Stop-color:rgb (255,255,0); Stop-opacity:1 "/> <StopOffset= "80%"style= "Stop-color:rgb (255,0,0); Stop-opacity:1 "/> </lineargradient> </defs> </svg></Body></HTML>
The performance is shown below
Notes:svg (1)