liveBook · Manning

SVG

As explained in Tiny CSS Projects

SVG is an XML-based standard for describing two-dimensional vector graphics.

SVG (Scalable Vector Graphics) is an XML-based way to describe shapes on a coordinate plane. A shape’s coordinates determine where it appears; the plane’s origin is (0, 0). You can write SVG directly or export it from a graphics program and edit the resulting file. section 3.2

Unlike PNG, JPEG, and GIF images, which use grids of pixels, SVG shapes can grow or shrink without becoming pixelated. Raster images remain a better practical choice for complex images such as photos. section 3.2

To build a row of bars for a responsive loading graphic:

  • Place an <svg> element in the HTML and give it a viewBox so its contents resize with the available space. section 3.2.4
  • Add <rect> elements with width, height, x, and y attributes. The x and y values position each rectangle’s top-left corner within the SVG. section 3.2.4
  • Space eleven 60-unit-wide bars by increasing x by 65 each time, leaving a 5-unit gap. section 3.2.4
Listing 3.4 Eleven rectangles
<svg viewBox="0 0 710 300" width="100%" height="300">
        <rect width="60" height="300" x="0" />
        <rect width="60" height="300" x="65" />
        <rect width="60" height="300" x="130" />
        <rect width="60" height="300" x="195"/>
        <rect width="60" height="300" x="260"/>
        <rect width="60" height="300" x="325"/>
        <rect width="60" height="300" x="390"/>
        <rect width="60" height="300" x="455"/>
        <rect width="60" height="300" x="520"/>
        <rect width="60" height="300" x="585"/>
        <rect width="60" height="300" x="650"/>
    </svg>

The complete markup shows the viewBox and all eleven rectangle positions together. section 3.2.4

Inline SVG also lets page CSS target individual shapes—for example, applying a different fill color to each bar. An SVG loaded through <img> or CSS background-image can be sized from the page, but its individual shapes cannot be restyled there; their styles must live inside the SVG. Keep explanatory text alongside a loading graphic so assistive technologies can communicate what is happening. section 3.3 section 3.0

How Tiny CSS Projects covers it

How deep it goes
Explains vector coordinates, basic shapes, responsive rectangle placement, and styling access; leaves irregular paths unused.
Examples
Shows eleven spaced rectangles in a responsive loader and CSS fill colors applied to individual bars.
What it assumes
Introduces SVG markup and coordinates from basic definitions while using HTML and CSS to place and style the graphic.
What you can do after
Build it from scratch: position SVG rectangles in a responsive loader and style their fills with CSS.
How it connects
Connects SVG to raster images, HTML, CSS, viewBox, and accessibility for loading indicators.

Also explained in

Compare how 2 books explain SVG →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny CSS Projects. The section links point to the parts of the book it draws on.