- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <svg> Tag
In order to contain SVG graphics, we use the <svg> tag. A modular language called HTML SVG is used to describe visuals in XML. It describes mixed vector and two-dimensional vector graphics in XML. The W3C has recommended it.
XML text files are used to define SVG images and their behaviors. An SVG image can therefore be created and edited as XML files, but generally speaking, drawing program like inkspace are preferred to generate it. SVG is mostly used for vector diagrams, such as pie charts and 2-D graphs with an X, Y coordinate system etc.
Syntax
Following is the syntax of the <svg> tag −
<svg> ...... </svg>
Specific Attributes
The HTML <svg> tag also supports the following additional attributes −
S.No. | Attribute & Description |
---|---|
1 | baseProfile This section outlines the minimum SVG language profile that the author thinks is required to render the content correctly.Not supported after SVG2. |
2 | contentScriptType Names the standard scripting language for the specified document fragment. |
3 | contentStyleType Specifies the SVGfragment's default style sheet language. |
4 | height Indicates the vertical length of rect. |
5 | preserveAspectRatio Specifies the required deformation of the SVG fragment when it is inserted into a container with a different aspect ratio. |
6 | version specifies the SVG version that was used to create the element's inner content. |
7 | viewbox For the current SVG fragment, defines the bounds of the SVG viewport. |
8 | width indicates the width of the rect. |
9 | x determines the svg container's x coordinate. The outermost SVG elements are unaffected. |
10 | y determines the svg container's y coordinate. The outermost SVG elements are unaffected. |
Example
Let’s look at the following example, where we are going to draw a rectangle using the <svg> tag.
<!DOCTYPE html> <html> <body> <svg width="250" height="150"> <rect width="200" height="100" style="fill:#DE3163; stroke-width:8;stroke:#D5F5E3" /> </svg> </body> </html>
On running the above code, it will generate an output consisting of a rectangle drawn on the webpage.
Example
Considering another scenario where we are going to draw a square with round corners.
<!DOCTYPE html> <html> <body> <svg width="400" height="400"> <rect x="25" y="25" rx="20" ry="20" width="200" height="200" style="fill:#58D68D;stroke:#7D3C98;stroke-width:3;opacity:0.5" /> </svg> </body> </html>
When we execute the above code, the output window will pop up, displaying the square drawn with round corners displayed on the webpage.
Example
Following is the example, where we are going to draw the SVG logo.
<!DOCTYPE html> <html> <body> <svg height="200" width="600"> <defs> <linearGradient id="tutorial" x1="1%" y1="1%" x2="50%" y2="1%"> <stop offset="0%" style="stop-color:white; stop-opacity: 1" /> <stop offset="100%" style="stop-color: #52BE80; stop-opacity: 1" /> </linearGradient> </defs> <ellipse cx="210" cy="100" rx="120" ry="81" fill="url(#tutorial)" /> <text fill="#17202A" font-size="20" font-family="verdana" x="121" y="111"> TUTORIALSPOINT </text> </svg> </body> </html>
On running the above code, it will generate an output consisting of the SVG logo displayed on the webpage.
To Continue Learning Please Login
Login with Google