Home > Web Front-end > H5 Tutorial > body text

How to use SVG in HTML5

青灯夜游
Release: 2018-12-04 10:49:14
Original
9026 people have browsed it

In HTML5 we can use the tag to inline SVG, use HTML's How to use SVG in HTML5 tag, tag, tag,

How to use SVG in HTML5

SVG is a vector graphics format that can be redrawn to adapt to the size of the Web page as it changes in size without any distortion; very Suitable for use in responsive web design. This article will give you a detailed introduction to how to use SVG in HTML5. I hope it will be helpful to you. [Recommended related video tutorials: HTML5 tutorial]

Using HTML5 tags to inline SVG

##SVG Part of the HTML 5 draft specification, the tag is part of the HTML 5 language and can be inline. All major browser brands (except IE9) now offer very good support.

Note:

1. To use the tag to inline SVG, you must not forget to declare: xmlns=" within the tag element. http://www.w3.org/2000/svg".

2. This can only be used for static SVG import.

The following is a simple HTML5 SVG example.

<svg  id = "circle"  height = "200"  xmlns = "http://www.w3.org/2000/svg" > 
      <circle  id = "greencircle"  cx = "30"  cy = "30"  r = " 30"  fill = "red"  /> 
</svg>
Copy after login

Rendering:

How to use SVG in HTML5

Use the How to use SVG in HTML5 tag to import SVG images

Note: The How to use SVG in HTML5 tag can only be used to import static SVG images.

<img  src = "green-circle.svg"  height = "80"  alt="漂亮的绿色圆圈" />
Copy after login

Rendering:

How to use SVG in HTML5

##Use the tag to import SVG images
<object type="image/svg+xml" data="image.svg"></object>
Copy after login
Technically, the tag can be used on many elements, including SVG files, and if there are elements that are not recognized as images, they will not be available in image searches. The workaround is to use the How to use SVG in HTML5 tag as a fallback:

<object type="image/svg+xml" data="image.svg">
    <img  src="image.svg" / alt="How to use SVG in HTML5" >
</object>
Copy after login

Using the tag to import SVG images

<embed type="image/svg+xml" src="image.svg" />
Copy after login
Not recommended SVG images are imported using the tag, which is not part of the HTML specification but is widely supported on all browsers primarily used to implement Flash plug-ins.

Using the