From the course: Learning SVG
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Reuse SVG symbols with <symbol> and <use> - SVG Tutorial
From the course: Learning SVG
Reuse SVG symbols with <symbol> and <use>
- [Instructor] One of the advantages to using inline SVGs is we can reuse the graphic elements of the SVG as many times as we want in a document without having to copy and paste the entire SVG code. We simply turn the graphic elements of the SVG into symbols, and then reference those symbols anytime we want to use them. Define the SVG once, then use its symbols in different variants in different places as many times as you like. Let's say, for example, I want to display a smaller version of just this symbol in this graphic without the blue border next to the figure, and I want it to be green. To do this, I first have to convert the elements that make up this icon here into a symbol, and then call it in using the use element. In the markup, I've already grouped together the elements that make up the symbol, it's sitting inside this g element with a class icon, so now I can wrap the g element in a symbol element. We'll use the id of the symbol element to reference it later when we want…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Add SVG to a web document3m 54s
-
(Locked)
Define the display size of an SVG3m 8s
-
(Locked)
Understand the viewBox5m 20s
-
(Locked)
SVG shape elements4m 52s
-
(Locked)
Group SVG shapes with <g>2m 54s
-
(Locked)
Reuse SVG symbols with <symbol> and <use>5m 31s
-
(Locked)
Size used SVG symbols6m 14s
-
(Locked)
Apply CSS to individual symbol instances4m 25s
-
-
-
-
-