DEV Community

SVG essentials. Introduction

SVG stands for Scalable Vector Graphics, an XML-based markup language that defines images using mathematical formulas rather than pixels. This makes SVG ideal for icons, logos, and line drawings as they can be resized without loss of quality and have smaller file sizes. SVG images can be targeted with CSS to change their presentation, such as color and animation. There are several ways to display an SVG image on a webpage, including directly embedding it, using the img element, object element, or iframe element. Each method has its own advantages and limitations, such as caching and JavaScript manipulation. SVG code follows XML language rules, including case-sensitivity, closing tags, and attribute values in quotation marks. The SVG image structure includes the root element, viewBox, and defs element, which defines styles or elements that will be referenced later. The viewBox defines a drawing region in abstract units, while width and height can be set inside the svg tag. The defs element can contain style elements, shapes, gradients, and symbols, and can be referenced later in the code. Finally, actual drawing elements such as path, circle, rect, line, ellipse, and polygon are used to create the image.
favicon
dev.to
dev.to
Create attached notes ...