theme | class | highlighter | lineNumbers | info | drawings | download | layout | title | |
---|---|---|---|---|---|---|---|---|---|
./theme |
text-center |
prism |
true |
## Slides for Intro to SVG L&L
|
|
true |
intro |
Intro to SVG |
Let's start
layout: presenter presenterImage: 'https://pbs.twimg.com/profile_images/1441783883456942080/vV37mSqv_400x400.jpg'
- 💻 Grad Software Developer at Thoughtworks
- ✏ Writes about Web Dev, UI, Dev growth
- 🎨 Experienced in creating mockups & graphics
- What is SVG?
- Why do we use SVG?
- How do we get SVG?
- How to use SVG?
Story Time!
---
File Extension | Description |
---|---|
.gif |
Graphics Interchange Format |
.png |
Portable Network Graphic |
.jpg / .jpeg |
Image format by Joint Photographic Experts Group |
.webp |
A superior image format of .png & .jpg |
.svg |
Scalable Vector Graphics |
File Extension | Color Modes | Compression | Usage |
---|---|---|---|
.gif |
Indexed Color | Lossless | Animated images |
.png |
Greyscale, True Color, Alpha | Lossless (better than .GIF) | Static Line art, iconic graphics where transparency matters. |
.jpg / .jpeg |
True Color | Lossy | Photographs, realistic images of people, venues etc. |
.webp |
Depends on compression | Lossless / Lossy | A superior image format of .png & .jpg |
.svg |
Anything that can be specified using CSS color syntax. | NA | UI that requires to be redrawn accurately at different sizes |
- Create SVG from scratch
- Generate SVG
- Extract from websites
<rectangle />
<circle />
<polygon />
Code Time!
<svg>
<rect width="100%" height="100%" fill="white" />
<circle cx="50%" cy="50%" r=60 fill="#BC002D" />
</svg>
<svg>
<rect width="100%" height="20%" y="0" fill="red" />
<rect width="100%" height="20%" y="20%" fill="white" />
<rect width="100%" height="20%" y="40%" fill="blue" />
<rect width="100%" height="20%" y="60%" fill="white" />
<rect width="100%" height="20%" y="80%" fill="red" />
</svg>
<svg>
<defs>
<polygon id="star" fill="yellow"
points="100,10 40,198 190,78 10,78 160,198" />
</defs>
<rect width="100%" height="100%" fill="red" />
<svg viewBox="100 0 600 600" x="25%" y="25%">
<use href="#star">
</use>
</svg>
</svg>
<polygon points="100,10 40,198 190,78 10,78 160,198" fill='#abcbca' stroke='#123123' stroke-width='5' />
<polyline points="100,10 40,198 190,78 10,78 160,198" fill='#abcbca' stroke='#123123' stroke-width='5' />
<svg>
<rect width="100%" height="50%" fill="red" />
<rect width="100%" height="50%" y="50%" fill="white" />
<circle cx='15%' cy='25%' r='30' fill='white' />
<circle cx='20%' cy='25%' r='30' fill='red' />
<svg viewBox="600 -100 1000 1800">
<use href="#white-star" />
<use href="#white-star" x="-20%" y="10%" />
<use href="#white-star" x="20%" y="10%" />
<use href="#white-star" x="-12.5%" y="22%" />
<use href="#white-star" x="12.5%" y="22%" />
</svg>
</svg>
Ellipse, Polygon, Paths, Bezier Curves
<img src="/svg/animals/Rabbit.svg"
class="special-image" />
.special-image {
height:240px;
animation:spin 4s linear infinite;
}
@keyframes spin {
100% {
transform:rotate(360deg);
}
}
1. Squicley for generating Squircles
![](/lyqht/intro-to-svg-slides/raw/main/squircley-demo.png)
2. SVGBackgrounds.com for generating backgrounds
![](/lyqht/intro-to-svg-slides/raw/main/SVGBackgrounds-demo.png)
Demo with Hacktoberfest's SVG
P.S. If you use any extracted images for your own websites or apps, please remember to give attribution.
- What is SVG?
- Why do we use SVG?
- How do we get SVG?
- How to use SVG?
Shape | Usage Example | |
---|---|---|
1. | Square | <rect width="40" height="40" /> |
2. | Rectangle | <rect width="80" height="40" /> |
3. | Circle | <circle cx="50%" cy="50%" r="60" /> |
4. | Ellipse | <ellipse cx="100" cy="50" rx="80" ry="40" /> |
5. | Polygon | <polygon points="100,10 40,198 190,78 10,78 160,198" /> |
6. | Polyline | <polyline points="100,10 40,198 190,78 10,78 160,198" /> |
- More complex SVG elements such as patterns, filters, paths
- Accessibility of SVGs
- Performance of SVGs
- MDN Web Docs on SVG
- CSS Tricks - how to scale SVG
- Smashing Magazine - SVG Generators
- Frontend Masters - SVG Essentials & Animations v2
Hope you enjoyed the L&L 😄
Any questions?
--