ποΈ 21062025 1644
What is SVG?β
- SVG (Scalable Vector Graphics) is a markup language for describing 2D vector images.
- Syntax is similar to HTML.
- All SVGs start with a root
<svg>element.
SVG Shapesβ
| element | description |
|---|---|
<rect> | rectangles |
<circle> | circles |
<polygon> | custom shapes |
<line> | lines |
<text> | text |
- Controlled via attributes like:
x,y,width,height,r,cx,cy,pointsfillandstrokefor color and borders
Styling SVGsβ
- SVG elements can be styled with CSS.
- CSS properties like
fill,stroke, andstroke-widthare supported. - Enables animations and transitions.
- Some CSS features donβt work with SVG and vice versa.
Layout Differencesβ
- SVGs do not have an automatic layout engine like HTML.
- Elements stack on top of each other unless explicitly positioned.
- Use attributes like
x,y, ortransformto control placement.
Embedding SVGsβ
Inlineβ
- SVG code is written directly into HTML.
- Allows full styling and JavaScript interaction.
- Increases DOM size.
Externalβ
- SVG is referenced as an image using
<img>orbackground-image. - Reduces DOM size and allows caching.
- Limited in styling and animation control.
- External SVGs must include
xmlns