SVG Introduction
SVG, Scalable Vector Graphics, is an XML markup language for describing two-dimensional graphics.
Unlike bitmap images, SVG images are stored as text and can be scaled to any size without distortion, because they are based on mathematical descriptions rather than pixels.
Basic knowledge you should have before learning:
Before continuing, you should have a basic understanding of the following:
- HTML
- XML Basics
If you want to learn these first, please visit theHomeand select the corresponding tutorial.
What is SVG?
- SVG stands for Scalable Vector Graphics
- SVG is used to define vector-based graphics for the web
- SVG uses the XML format to define graphics
- SVG images do not lose graphic quality when enlarged or resized
- SVG is a World Wide Web Consortium standard
- SVG is an integral part of W3C standards such as DOM and XSL
SVG is a W3C Recommendation
SVG became a W3C Recommendation on January 14, 2003.
For more information about W3C's SVG activities, please visit our W3C Tutorial.
History and Advantages of SVG
** SVG History:**
SVG was initiated by the W3C SVG Working Group established in 1998, emerging from six standards proposals submitted to W3C that year:
- On September 4, 2001, SVG 1.0 was released.
- On January 4, 2003, SVG 1.1 was released.
- On January 14, 2003, mobile SVG sub-versions were launched: SVG Tiny and SVG Basic.
- On December 22, 2008, SVG Tiny 1.2 was released.
- On August 16, 2011, SVG 1.1 (2nd Edition) was released, becoming the current W3C recommended standard.
- W3C is still working on SVG 2; the latest draft can be seen atClick here to view .
** SVG Advantages:**
-
Scalability: SVG images can be scaled to any size without loss or distortion. This is because SVG is based on vector descriptions rather than pixel images, so it stays sharp on screens of different resolutions and sizes.
-
Text-based nature: SVG files are XML-based text files, easy to edit and maintain. You can directly edit an SVG file to adjust the graphics, or use a text editor or code editor to create and modify SVG images.
-
Interactivity: SVG allows adding interactive elements such as links, animations, and event handlers. This lets SVG images interact with users, creating a richer user experience.
-
Animation support: SVG supports creating animations with CSS and JavaScript, making graphics more lively. You can use CSS animations or JavaScript to achieve dynamic effects such as transitions, rotation, and scaling.
-
Embeddability: SVG images can be embedded directly into HTML documents, or linked to HTML documents as external files. This allows SVG images to integrate seamlessly with other web technologies such as CSS and JavaScript.
View SVG File
SVG is widely supported in modern web browsers, including Chrome, Firefox, Safari, and more.
SVG images can be embedded into HTML documents via inline SVG code or external SVG files.
-
Google Chrome: Google Chrome is a popular modern web browser with good support for the SVG format, and offers rich developer tools.
-
Mozilla Firefox: Mozilla Firefox is also a widely used web browser that supports the display and rendering of SVG images and most SVG features.
-
Apple Safari: Safari is a web browser developed by Apple with good support for SVG, for Mac, iOS, and other devices.
-
Microsoft Edge: Microsoft Edge is a web browser launched by Microsoft that supports the SVG format and is continuously improving its SVG support.
-
Opera: Opera is a fast and secure web browser with good support for SVG and many modern web technologies.
-
Brave: Brave is a privacy-focused web browser built on Chromium, so it also supports SVG images.
-
Vivaldi: Vivaldi is a highly customizable web browser, also built on Chromium, and supports the SVG format.
Create an SVG file
The following are the basic steps to create an SVG file:
-
Open a text editor: Use your favorite text editor, such as Visual Studio Code, see the VScode Tutorial.
-
Write SVG code: Write SVG code in the text editor. SVG code consists of XML tags describing graphic elements, attributes, and styles.
-
Save file: Save the written SVG code as a file ending with the
.svgextension, such asexample.svg. -
Preview the SVG file: Open the SVG file in a web browser, or embed the SVG file into an HTML document, and preview the SVG image in the browser.
The following is a simple SVG file example, creating an SVG image containing one circle:
This code describes an SVG canvas with a width of 200 units and a height of 200 units. A circle is drawn on the canvas with center coordinates at (100, 100), a radius of 80 units, and a blue fill color.