What is SVG?
- SVG stands for Scalable Vector Graphics. Unlike raster images like PNGs or JPGs, SVGs are not pixel-based.
- They're composed of vectors—mathematical formulas that describe shapes, paths, and fills. This means SVGs can be resized without losing quality.
Why Use SVG?
Scalability
- SVG images can be scaled indefinitely without losing quality, which is ideal for responsive web design.
File Size
- SVG files are often smaller than their raster counterparts, especially for simple shapes and icons.
Flexibility
- SVGs can be styled, animated, and manipulated using CSS and JavaScript.
How to Embed SVG in HTML
- Inline SVG: Directly writing the SVG XML code within HTML.
- Using a <img> tag: Point the src attribute to an SVG file.
- Using CSS: Setting SVG as a background image in a CSS file.
Inline SVG Example
<img> Tag Example
CSS Background Example
SVG Attributes
- width and height: To set the dimensions.
- viewBox: To set the coordinate system.
- fill and stroke: To set the colors.
Examples
0 Comments:
Post a Comment
Do leave your comments