Home  >  Article  >  Web Front-end  >  How to use SVG in HTML5

How to use SVG in HTML5

青灯夜游
青灯夜游Original
2018-11-30 14:18:499025browse

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>

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="漂亮的绿色圆圈" />

Rendering:

How to use SVG in HTML5

##Use the tag to import SVG images
<object type="image/svg+xml" data="image.svg"></object>
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>

Using the tag to import SVG images

<embed type="image/svg+xml" src="image.svg" />
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

Use CSS background image to import SVG image

We can use css background attribute to import SVG image as background image

This is equivalent to using the How to use SVG in HTML5 tag, and has the same advantages and disadvantages.

#id {
  background-image: url(image.svg)  no-repeat;
}

Rendering:

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study. How to use SVG in HTML5

The above is the detailed content of How to use SVG in HTML5. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is SVGNext article:What is SVG