search
HomeWeb Front-endH5 TutorialXiaoqiang's road to HTML5 mobile development (17) – HTML5 inline SVG

1. What is SVG

Scalable vector graphics is a graphics format based on Extensible Markup Language (a subset of Standard Universal Markup Language) that is used to describe two-dimensional vector graphics. It became a W3C Recommendation on January 14, 2003 by the World Wide Web Consortium SVG.

SVG stands for Scalable Vector Graphics

SVG is used to define vector-based graphics for the web

SVG uses XML format to define graphics

SVG images will not lose their graphic quality when enlarged or changed in size

SVG is a standard of the World Wide Web Consortium

SVG is consistent with W3C standards such as DOM and XSL A whole

2. Advantages of SVG

In January 2003, SVG 1.1 was established as a W3C standard.

The organizations involved in defining SVG include: Sun Microsystems, Adobe, Apple, IBM and Kodak.

Compared with other image formats, the advantage of using SVG is:

SVG can be read and modified by many tools (such as Notepad)

SVG and JPEG Compared with GIF images, they are smaller in size and more compressible.

SVG is scalable

SVG images can be printed with high quality at any resolution

SVG can be enlarged without losing image quality

Text in SVG images is optional and searchable (great for making maps)

SVG can run with Java technology

SVG is an open standard

SVG files are pure XML

The main competitor for SVG is Flash.

Compared with Flash, the biggest advantage of SVG is that it is compatible with other standards (such as XSL and DOM). Flash is a proprietary technology that is not open source.

3. Browser support

Internet Explorer 9, Firefox, Opera, Chrome and Safari support inline SVG.

4. Embedding SVG in HTML pages

In HTML5, you can embed SVG elements directly into HTML pages:

<!DOCTYPE html>  
<html>  
    <body>  
  
        <svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="190">  
            <polygon points="100,10 40,180 190,60 10,60 160,180"  
                style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;" />  
        </svg>  
  
    </body>  
</html>

Xiaoqiangs road to HTML5 mobile development (17) – HTML5 inline SVG

5. Simple and practical methods of SVG

SVG has some predefined shape elements that can be used and manipulated by developers:

  • Rectangle

  • Circle

  • ##Ellipse

  • Line

  • Polyline

  • ##Polygon
  • Path
  • Let’s look at an example of a rectangle
<!DOCTYPE html>  
<html>  
    <body>  
  
        <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="100%">  
            <rect x="20" y="20" width="250" height="250"  
                style="fill:blue;stroke:pink;stroke-width:5;  
                fill-opacity:0.1;stroke-opacity:0.9"/>  
        </svg>  
  
    </body>  
</html>

    x attribute defines a rectangle The left position of the rectangle (for example, x="0" defines the distance of the rectangle to the left side of the browser window is 0px)
  • y attribute defines the top position of the rectangle (for example, y=" 0" defines the distance from the rectangle to the top of the browser window as 0px)
  • The fill-opacity attribute of CSS defines the fill color transparency (the legal range is: 0 - 1)
  • The stroke-opacity property of CSS defines the transparency of the stroke color (the legal range is: 0 - 1)

Xiaoqiangs road to HTML5 mobile development (17) – HTML5 inline SVG What we used above is the tag, which can be used to create graphics with no less than three sides.

<!DOCTYPE html>  
<html>  
    <body>  
  
        <svg width="100%" height="100%" version="1.1"  
            xmlns="http://www.w3.org/2000/svg">  
  
            <polygon points="220,100 300,210 170,250"  
                style="fill:#cccccc;  
                stroke:#000000;stroke-width:1"/>  
  
        </svg>  
    </body>  
</html>

The coordinates of the three points are defined above, and then the color and fill of the line are defined. Method

Xiaoqiangs road to HTML5 mobile development (17) – HTML5 inline SVG6. SVG example demonstration


##Source code: Xiaoqiangs road to HTML5 mobile development (17) – HTML5 inline SVG

<!DOCTYPE html>  
<html>  
    <body>  
    <svg width="100%" height="100%" version="1.1"  
    xmlns="http://www.w3.org/2000/svg">  
  
        <rect id="rec" x="300" y="100" width="300" height="100" style="fill:lime">   
        <animate attributeName="x" attributeType="XML" begin="0s" dur="6s" fill="freeze" from="300" to="0"/>   
        <animate attributeName="y" attributeType="XML" begin="0s" dur="6s" fill="freeze" from="100" to="0"/>   
        <animate attributeName="width" attributeType="XML" begin="0s" dur="6s" fill="freeze" from="300" to="800"/>   
        <animate attributeName="height" attributeType="XML" begin="0s" dur="6s" fill="freeze" from="100" to="300"/>   
        <animateColor attributeName="fill" attributeType="CSS" from="lime" to="red" begin="2s" dur="4s" fill="freeze"/>  
        </rect>  
  
        <g transform="translate(100,100)">   
        <text id="TextElement" x="0" y="0" style="font-family:Verdana;font-size:24; visibility:hidden"> It&#39;s SVG!  
        <set attributeName="visibility" attributeType="CSS" to="visible" begin="1s" dur="5s" fill="freeze"/>  
        <animateMotion path="M 0 0 L 100 100" begin="1s" dur="5s" fill="freeze"/>  
        <animateColor attributeName="fill" attributeType="CSS" from="red" to="blue" begin="1s" dur="5s" fill="freeze"/>   
        <animateTransform attributeName="transform" attributeType="XML" type="rotate" from="-30" to="0" begin="1s" dur="5s" fill="freeze"/>   
        <animateTransform attributeName="transform" attributeType="XML" type="scale" from="1" to="3" additive="sum" begin="1s" dur="5s" fill="freeze"/>   
        </text>   
        </g>  
  
    </svg>  
  
    </body>  
</html>

The above is the content of Xiaoqiang’s HTML5 mobile development road (17) - HTML5 inline SVG. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!
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
H5 vs. Older HTML Versions: A ComparisonH5 vs. Older HTML Versions: A ComparisonMay 06, 2025 am 12:09 AM

The main differences between HTML5 (H5) and older versions of HTML include: 1) H5 introduces semantic tags, 2) supports multimedia content, and 3) provides offline storage functions. H5 enhances the functionality and expressiveness of web pages through new tags and APIs, such as and tags, improving user experience and SEO effects, but need to pay attention to compatibility issues.

H5 vs. HTML5: Clarifying the Terminology and RelationshipH5 vs. HTML5: Clarifying the Terminology and RelationshipMay 05, 2025 am 12:02 AM

The difference between H5 and HTML5 is: 1) HTML5 is a web page standard that defines structure and content; 2) H5 is a mobile web application based on HTML5, suitable for rapid development and marketing.

HTML5 Features: The Core of H5HTML5 Features: The Core of H5May 04, 2025 am 12:05 AM

The core features of HTML5 include semantic tags, multimedia support, form enhancement, offline storage and local storage. 1. Semantic tags such as, improve code readability and SEO effect. 2. Multimedia support simplifies the process of embedding media content through and tags. 3. Form Enhancement introduces new input types and verification properties, simplifying form development. 4. Offline storage and local storage improve web page performance and user experience through ApplicationCache and localStorage.

H5: Exploring the Latest Version of HTMLH5: Exploring the Latest Version of HTMLMay 03, 2025 am 12:14 AM

HTML5isamajorrevisionoftheHTMLstandardthatrevolutionizeswebdevelopmentbyintroducingnewsemanticelementsandcapabilities.1)ItenhancescodereadabilityandSEOwithelementslike,,,and.2)HTML5enablesricher,interactiveexperienceswithoutplugins,allowingdirectembe

Beyond Basics: Advanced Techniques in H5 CodeBeyond Basics: Advanced Techniques in H5 CodeMay 02, 2025 am 12:03 AM

Advanced tips for H5 include: 1. Use complex graphics to draw, 2. Use WebWorkers to improve performance, 3. Enhance user experience through WebStorage, 4. Implement responsive design, 5. Use WebRTC to achieve real-time communication, 6. Perform performance optimization and best practices. These tips help developers build more dynamic, interactive and efficient web applications.

H5: The Future of Web Content and DesignH5: The Future of Web Content and DesignMay 01, 2025 am 12:12 AM

H5 (HTML5) will improve web content and design through new elements and APIs. 1) H5 enhances semantic tagging and multimedia support. 2) It introduces Canvas and SVG, enriching web design. 3) H5 works by extending HTML functionality through new tags and APIs. 4) Basic usage includes creating graphics using it, and advanced usage involves WebStorageAPI. 5) Developers need to pay attention to browser compatibility and performance optimization.

H5: New Features and Capabilities for Web DevelopmentH5: New Features and Capabilities for Web DevelopmentApr 29, 2025 am 12:07 AM

H5 brings a number of new functions and capabilities, greatly improving the interactivity and development efficiency of web pages. 1. Semantic tags such as enhance SEO. 2. Multimedia support simplifies audio and video playback through and tags. 3. Canvas drawing provides dynamic graphics drawing tools. 4. Local storage simplifies data storage through localStorage and sessionStorage. 5. The geolocation API facilitates the development of location-based services.

H5: Key Improvements in HTML5H5: Key Improvements in HTML5Apr 28, 2025 am 12:26 AM

HTML5 brings five key improvements: 1. Semantic tags improve code clarity and SEO effects; 2. Multimedia support simplifies video and audio embedding; 3. Form enhancement simplifies verification; 4. Offline and local storage improves user experience; 5. Canvas and graphics functions enhance the visualization of web pages.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools