<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mariana Beldi</title>
    <description>The latest articles on DEV Community by Mariana Beldi (@marianabeldi).</description>
    <link>https://dev.to/marianabeldi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F286744%2F098927c1-533d-47bb-a31c-cfc36382bac1.jpg</url>
      <title>DEV Community: Mariana Beldi</title>
      <link>https://dev.to/marianabeldi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/marianabeldi"/>
    <language>en</language>
    <item>
      <title>Building an SVG virtual stand</title>
      <dc:creator>Mariana Beldi</dc:creator>
      <pubDate>Sun, 06 Feb 2022 21:32:56 +0000</pubDate>
      <link>https://dev.to/marianabeldi/building-an-svg-virtual-stand-3jj6</link>
      <guid>https://dev.to/marianabeldi/building-an-svg-virtual-stand-3jj6</guid>
      <description>&lt;h2&gt;
  
  
  A responsive illustrated website with CSS Grid.
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://nerdear.la/"&gt;Nerdearla&lt;/a&gt; is an annual conference with talks and workshops about technology and science here in Buenos Aires.&lt;/p&gt;

&lt;p&gt;As sponsors of the event with &lt;a href="https://www.leniolabs.com/"&gt;Leniolabs&lt;/a&gt;, we used to have a stand where people could come by and say hi, play games with us, talk about technologies we love, and get some of our &lt;a href="https://www.behance.net/gallery/90294769/Leniolabs_-merchandising"&gt;alien merch&lt;/a&gt;. &lt;strong&gt;It was the perfect excuse to get to know each other in this community&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mS5Dr6NW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ljebrhb9fbtcrkfn8sf8.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mS5Dr6NW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ljebrhb9fbtcrkfn8sf8.jpg" alt="Leniolabs’ merchandising in events" width="880" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then the pandemic changed everything. And the event as we knew it was not possible anymore. They resolved to make this last edition online, so &lt;strong&gt;we decided to build a site to still be able to interact with people&lt;/strong&gt; and play the games we’ve been developing. We didn’t know what to expect. Trying to keep closer in the distance was a challenge for us. But at the same time, there was a bigger audience to connect to, as many speakers and attendees could be present from any part of the world.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We first attempted to create an interactive city&lt;/strong&gt; to chat in bars or share articles in the library, talk in the theatres, or play games in the park. But all those places seemed far away from our reality at that moment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8fE2jTO9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/98ihy9n7tzsg71pi3nnr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8fE2jTO9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/98ihy9n7tzsg71pi3nnr.jpg" alt="First idea. Leniolabs city." width="880" height="638"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then the popular &lt;em&gt;#stayathome&lt;/em&gt; hashtag hit us: &lt;strong&gt;why not illustrate our own house at Leniolabs?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Each room would refer to one area of the company&lt;/strong&gt;; we had our videos of workshops and talks in the garage, our blog posts in the home library, the live chat in the living room, the games in the garden, the trivia challenges in the loft, our lab in the basement, the Bootcamp we were cooking at the kitchen, and the job section in the office room. And everyone was invited; we wanted to share what happens inside Leniolabs, our internal workshops, and articles we write to share our knowledge.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vsepGL3O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dl5bto0cjsnrihtm7av1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vsepGL3O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dl5bto0cjsnrihtm7av1.jpg" alt="Leniolabs’ house website design." width="880" height="1557"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Coding the design and making it responsive
&lt;/h2&gt;

&lt;p&gt;There was a challenge to make this website mobile-friendly as the whole site was a big illustration. After playing around with different approaches, we decided to use &lt;a href="https://grid.layoutit.com/"&gt;Layoutit&lt;/a&gt; to build a CSS Grid. We exported every room as a single SVG and made every SVG a component. Then &lt;strong&gt;we created a grid where every grid item was one of these components&lt;/strong&gt;. We changed the layout and the position of the grid areas depending on the screen size, going from 4 column layout on large screens to a single column on mobile.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kgtRZSAd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4m9uiwdcir3x89xgnjd5.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kgtRZSAd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4m9uiwdcir3x89xgnjd5.gif" alt="CSS grid and SVG components." width="880" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The technology used
&lt;/h2&gt;

&lt;p&gt;We chose &lt;a href="https://nuxtjs.org/"&gt;Nuxt&lt;/a&gt; as we needed a site that would last 5 days but with one month to build it from scratch. No time was lost in router configuration, auto imported components, and a nice folder structure in a pre-rendered site. And we chose &lt;a href="https://www.netlify.com/"&gt;Netlify&lt;/a&gt; as we needed to iterate and share the results often. A free, serverless platform to push and deploy.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS animations
&lt;/h2&gt;

&lt;p&gt;We used some small animations on hover to make the house a little bit more alive—all with preferred reduce-motion for accessibility.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KgpTcWiK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7yfte06wy63iyc6xttrn.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KgpTcWiK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7yfte06wy63iyc6xttrn.gif" alt="Image description" width="679" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Night mode and easter eggs
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;After a certain hour, the house switches off&lt;/strong&gt;, some of the lights are out, and others are on. The sleeping cat is now catching a spider; Leni (our alien mascot) falls asleep outside the house. &lt;strong&gt;We love the idea that the more you visit the site, the more details you’ll find hidden&lt;/strong&gt;. Every SVG is a reusable component that appears on each internal page and changes as the dark mode turns on.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0oIDyjJJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tbtizhei2efhavjhb99g.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0oIDyjJJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tbtizhei2efhavjhb99g.gif" alt="Day mode — Night mode." width="724" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fnOf4U_P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6bcmxikj2no2r5j69vn2.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fnOf4U_P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6bcmxikj2no2r5j69vn2.gif" alt="Day mode — Night mode." width="880" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HGD5PTzu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gz69d4z813s60f15rpcn.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HGD5PTzu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gz69d4z813s60f15rpcn.gif" alt="Day mode — Night mode." width="730" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Between 4 pm and 7 am, this function adds a class to the container of the site to activate the dark mode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;{ night: isDark }&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/template&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;isDark&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
 &lt;span class="na"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;updateTime&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hours&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;getHours&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isDark&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;hours&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;hours&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
 &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ended up being our official event site for Nerdearla, as they will continue doing it online and we are part of the 2021 edition from 20 to 23rd of October. We will be hosting games and sending gifts to everyone who will join us this year! But even if you don’t join the conference &lt;strong&gt;you can still visit our virtual stand at &lt;a href="https://nerdearla.leniolabs.com/"&gt;https://nerdearla.leniolabs.com&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;More details about the making of the site are in this talk (Spanish version):&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/fUTEryzf6ag"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>svg</category>
      <category>css</category>
      <category>vue</category>
      <category>grid</category>
    </item>
    <item>
      <title>Going beyond automatic SVG compression with the “use” element</title>
      <dc:creator>Mariana Beldi</dc:creator>
      <pubDate>Thu, 07 May 2020 12:52:58 +0000</pubDate>
      <link>https://dev.to/marianabeldi/going-beyond-automatic-svg-compression-with-the-use-element-7l8</link>
      <guid>https://dev.to/marianabeldi/going-beyond-automatic-svg-compression-with-the-use-element-7l8</guid>
      <description>&lt;p&gt;If you draw your own SVG files or if you download them from the internet, tools like this  &lt;a href="https://petercollingridge.appspot.com/svg-editor"&gt;SVG-Editor&lt;/a&gt;  or  &lt;a href="https://jakearchibald.github.io/svgomg/"&gt;SVGOMG&lt;/a&gt;  are your friends. Compressing the files with those tools takes only a few seconds and reduces your file size a lot. But if you need to use your SVG inline to animate or interact with the code, there’s still a lot you can do about  &lt;em&gt;code legibility&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Reusing content with SVG’s  &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt;  is not always an option, but when it is, you won’t regret taking a few extra minutes to put it in practice.&lt;/p&gt;

&lt;p&gt;In this article, I’ll show an example where I was able to take a lot of advantage of this element — not only for keeping the file size down but also a clearer markup that became more legible and easy to maintain.&lt;/p&gt;

&lt;p&gt;This is the first design that I needed to work with. It was originally created in Illustrator:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QlUXMlFj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/2864/1%2AWacIur-WLoP7M4lFn2nTQA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QlUXMlFj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/2864/1%2AWacIur-WLoP7M4lFn2nTQA.png" alt="Org chart with astronaut images" width="880" height="728"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Take a look at the following code, this is the original file exported directly from the software, weighs  &lt;strong&gt;2.05kb:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marianab/embed/RwwmmLd?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;It’s not a heavy file at all. However, open it and you’ll find there are lots of empty tags, deprecated namespaces, unnecessary white space, commas and extra information  &lt;a href="https://css-tricks.com/one-illustration-three-svg-outputs/"&gt;applied by the software&lt;/a&gt;. This makes the code hard to work with, annoying to scan and creates a big scroll for those hundreds of lines in your document.&lt;/p&gt;

&lt;p&gt;You’ll also notice that the file is indeed using  &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt;  and  &lt;code&gt;&amp;lt;defs&amp;gt;&lt;/code&gt;  elements, but not in the best way it could. And that’s not the software’s fault! Each astronaut illustration in the original file has a clipping mask: an invisible circle that acts like a window through which we can see our character. Without it, the suit of the astronaut would be flooding outside the circle. There are a few ways to avoid this in Illustrator, like cropping those extra parts with a pathfinder option. That way we would gain a few bytes and avoid using an extra circle only for clipping information of the graphic that we won’t show.  &lt;strong&gt;The compression of the file starts in the software.&lt;/strong&gt;  Still, there are a lot of things we’ll be able to improve on the code in case we don’t want to edit the original file.&lt;/p&gt;




&lt;p&gt;Compressing the SVG with SVGOMG and keeping the default options won’t take any effort and you’ll get a file that weighs  &lt;strong&gt;1.46kb&lt;/strong&gt;. That is a reduction of 30% compared to the original size and the graphic will look exactly the same.&lt;/p&gt;




&lt;h2&gt;
  
  
  Reusing content
&lt;/h2&gt;

&lt;p&gt;This will require going through the SVG and making some adjustments. I know this option takes more time regarding the previous example, but it’s not as hard as it seems.&lt;/p&gt;

&lt;p&gt;We have one repeated element, which is the astronaut inside the circle. That’s the one we’ll compress on SVGOMG. The result will look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;"http://www.w3.org/2000/svg"&lt;/span&gt; &lt;span class="na"&gt;xmlns:xlink=&lt;/span&gt;&lt;span class="s"&gt;"http://www.w3.org/1999/xlink"&lt;/span&gt; &lt;span class="na"&gt;viewBox=&lt;/span&gt;&lt;span class="s"&gt;"0 0 95.8 95.8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;.st3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="nc"&gt;.st4&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="py"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;#ffcb2f&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="py"&gt;stroke&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;#12192c&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="py"&gt;stroke-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;1.4891&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="py"&gt;stroke-miterlimit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="nc"&gt;.st4&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="py"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;#69b2b1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;   
&lt;span class="nt"&gt;&amp;lt;circle&lt;/span&gt; &lt;span class="na"&gt;cx=&lt;/span&gt;&lt;span class="s"&gt;"47.9"&lt;/span&gt; &lt;span class="na"&gt;cy=&lt;/span&gt;&lt;span class="s"&gt;"47.9"&lt;/span&gt; &lt;span class="na"&gt;r=&lt;/span&gt;&lt;span class="s"&gt;"47.9"&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"#12192c"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;      
&lt;span class="nt"&gt;&amp;lt;circle&lt;/span&gt; &lt;span class="na"&gt;cx=&lt;/span&gt;&lt;span class="s"&gt;"47.9"&lt;/span&gt; &lt;span class="na"&gt;cy=&lt;/span&gt;&lt;span class="s"&gt;"47.9"&lt;/span&gt; &lt;span class="na"&gt;r=&lt;/span&gt;&lt;span class="s"&gt;"40.7"&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"#f6a2a4"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;      
&lt;span class="nt"&gt;&amp;lt;defs&amp;gt;&amp;lt;circle&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"SVGID_1_"&lt;/span&gt; &lt;span class="na"&gt;cx=&lt;/span&gt;&lt;span class="s"&gt;"47.9"&lt;/span&gt; &lt;span class="na"&gt;cy=&lt;/span&gt;&lt;span class="s"&gt;"47.9"&lt;/span&gt; &lt;span class="na"&gt;r=&lt;/span&gt;&lt;span class="s"&gt;"40.7"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&amp;lt;/defs&amp;gt;&lt;/span&gt;    &lt;span class="nt"&gt;&amp;lt;clipPath&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"SVGID_2_"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;use&lt;/span&gt; &lt;span class="na"&gt;xlink:href=&lt;/span&gt;&lt;span class="s"&gt;"#SVGID_1_"&lt;/span&gt; &lt;span class="na"&gt;overflow=&lt;/span&gt;&lt;span class="s"&gt;"visible"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&amp;lt;/clipPath&amp;gt;&lt;/span&gt;   
&lt;span class="nt"&gt;&amp;lt;g&lt;/span&gt; &lt;span class="na"&gt;clip-path=&lt;/span&gt;&lt;span class="s"&gt;"url(#SVGID_2_)"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;        
&lt;span class="nt"&gt;&amp;lt;path&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"st3"&lt;/span&gt; &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"M63.9 45.6H32c-4 0-7.2 1.9-7.3 4.3l-.8 26.6H72l-.8-26.6c-.2-2.5-3.4-4.3-7.3-4.3z"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;        
&lt;span class="nt"&gt;&amp;lt;path&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"st4"&lt;/span&gt; &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"M74.3 86.9L66 88.2C53.8 90 41.4 90 29.1 88.1l-7.7-1.2v-14c0-4 3.2-7.2 7.2-7.2h38.5c4 0 7.2 3.2 7.2 7.2v14z"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;      &lt;span class="nt"&gt;&amp;lt;path&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"st3"&lt;/span&gt; &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"M31.8 47.3h-.6c-.7 0-1.2-.6-1.2-1.2V23.2c0-.7.6-1.2 1.2-1.2h.6c.7 0 1.2.6 1.2 1.2v22.9c0 .7-.6 1.2-1.2 1.2z"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;        
&lt;span class="nt"&gt;&amp;lt;circle&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"st4"&lt;/span&gt; &lt;span class="na"&gt;cx=&lt;/span&gt;&lt;span class="s"&gt;"31.5"&lt;/span&gt; &lt;span class="na"&gt;cy=&lt;/span&gt;&lt;span class="s"&gt;"20.7"&lt;/span&gt; &lt;span class="na"&gt;r=&lt;/span&gt;&lt;span class="s"&gt;"2.8"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;        
&lt;span class="nt"&gt;&amp;lt;circle&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"st4"&lt;/span&gt; &lt;span class="na"&gt;cx=&lt;/span&gt;&lt;span class="s"&gt;"47.9"&lt;/span&gt; &lt;span class="na"&gt;cy=&lt;/span&gt;&lt;span class="s"&gt;"51.4"&lt;/span&gt; &lt;span class="na"&gt;r=&lt;/span&gt;&lt;span class="s"&gt;"20.3"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;        
&lt;span class="nt"&gt;&amp;lt;path&lt;/span&gt; &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"M64.5 53.1c0 8-7.4 11.2-16.5 11.2S31.4 61 31.4 53.1s7.4-14.4 16.5-14.4 16.6 6.4 16.6 14.4z"&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"#13192d"&lt;/span&gt; &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"#12192c"&lt;/span&gt; &lt;span class="na"&gt;stroke-width=&lt;/span&gt;&lt;span class="s"&gt;"1.489"&lt;/span&gt; &lt;span class="na"&gt;stroke-miterlimit=&lt;/span&gt;&lt;span class="s"&gt;"10"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;        
&lt;span class="nt"&gt;&amp;lt;path&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"none"&lt;/span&gt; &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"#12192c"&lt;/span&gt; &lt;span class="na"&gt;stroke-width=&lt;/span&gt;&lt;span class="s"&gt;"1.489"&lt;/span&gt; &lt;span class="na"&gt;stroke-linecap=&lt;/span&gt;&lt;span class="s"&gt;"round"&lt;/span&gt; &lt;span class="na"&gt;stroke-linejoin=&lt;/span&gt;&lt;span class="s"&gt;"round"&lt;/span&gt; &lt;span class="na"&gt;stroke-miterlimit=&lt;/span&gt;&lt;span class="s"&gt;"10"&lt;/span&gt; &lt;span class="na"&gt;stroke-dasharray=&lt;/span&gt;&lt;span class="s"&gt;"9.6793,3.7228"&lt;/span&gt; &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"M65.9 88V76.9"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;        
&lt;span class="nt"&gt;&amp;lt;path&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"none"&lt;/span&gt; &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"#12192c"&lt;/span&gt; &lt;span class="na"&gt;stroke-width=&lt;/span&gt;&lt;span class="s"&gt;"1.489"&lt;/span&gt; &lt;span class="na"&gt;stroke-linecap=&lt;/span&gt;&lt;span class="s"&gt;"round"&lt;/span&gt; &lt;span class="na"&gt;stroke-linejoin=&lt;/span&gt;&lt;span class="s"&gt;"round"&lt;/span&gt; &lt;span class="na"&gt;stroke-miterlimit=&lt;/span&gt;&lt;span class="s"&gt;"10"&lt;/span&gt; &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"M29.6 87.9v-11"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;  
&lt;span class="nt"&gt;&amp;lt;/g&amp;gt;&lt;/span&gt;  
&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;First recommendations:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Move the  &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt;  content to the CSS file (assuming you can use your SVG inline and that you have a stylesheet linked in your document).&lt;/li&gt;
&lt;li&gt; Rename the IDs with something that makes sense to you.&lt;/li&gt;
&lt;li&gt; Round those complicated numbers, like  &lt;code&gt;stroke-width="1.489"&lt;/code&gt;  to  &lt;code&gt;stroke-width="1.5"&lt;/code&gt;. This is something that could happen if you resize your vectors in Illustrator with the option of scaling borders checked.&lt;/li&gt;
&lt;li&gt; Remove the  &lt;code&gt;stroke-miterlimit="10"&lt;/code&gt;  as we don’t need it since our  &lt;code&gt;stroke-linejoin&lt;/code&gt;  is round.&lt;/li&gt;
&lt;li&gt; This code will be our astronaut template. We need to wrap everything in a group, add an ID to that group and place it inside a  &lt;code&gt;&amp;lt;defs&amp;gt;&lt;/code&gt;  tag. Notice that we already have a  &lt;code&gt;&amp;lt;defs&amp;gt;&lt;/code&gt;  element with a circle inside it. We can remove that one as it will be part of a bigger  &lt;code&gt;&amp;lt;defs&amp;gt;&lt;/code&gt;  tag.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Notice that the first two circles are filled shapes with different radius and color. We can keep the smaller one and add a stroke big enough to achieve the same effect — again, something that we could avoid using a circle with border in Illustrator in the first place.&lt;/p&gt;

&lt;p&gt;Another important thing is that our current viewBox is too small for what we want to build. Let’s make it bigger and add some negative space on the x-axis so we can start cloning our astronaut from the middle.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To learn more about viewBox, check out  &lt;a href="https://wattenberger.com/guide/scaling-svg"&gt;this beautiful guide&lt;/a&gt;  to scaling SVG by Amelia Wattenberger.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We will end with something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;"http://www.w3.org/2000/svg"&lt;/span&gt; &lt;span class="na"&gt;xmlns:xlink=&lt;/span&gt;&lt;span class="s"&gt;"http://www.w3.org/1999/xlink"&lt;/span&gt; &lt;span class="na"&gt;viewBox=&lt;/span&gt;&lt;span class="s"&gt;"-400 0 1000 5000"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;    
&lt;span class="nt"&gt;&amp;lt;defs&amp;gt;&lt;/span&gt;  
&lt;span class="nt"&gt;&amp;lt;g&lt;/span&gt; &lt;span class="na"&gt;**id=&lt;/span&gt;&lt;span class="s"&gt;"astronaut"&lt;/span&gt;&lt;span class="na"&gt;**&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;      
&lt;span class="nt"&gt;&amp;lt;circle&lt;/span&gt; &lt;span class="na"&gt;cx=&lt;/span&gt;&lt;span class="s"&gt;"94.5"&lt;/span&gt; &lt;span class="na"&gt;cy=&lt;/span&gt;&lt;span class="s"&gt;"48"&lt;/span&gt; &lt;span class="na"&gt;r=&lt;/span&gt;&lt;span class="s"&gt;"44"&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"currentColor"&lt;/span&gt; &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"#12192c"&lt;/span&gt; &lt;span class="na"&gt;stroke-width=&lt;/span&gt;&lt;span class="s"&gt;"8"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&amp;lt;clipPath&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"a"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;circle&lt;/span&gt; &lt;span class="na"&gt;cx=&lt;/span&gt;&lt;span class="s"&gt;"94.5"&lt;/span&gt; &lt;span class="na"&gt;cy=&lt;/span&gt;&lt;span class="s"&gt;"47.9"&lt;/span&gt; &lt;span class="na"&gt;r=&lt;/span&gt;&lt;span class="s"&gt;"40"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&amp;lt;/clipPath&amp;gt;&lt;/span&gt;      
&lt;span class="nt"&gt;&amp;lt;g&lt;/span&gt; &lt;span class="na"&gt;clip-path=&lt;/span&gt;&lt;span class="s"&gt;"url(#a)"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;path&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"st3"&lt;/span&gt; &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"M110.5 45.6H78.6c-4 0-7.2 1.9-7.3 4.3l-.8 26.6h48.1l-.8-26.6c-.1-2.5-3.4-4.3-7.3-4.3z"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&amp;lt;path&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"st4"&lt;/span&gt; &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"M121 86.9l-8.3 1.3C100.4 90 88 90 75.8 88.1l-7.7-1.2v-14c0-4 3.2-7.2 7.2-7.2h38.5c4 0 7.2 3.2 7.2 7.2v14z"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&amp;lt;path&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"st3"&lt;/span&gt; &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"M78.4 47.3h-.6c-.7 0-1.2-.6-1.2-1.2V23.2c0-.7.6-1.2 1.2-1.2h.6c.7 0 1.2.6 1.2 1.2v22.9c0 .7-.5 1.2-1.2 1.2z"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&amp;lt;circle&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"st4"&lt;/span&gt; &lt;span class="na"&gt;cx=&lt;/span&gt;&lt;span class="s"&gt;"78.1"&lt;/span&gt; &lt;span class="na"&gt;cy=&lt;/span&gt;&lt;span class="s"&gt;"20.7"&lt;/span&gt; &lt;span class="na"&gt;r=&lt;/span&gt;&lt;span class="s"&gt;"2.8"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&amp;lt;circle&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"st4"&lt;/span&gt; &lt;span class="na"&gt;cx=&lt;/span&gt;&lt;span class="s"&gt;"94.5"&lt;/span&gt; &lt;span class="na"&gt;cy=&lt;/span&gt;&lt;span class="s"&gt;"51.4"&lt;/span&gt; &lt;span class="na"&gt;r=&lt;/span&gt;&lt;span class="s"&gt;"20.3"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&amp;lt;path&lt;/span&gt; &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"M111.1 53.1c0 8-7.4 11.2-16.5 11.2S78 61 78 53.1s7.4-14.4 16.5-14.4 16.6 6.4 16.6 14.4z"&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"#13192d"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;path&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"none"&lt;/span&gt; &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"#12192c"&lt;/span&gt; &lt;span class="na"&gt;stroke-width=&lt;/span&gt;&lt;span class="s"&gt;"1.5"&lt;/span&gt; &lt;span class="na"&gt;stroke-linecap=&lt;/span&gt;&lt;span class="s"&gt;"round"&lt;/span&gt; &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"M112.5 88V76.9"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&amp;lt;path&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"none"&lt;/span&gt; &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"#12192c"&lt;/span&gt; &lt;span class="na"&gt;stroke-width=&lt;/span&gt;&lt;span class="s"&gt;"1.5"&lt;/span&gt; &lt;span class="na"&gt;stroke-linecap=&lt;/span&gt;&lt;span class="s"&gt;"round"&lt;/span&gt; &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"M76.3 87.9v-11"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&amp;lt;/g&amp;gt;&lt;/span&gt;  
&lt;span class="nt"&gt;&amp;lt;g&amp;gt;&lt;/span&gt;  
&lt;span class="nt"&gt;&amp;lt;/defs&amp;gt;&lt;/span&gt;   
&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What goes inside the  &lt;code&gt;&amp;lt;defs&amp;gt;&lt;/code&gt;  won’t render anywhere. To start cloning our astronaut, we need to link its ID inside a  &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt;  element like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;use&lt;/span&gt; &lt;span class="na"&gt;xlink:href=&lt;/span&gt;&lt;span class="s"&gt;"**#astronaut**"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;_xlink:href_&lt;/code&gt;  is deprecated since SVG2, but is better to use it for compatibility purposes. You can use href in modern browsers, but I tested it on Safari and it wasn’t working as of this writing. If you usexlink:href,make sure you include this namespace in your SVG tag:  &lt;code&gt;_xmlns:xlink="http://www.w3.org/1999/xlink_&lt;/code&gt;  (you won’t need it if you decide to use  &lt;code&gt;_href_&lt;/code&gt;).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now we can add the corresponding text to this first figure and align it with the transform attribute. We better place both elements inside a group so in the future instances we’ll be able to translate the whole group to the position we want:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;g&lt;/span&gt; &lt;span class="na"&gt;transform=&lt;/span&gt;&lt;span class="s"&gt;"translate(-95 210)"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;     
 &lt;span class="nt"&gt;&amp;lt;use&lt;/span&gt; &lt;span class="na"&gt;xlink:href=&lt;/span&gt;&lt;span class="s"&gt;"#astronaut"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;     
 &lt;span class="nt"&gt;&amp;lt;text&lt;/span&gt; &lt;span class="na"&gt;transform=&lt;/span&gt;&lt;span class="s"&gt;"translate(25 130)"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Tech Leader&lt;span class="nt"&gt;&amp;lt;/text&amp;gt;&lt;/span&gt;   
&lt;span class="nt"&gt;&amp;lt;/g&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The connecting lines are simple shapes that can be drawn directly with  &lt;code&gt;&amp;lt;path&amp;gt;&lt;/code&gt;. Paths look scary but, for rect lines, there is not much to worry about. I’ll explain this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;path&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"line"&lt;/span&gt; &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"M-4 200v-25h200"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;d=""&lt;/code&gt;  is for data and that’s where we’ll place our commands.  &lt;code&gt;M&lt;/code&gt;  is to move our hand to the place where we’ll start drawing (but it’s not drawing anything).  &lt;code&gt;-4 200&lt;/code&gt;  means we place our pencil four units to the left and 200 to the bottom of our viewBox (following the orientation of the SVG coordinate system).  &lt;code&gt;v&lt;/code&gt;  is the command to start drawing a vertical line that will go from this place to -25 units up.  &lt;code&gt;h&lt;/code&gt;  is for horizontal, so we’re drawing a line from there to 200 to the right. It feels like logo writer.&lt;/p&gt;

&lt;p&gt;I separated the lines in three paths, but we can use just one with the  &lt;code&gt;M&lt;/code&gt;  value after a series of commands to move our hand and start drawing from a new point in the coordinate system.&lt;/p&gt;

&lt;p&gt;Take a look at the final document. Now the file weighs  &lt;strong&gt;779 bytes&lt;/strong&gt; and has  &lt;strong&gt;12 lines&lt;/strong&gt;  of legible and scalable code:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marianab/embed/gOOJJVp?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If we declare any value in the attributes we defined in the  &lt;code&gt;_&amp;lt;defs&amp;gt;_&lt;/code&gt;  then it won’t be possible to change it in their clones because of the nature of the  &lt;code&gt;_&amp;lt;use&amp;gt;_&lt;/code&gt;  element. That’s why in the example above the fill of the main circle was replaced with a value of  &lt;code&gt;_currentColor_&lt;/code&gt;  to have control of the backgrounds of all the replications.  &lt;code&gt;_currentColor_&lt;/code&gt;  will inherit the CSS color value of the element (or any element above it). In the SVG, I’m adding a class to some replicated astronauts and adding a color value in CSS to those classes. This way, I’ll be able to change all instances of the  &lt;code&gt;_&amp;lt;use&amp;gt;_&lt;/code&gt;  element with that class. To understand more about  &lt;code&gt;_&amp;lt;use&amp;gt;_&lt;/code&gt;  and how to style its content,  &lt;a href="https://tympanus.net/codrops/2015/07/16/styling-svg-use-content-css/"&gt;this post&lt;/a&gt;  by  &lt;a href="https://www.sarasoueidan.com/"&gt;Sara Soueidan&lt;/a&gt;  has everything you need to know.&lt;/p&gt;

&lt;p&gt;With this code ready, we’ll be able to scale the graphic to something like this much more easily:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LESiCBmG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/3464/1%2AfFpVAKzXlmk8gIecfNKKqA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LESiCBmG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/3464/1%2AfFpVAKzXlmk8gIecfNKKqA.png" alt="Org chart with astronaut images, bigger scale" width="880" height="666"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the complete code:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marianab/embed/abbrgag?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Here are the three examples side by side to compare legibility and amount of code, we went from  &lt;strong&gt;241&lt;/strong&gt;  to  &lt;strong&gt;12&lt;/strong&gt;  neat lines:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mqiGnUwQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/3200/1%2AyaQrcoMkJESHl9vqfFHoew.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mqiGnUwQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/3200/1%2AyaQrcoMkJESHl9vqfFHoew.jpeg" alt="Comparing amount of code between the 3 examples" width="880" height="2465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From left to right: Code direct from Illustrator, code after SVGOMG, code after optimization.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This article was first published on  &lt;a href="https://css-tricks.com/going-beyond-automatic-svg-compression-with-the-use-element/"&gt;CSS-Tricks&lt;/a&gt;  with edits from  &lt;a href="https://chriscoyier.net/"&gt;Chris Coyier&lt;/a&gt;  and  &lt;a href="https://geoffgraham.me/"&gt;Geoff Graham&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>svg</category>
      <category>optimization</category>
      <category>webdev</category>
      <category>webgraphics</category>
    </item>
    <item>
      <title>Usar y reusar todo en SVG … ¡Incluso animaciones!</title>
      <dc:creator>Mariana Beldi</dc:creator>
      <pubDate>Tue, 17 Mar 2020 15:17:05 +0000</pubDate>
      <link>https://dev.to/marianabeldi/usar-y-reusar-todo-en-svg-incluso-animaciones-3c9f</link>
      <guid>https://dev.to/marianabeldi/usar-y-reusar-todo-en-svg-incluso-animaciones-3c9f</guid>
      <description>&lt;h1&gt;
  
  
  Cómo crear y optimizar SVG y animaciones CSS
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://dev.to/marianabelda/how-to-use-and-reuse-everything-in-svg-even-animations-3414"&gt;Read the English version here&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;Si estás familiarizado con SVG y animaciones CSS, o empezaste a trabajar con ellas a menudo, acá hay algunas ideas a tener en cuenta antes de comenzar a trabajar. Este artículo trata sobre cómo escribir y optimizar código con &lt;strong&gt;el elemento , las variables CSS y las animaciones CSS&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Parte 1: El elemento SVG &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Si sos un desarrollador al que le gusta mantener su código &lt;a href="https://es.wikipedia.org/wiki/No_te_repitas"&gt;DRY&lt;/a&gt; o sos de usar las variables Sass / CSS, es muy probable que te guste esta etiqueta.&lt;/p&gt;

&lt;p&gt;Digamos que tenés un elemento que se repite muchas veces en tu gráfico. En lugar de repetir una parte compleja del código varias veces en el SVG, se puede definir esta parte una vez y luego clonarla en otro lugar del documento con el elemento &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt;. Esto no solo reducirá una enorme cantidad de código, sino que también lo hará más simple y fácil de manipular.&lt;/p&gt;

&lt;p&gt;Para comenzar a implementar el elemento &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt;, abrí tu SVG y seguí estos pasos:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Identificá la parte del código que querés clonar&lt;/li&gt;
&lt;li&gt;Agregale un ID a esa parte&lt;/li&gt;
&lt;li&gt;Linkeala dentro del tag &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt; de esta forma: &lt;code&gt;&amp;lt;use xlink:href="#id"/&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Eso es todo! Tu nuevo clon está listo, ahora podés cambiarle los atributos que necesites (por ej. la posición &lt;code&gt;x&lt;/code&gt; o la posición &lt;code&gt;y&lt;/code&gt;).&lt;/p&gt;

&lt;h3&gt;
  
  
  Veamos un ejemplo muy conveniente
&lt;/h3&gt;

&lt;p&gt;Este es un caso real donde necesitaba animar un cubo grande compuesto por cubos más pequeños. Algo así como un &lt;a href="https://www.rubiks.com/en-us/"&gt;cubo Rubik&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Empecemos a dibujar un pequeño cubo en SVG usando formas básicas (SVG basic shapes, en este caso sólo &lt;code&gt;rect&lt;/code&gt;) y transformaciones (transforms):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;viewBox=&lt;/span&gt;&lt;span class="s"&gt;"-130 -20 300 100"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;   
 &lt;span class="nt"&gt;&amp;lt;g&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"cubo"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;     
  &lt;span class="nt"&gt;&amp;lt;rect&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"21"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"24"&lt;/span&gt; &lt;span class="na"&gt;transform=&lt;/span&gt;&lt;span class="s"&gt;"skewY(30)"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;     
  &lt;span class="nt"&gt;&amp;lt;rect&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"21"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"24"&lt;/span&gt; &lt;span class="na"&gt;transform=&lt;/span&gt;&lt;span class="s"&gt;"skewY(-30) translate(21 24.3)"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;     
  &lt;span class="nt"&gt;&amp;lt;rect&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"21"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"21"&lt;/span&gt;  &lt;span class="na"&gt;transform=&lt;/span&gt;&lt;span class="s"&gt;"scale(1.41,.81)   rotate(45) translate(0 -21)"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;   
 &lt;span class="nt"&gt;&amp;lt;/g&amp;gt;&lt;/span&gt; 
&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marianab/embed/XWWQbYP?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Las formas (&lt;code&gt;rects&lt;/code&gt;) están agrupadas con el elemento &lt;code&gt;&amp;lt;g&amp;gt;&lt;/code&gt; (group) para poner agregarle un ID (#cubo) a toda la figura.&lt;/p&gt;

&lt;p&gt;Ahora, hagamos un cubo más grande clonando la unidad que acabamos de crear. Primero hay que ubicar el grupo dentro del elemento &lt;code&gt;&amp;lt;defs&amp;gt;&lt;/code&gt; dentro del tag de SVG. Dentro de &lt;code&gt;&amp;lt;defs&amp;gt;&lt;/code&gt; podemos poner cualquier cosa que queramos reutilizar, puede ser una forma, un grupo, una gradiente, casi cualquier elemento de SVG. No se renderizará nada de lo que incluyamos dentro de &lt;code&gt;&amp;lt;defs&amp;gt;&lt;/code&gt;, hasta que lo usemos fuera de él.&lt;/p&gt;

&lt;p&gt;Para poder usar la figura que acabamos de definir, vamos a linkearla con su ID dentro del elemento &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt; todas las veces que lo necesitemos, cambiando su posición &lt;code&gt;x&lt;/code&gt; y su posición &lt;code&gt;y&lt;/code&gt; en cada clon de la siguiente manera:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;use&lt;/span&gt; &lt;span class="na"&gt;xlink:href=&lt;/span&gt;&lt;span class="s"&gt;"#cubo"&lt;/span&gt; &lt;span class="na"&gt;x=&lt;/span&gt;&lt;span class="s"&gt;"142"&lt;/span&gt; &lt;span class="na"&gt;y=&lt;/span&gt;&lt;span class="s"&gt;"124"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; 
&lt;span class="nt"&gt;&amp;lt;use&lt;/span&gt; &lt;span class="na"&gt;xlink:href=&lt;/span&gt;&lt;span class="s"&gt;"#cubo"&lt;/span&gt; &lt;span class="na"&gt;x=&lt;/span&gt;&lt;span class="s"&gt;"100"&lt;/span&gt; &lt;span class="na"&gt;y=&lt;/span&gt;&lt;span class="s"&gt;"124"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; 
&lt;span class="c"&gt;&amp;lt;!-- ... --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marianab/embed/wvvZXqG?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Ahora hay que ubicar cada clon del cubo pequeño, recordando que el último elemento se muestra al frente, con esto tendremos nuestro primer gran cubo listo!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;code&gt;xlink:href&lt;/code&gt; está obsoleto desde SVG2, pero es mejor usarlo por cuestiones de compatibilidad. En algunos navegadores modernos se puede simplemente usar &lt;code&gt;href&lt;/code&gt; pero al momento de escribir esta nota lo testié en Safari y no está funcionando ahí. Si usás &lt;code&gt;xlink:href&lt;/code&gt; asegurate de incluir este namespace en tu SVG tag: &lt;code&gt;xmlns:xlink='http://www.w3.org/1999/xlink'&lt;/code&gt; (no lo necesitas si decidís usar &lt;code&gt;href&lt;/code&gt;).&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Parte 2: Usando variables CSS para aplicar diferentes estilos al gráfico reutilizado
&lt;/h2&gt;

&lt;p&gt;Elegí un color principal para el cubo, con tonalidades más claras y oscuras en los lados y el borde. Pero qué pasa si quiero crear un nuevo cubo con otro color?&lt;/p&gt;

&lt;p&gt;Podemos reemplazar el color de relleno y bordes con variables CSS para hacer estos atributos más flexibles. De esta manera, podremos reutilizar la misma unidad del pequeño cubo con otra paleta, en vez de definir un segundo pequeño cubo con distintos colores.&lt;/p&gt;

&lt;p&gt;Por qué no agregar una clase al nuevo cubo y cambiar los colores con CSS? Eso haremos, pero primero, intentá inspeccionar el elemento &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt;. Vas a notar que se renderiza en el Shadow DOM. Significa que no es vulnerable a scripts o estilos, como los elementos en el DOM normal. Cualquier valor que definas en la figura dentro de &lt;code&gt;&amp;lt;defs&amp;gt;&lt;/code&gt; será heredado por todas sus instancias y no podrán reescribirse con CSS. Pero si remplazamos esos valores con variables, podremos &lt;a href="https://tympanus.net/codrops/2015/07/16/styling-svg-use-content-css/"&gt;controlarlas con CSS&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;En nuestra unidad de cubo pequeño, reemplazaremos cada valor de relleno y borde con un nombre de variable semántico.&lt;/p&gt;

&lt;p&gt;Por ejemplo esto:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;rect&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"#00affa"&lt;/span&gt; &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"#0079ad"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;… puede reemplazarse con esto:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;rect&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"var(--colorPrincipal)"&lt;/span&gt; &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"var(--colorBorde)"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A partir de acá, podemos duplicar el SVG anterior para crear un nuevo cubo grande. Sin embargo, no necesitamos duplicar el elemento &lt;code&gt;&amp;lt;defs&amp;gt;&lt;/code&gt; si vamos a tener ambos cubos en el mismo documento. Podemos agregar una clase a cada SVG y controlar la paleta de colores con CSS, defefiniendo los valores de cada variable.&lt;/p&gt;

&lt;p&gt;Creemos una paleta para el cubo azul y otra para el cubo rosa:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.cubo-azul&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;   
 &lt;span class="py"&gt;--mainColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#009CDE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
 &lt;span class="py"&gt;--strokeColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#0079ad&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
 &lt;span class="py"&gt;--lightColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#00affa&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
 &lt;span class="py"&gt;--darkColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#008bc7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;  
&lt;span class="nc"&gt;.cubo-rosa&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;   
 &lt;span class="py"&gt;--mainColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#de0063&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
 &lt;span class="py"&gt;--strokeColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#ad004e&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
 &lt;span class="py"&gt;--lightColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#fa0070&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
 &lt;span class="py"&gt;--darkColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#c7005a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marianab/embed/gOOJQmw?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;De esta manera podemos crear la cantidad de cubos que queramos y cambiar todos los colores desde un solo lugar.&lt;/p&gt;




&lt;h2&gt;
  
  
  Parte 3: Reusando animaciones
&lt;/h2&gt;

&lt;p&gt;La idea de esta parte es quebrar el cubo cuando pasamos el mouse sobre él — algo así como una vista explotada, algunas piezas se alejarán del centro cuando pasamos el cursor sobre los cubos.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marianab/embed/KKKYdxE?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Empecemos definiendo dos movimientos, uno por cada eje: &lt;code&gt;move Y&lt;/code&gt; y &lt;code&gt;move X&lt;/code&gt;. Al definir las animaciones en movimientos, podremos reutilizarlas en cada cubo. Las animaciones consistirán en mover al cubo desde su posición inicial hasta 30px o 50px de distancia en una misma dirección. Podemos usar un transform translate (&lt;code&gt;X&lt;/code&gt; o &lt;code&gt;Y&lt;/code&gt; ) para lograrlo. &lt;br&gt;
Por ejemplo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@keyframes&lt;/span&gt; &lt;span class="n"&gt;moveX&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;   
 &lt;span class="nt"&gt;to&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-35px&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pero si queremos reutilizar esta animación, es mejor remplazar el valor numérico por una variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@keyframes&lt;/span&gt; &lt;span class="n"&gt;moveX&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;   
 &lt;span class="nt"&gt;to&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--translate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;35px&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Si la variable no está definida, el valor por defecto va a ser 35px.&lt;/p&gt;

&lt;p&gt;Ahora necesitamos al menos una clase para enlazar a esta animación. En este caso serán dos clases, para mover los cubos en el eje x: &lt;code&gt;.m-izquierda&lt;/code&gt; y &lt;code&gt;.m-derecha&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.m-izquierda&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;.m-derecha&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;    
 &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2s&lt;/span&gt; &lt;span class="n"&gt;moveX&lt;/span&gt; &lt;span class="n"&gt;alternate&lt;/span&gt; &lt;span class="n"&gt;infinite&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Para que el cubo se mueva a la izquierda, necesitamos un valor negativo, pero también podemos declarar un valor numérico distinto. Podemos definir nuestra variable &lt;em&gt;dentro&lt;/em&gt; de la clase &lt;code&gt;.m-izquierda&lt;/code&gt; así:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.m-izquierda&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="py"&gt;--translate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Acá estamos declarando que, cuando agreguemos la clase &lt;code&gt;.m-izquierda&lt;/code&gt; a un elemento, se lanzará la animación &lt;code&gt;moveX&lt;/code&gt; (la que definimos en los &lt;code&gt;@keyframes&lt;/code&gt;) que tardará dos segundos en moverse en el eje x hasta alcanzar una nueva posición 50px a la izquierda (los números negativos se mueven a la izquierda). Luego, la animación alterna de dirección para empezar a moverse desde esta última posición durante dos segundos hasta alcanzar su estado inicial. Lo hará en un loop infinito, porque eso hemos declarado al poner &lt;code&gt;infinite&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Podemos declarar otra variable para la clase &lt;code&gt;.m-derecha&lt;/code&gt; pero si no lo hacemos, recordá que tomará el valor por defecto de 35px que declaramos al principio.&lt;/p&gt;

&lt;p&gt;Por defecto el valor de &lt;code&gt;animation-play-state&lt;/code&gt; es &lt;code&gt;running&lt;/code&gt; pero quizás no queremos que los cubos se muevan todo el tiempo. Sería muy molesto si usamos estas cubos en un sitio con texto cerca de ellos. Así que intentaremos hacer que la animación se ejecute sólo cuando pasamos el cursor por encima:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;svg&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="nc"&gt;.m-izquierda&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2s&lt;/span&gt; &lt;span class="n"&gt;moveX&lt;/span&gt; &lt;span class="n"&gt;alternate&lt;/span&gt; &lt;span class="n"&gt;infinite&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Podés probar este código por tu cuenta y verás que la animación salta muy rápido a su estado inicial cada vez que quitamos el cursor de encima. Para evitar esto, podemos usar el valor &lt;code&gt;paused&lt;/code&gt; al final de la propiedad animation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.m-izquierda&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;   
 &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2s&lt;/span&gt; &lt;span class="n"&gt;moveX&lt;/span&gt; &lt;span class="n"&gt;alternate&lt;/span&gt; &lt;span class="n"&gt;infinite&lt;/span&gt; &lt;span class="n"&gt;paused&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ahora la animación está pausada pero se disparará on hover agregando esta línea de CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;svg&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nl"&gt;animation-play-state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;running&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Podemos aplicar cada una de estas clases a diferentes elementos dentro del SVG. En el primer cubo estamos moviendo algunas unidades; en el segundo cubo, estamos aplicando estas clases a grupos de unidades.&lt;/p&gt;

&lt;h3&gt;
  
  
  Para terminar…
&lt;/h3&gt;

&lt;p&gt;Tardé mucho en darme cuenta que podía reutilizar un simple cubo pequeño para construir todo. Trabajé en esa unidad para hacerla isométrica y así poder alinearla fácilmente con las demás unidades. A esta altura mi unidad era un &lt;code&gt;path&lt;/code&gt;, pero decidí reemplazarlo por SVG &lt;code&gt;rect&lt;/code&gt; para reducir la cantidad de código y hacerlo más legible.&lt;/p&gt;

&lt;p&gt;Aprendí que es mejor tomarse un tiempo para analizar qué se puede hacer con SVG antes de embarcarse en la tarea. En este caso hubo que modificar el diseño original levemente, pero esa modificación permitió hacer un código más mantenible y escalable. Puede tomar más tiempo al principio pero a largo plazo ganaremos mucho más.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Este artículo fue publicado originalmente en &lt;a href="https://css-tricks.com/use-and-reuse-everything-in-svg-even-animations/"&gt;CSS-Tricks&lt;/a&gt; editado por  &lt;a href="https://chriscoyier.net/"&gt;Chris Coyier&lt;/a&gt; y &lt;a href="https://geoffgraham.me/"&gt;Geoff Graham&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>svg</category>
      <category>optimization</category>
      <category>animation</category>
      <category>css</category>
    </item>
    <item>
      <title>How to use and reuse everything in SVG… even animations</title>
      <dc:creator>Mariana Beldi</dc:creator>
      <pubDate>Tue, 17 Mar 2020 15:01:02 +0000</pubDate>
      <link>https://dev.to/marianabeldi/how-to-use-and-reuse-everything-in-svg-even-animations-3414</link>
      <guid>https://dev.to/marianabeldi/how-to-use-and-reuse-everything-in-svg-even-animations-3414</guid>
      <description>&lt;h2&gt;
  
  
  Build and optimize SVG and CSS animations.
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.to/marianabelda/usar-y-reusar-todo-en-svg-incluso-animaciones-3c9f"&gt;Link a la versión en español&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;If you are familiar with SVG and CSS animations and started to work with them often, here are some ideas you might want to keep in mind before jumping into the job. This article will be about learning how to build and optimize your code with &lt;strong&gt;the &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt; element, CSS Variables and CSS animations&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 1: The SVG  element
&lt;/h2&gt;

&lt;p&gt;If you are a developer that likes to keep your code &lt;a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself"&gt;DRY&lt;/a&gt; or a big fan of Sass/CSS variables, there is a good chance that you will like this tag.&lt;/p&gt;

&lt;p&gt;Let's say you have an element that is repeated many times in your graphic. Instead of having a complex part of your code repeated many times in your SVG, you can define this part once and then clone it somewhere else in your document with the &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt; element. This will not only reduce an enormous amount of code but also will make your markup simpler and easier to manipulate.&lt;/p&gt;

&lt;p&gt;To start implementing the &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt; element, go to your SVG and follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Identify the part of the code that you want to clone&lt;/li&gt;
&lt;li&gt;Add an ID to that part&lt;/li&gt;
&lt;li&gt;Link it inside your &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt; tag like this: &lt;code&gt;&amp;lt;use xlink:href="#id"/&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's it! Your new clone is ready, now you can change its attributes (e.g. &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; position) to fit your needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's dive into a very convenient example
&lt;/h3&gt;

&lt;p&gt;I want to share this real case where I needed to animate a big cube made of little cube units. (Imagine the classic &lt;a href="https://www.rubiks.com/en-us/"&gt;Rubik's Cube&lt;/a&gt;.)&lt;/p&gt;

&lt;p&gt;We'll start by drawing the cube unit in SVG using basic shapes and transforms:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;viewBox=&lt;/span&gt;&lt;span class="s"&gt;"-130 -20 300 100"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;   
 &lt;span class="nt"&gt;&amp;lt;g&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"cube"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;     
  &lt;span class="nt"&gt;&amp;lt;rect&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"21"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"24"&lt;/span&gt; &lt;span class="na"&gt;transform=&lt;/span&gt;&lt;span class="s"&gt;"skewY(30)"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;     
  &lt;span class="nt"&gt;&amp;lt;rect&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"21"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"24"&lt;/span&gt; &lt;span class="na"&gt;transform=&lt;/span&gt;&lt;span class="s"&gt;"skewY(-30) translate(21 24.3)"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;     
  &lt;span class="nt"&gt;&amp;lt;rect&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"21"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"21"&lt;/span&gt;  &lt;span class="na"&gt;transform=&lt;/span&gt;&lt;span class="s"&gt;"scale(1.41,.81)   rotate(45) translate(0 -21)"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;   
 &lt;span class="nt"&gt;&amp;lt;/g&amp;gt;&lt;/span&gt; 
&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marianab/embed/XWWQbYP?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Note that the shapes are grouped in a &lt;code&gt;&amp;lt;g&amp;gt;&lt;/code&gt; element so we can add the &lt;code&gt;ID&lt;/code&gt; to the whole figure.&lt;/p&gt;

&lt;p&gt;Next, let's build a bigger cube cloning this unit. First, we need to wrap the cube from the previous example inside the &lt;code&gt;&amp;lt;defs&amp;gt;&lt;/code&gt; tag inside the SVG. In the &lt;code&gt;&amp;lt;defs&amp;gt;&lt;/code&gt; element we can put whatever we want to reuse, which could be a single shape, a group, a gradient.. almost any SVG element. They won't render anywhere unless we use them outside this tag.&lt;/p&gt;

&lt;p&gt;Then we can link the unit as many times as we want using its ID and change the &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; position on every clone like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;use&lt;/span&gt; &lt;span class="na"&gt;xlink:href=&lt;/span&gt;&lt;span class="s"&gt;"#cube"&lt;/span&gt; &lt;span class="na"&gt;x=&lt;/span&gt;&lt;span class="s"&gt;"142"&lt;/span&gt; &lt;span class="na"&gt;y=&lt;/span&gt;&lt;span class="s"&gt;"124"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; 
&lt;span class="nt"&gt;&amp;lt;use&lt;/span&gt; &lt;span class="na"&gt;xlink:href=&lt;/span&gt;&lt;span class="s"&gt;"#cube"&lt;/span&gt; &lt;span class="na"&gt;x=&lt;/span&gt;&lt;span class="s"&gt;"100"&lt;/span&gt; &lt;span class="na"&gt;y=&lt;/span&gt;&lt;span class="s"&gt;"124"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt; 
&lt;span class="c"&gt;&amp;lt;!-- ... --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marianab/embed/wvvZXqG?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Now we have to position every cube remembering that the last element will appear at the front, after that, we'll have our first big cube ready!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;code&gt;xlink:href&lt;/code&gt; is deprecated since SVG2, but it is better to use it for compatibility purposes. In modern browsers, you can just use &lt;code&gt;href&lt;/code&gt; but I tested it on Safari and at the time of writing is not working there. If you use &lt;code&gt;xlink:href&lt;/code&gt; make sure you include this namespace in your SVG tag: &lt;code&gt;xmlns:xlink="http://www.w3.org/1999/xlink"&lt;/code&gt; (you won't need it if you decide to use &lt;code&gt;href&lt;/code&gt;).&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Part 2: Using CSS variables to apply different styles to your reused graphic
&lt;/h2&gt;

&lt;p&gt;I chose a main color for the cube, which is a lighter and a darker shade for the sides and a stroke color. But what if we want to make a second cube a different color?&lt;/p&gt;

&lt;p&gt;We can replace the fills and strokes with CSS variables to make these attributes more flexible. That way, we'll be able to reuse the same cube unit with another palette (instead of defining a second unit with different colors for a second cube).&lt;/p&gt;

&lt;p&gt;Why not add a class to the new cube and change the fill color with CSS? We'll do that, but first, try to inspect a &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt; element. You'll notice it renders in the Shadow DOM, which means it is not vulnerable to scripts and styles, like elements in the normal DOM. Whatever values you define in the figure inside &lt;code&gt;&amp;lt;defs&amp;gt;&lt;/code&gt; will be inherited by all its instances and you won't be able to rewrite those with CSS. But if you replace those values with variables, then you'll be able to &lt;a href="https://tympanus.net/codrops/2015/07/16/styling-svg-use-content-css/"&gt;control them in CSS&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In our cube unit, we'll go through each side and replace the fill and stroke values with semantic variable names.&lt;/p&gt;

&lt;p&gt;For example, this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;rect&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"#00affa"&lt;/span&gt; &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"#0079ad"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;…can be replaced with this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;rect&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"var(--mainColor)"&lt;/span&gt; &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"var(--strokeColor)"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From here, we must duplicate the SVG to build a second cube. However, we don't need to duplicate &lt;code&gt;&amp;lt;defs&amp;gt;&lt;/code&gt; if we are keeping both in the same document. We can add a class to each SVG and control the color palette through CSS, redefining the values of the variable.&lt;/p&gt;

&lt;p&gt;Let's create a palette for the blue cube and another one for the pink cube:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.blue-cube&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;   
 &lt;span class="py"&gt;--mainColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#009CDE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
 &lt;span class="py"&gt;--strokeColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#0079ad&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
 &lt;span class="py"&gt;--lightColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#00affa&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
 &lt;span class="py"&gt;--darkColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#008bc7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;  
&lt;span class="nc"&gt;.pink-cube&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;   
 &lt;span class="py"&gt;--mainColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#de0063&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
 &lt;span class="py"&gt;--strokeColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#ad004e&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
 &lt;span class="py"&gt;--lightColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#fa0070&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
 &lt;span class="py"&gt;--darkColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#c7005a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marianab/embed/gOOJQmw?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;This way, we can add as many cubes as we want and change all colors from one place.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 3: Reusing animations
&lt;/h2&gt;

&lt;p&gt;The idea for this instance is to break the cubes on hover - something like an exploded view so some pieces will move away from the center when we place the cursor over the cubes.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marianab/embed/KKKYdxE?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let's start by defining two movements, one for each axis: &lt;code&gt;move Y&lt;/code&gt; and &lt;code&gt;move X&lt;/code&gt;. By dividing the animations into movements, we'll be able to reuse them in every cube. The animations will consist of moving the cube from its initial position to 30px or 50px away in one direction. We can use a transform translate (&lt;code&gt;X&lt;/code&gt; or &lt;code&gt;Y&lt;/code&gt; ) to achieve that. &lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@keyframes&lt;/span&gt; &lt;span class="n"&gt;moveX&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;   
 &lt;span class="nt"&gt;to&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-35px&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But if we want to be able to reuse this animation, it's better to replace the numeric value with a variable, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@keyframes&lt;/span&gt; &lt;span class="n"&gt;moveX&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;   
 &lt;span class="nt"&gt;to&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--translate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;35px&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the variable is not defined, the default value will be 35px.&lt;/p&gt;

&lt;p&gt;Now we need at least one class to bind to the animation. In this case, though, we need two classes to move cubes in the x-axis: &lt;code&gt;.m-left&lt;/code&gt; and &lt;code&gt;.m-right&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.m-left&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;.m-right&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;    
 &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2s&lt;/span&gt; &lt;span class="n"&gt;moveX&lt;/span&gt; &lt;span class="n"&gt;alternate&lt;/span&gt; &lt;span class="n"&gt;infinite&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the cube to move left, we need a negative value, but we can also declare a different number. We can define our variable like this inside the &lt;code&gt;.m-left&lt;/code&gt; class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.m-left&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="py"&gt;--translate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What's happening here is we're declaring that when we add the class &lt;code&gt;.m-left&lt;/code&gt; to one element, this will play the animation &lt;code&gt;moveX&lt;/code&gt; (the one defined in the &lt;code&gt;@keyframes&lt;/code&gt;) which will last two seconds to translate in the x-axis and reach a new position that is -50px left. Then, the animation alternates directions so that it moves from the last position and take two more seconds to go to its original state. And so on, because it's an infinite loop.&lt;/p&gt;

&lt;p&gt;We can declare another variable to the &lt;code&gt;.m-right&lt;/code&gt; class but if we don't, remember that it will take the 35px we declared at the beginning.&lt;/p&gt;

&lt;p&gt;The default &lt;code&gt;animation-play-state&lt;/code&gt; value is &lt;code&gt;running&lt;/code&gt; but maybe we don't want the cubes to move all the time. It would be very distracting and annoying to use on a site with some nearby content. So, let's try to play the animation only on hover by adding this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;svg&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="nc"&gt;.m-left&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2s&lt;/span&gt; &lt;span class="n"&gt;moveX&lt;/span&gt; &lt;span class="n"&gt;alternate&lt;/span&gt; &lt;span class="n"&gt;infinite&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can try it by yourself and will find that the animation is jumping super fast to the initial state every time we place the cursor out of the cube. To avoid it, we can add the value &lt;code&gt;paused&lt;/code&gt; at the end of the animation shorthand:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.m-left&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;   
 &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2s&lt;/span&gt; &lt;span class="n"&gt;moveX&lt;/span&gt; &lt;span class="n"&gt;alternate&lt;/span&gt; &lt;span class="n"&gt;infinite&lt;/span&gt; &lt;span class="n"&gt;paused&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the animation is paused but will be running on hover by adding this line of CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;svg&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nl"&gt;animation-play-state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;running&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can apply each class to different elements in the SVG. In the first blue cube, we are moving single cubes; in the second one, we're applying those classes to groups of cubes.&lt;/p&gt;

&lt;h3&gt;
  
  
  One last thing…
&lt;/h3&gt;

&lt;p&gt;It wasn't until later that I realized I could reuse a single unit to build them all. I worked on the small cube to make it isometric enough so it could align easily with the other ones next to it. At this point, my unit was a &lt;code&gt;&amp;lt;path&amp;gt;&lt;/code&gt; but I decided to replace it with SVG shapes to reduce the code and get cleaner markup.&lt;/p&gt;

&lt;p&gt;I learned that it is better to take some time to analyze what can be done with SVG before drawing every single shape and dealing with a huge amount of code. It might take more time in the beginning but will save you a lot of time and effort in the long run.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This article was first published on &lt;a href="https://css-tricks.com/use-and-reuse-everything-in-svg-even-animations/"&gt;CSS-Tricks&lt;/a&gt; with edits from &lt;a href="https://chriscoyier.net/"&gt;Chris Coyier&lt;/a&gt; and &lt;a href="https://geoffgraham.me/"&gt;Geoff Graham&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>svg</category>
      <category>optimization</category>
      <category>animation</category>
      <category>css</category>
    </item>
    <item>
      <title>Store Loading animation</title>
      <dc:creator>Mariana Beldi</dc:creator>
      <pubDate>Sat, 07 Dec 2019 14:49:49 +0000</pubDate>
      <link>https://dev.to/marianabeldi/store-loading-animation-19l2</link>
      <guid>https://dev.to/marianabeldi/store-loading-animation-19l2</guid>
      <description>&lt;h2&gt;
  
  
  with SVG and CSS
&lt;/h2&gt;

&lt;p&gt;We were building a site where the user was able to create their own store for selling products online. This task might take a while, so we decided to make a loading animation to explain what was happening at the moment. &lt;/p&gt;

&lt;p&gt;This was my proposal, SVG drawing + CSS animations = 22k weight:&lt;br&gt;
(place your mouse over the tree and wait for the &amp;gt;.&amp;lt;)&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/marianab/embed/XPOQaR?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>svg</category>
      <category>css</category>
      <category>webdev</category>
      <category>ux</category>
    </item>
    <item>
      <title>Contact form with animated feedback</title>
      <dc:creator>Mariana Beldi</dc:creator>
      <pubDate>Fri, 06 Dec 2019 17:41:41 +0000</pubDate>
      <link>https://dev.to/marianabeldi/contact-form-with-animated-feedback-26g6</link>
      <guid>https://dev.to/marianabeldi/contact-form-with-animated-feedback-26g6</guid>
      <description>&lt;h2&gt;
  
  
  SVG interactions to improve your UX with UI
&lt;/h2&gt;

&lt;p&gt;Animations are the best way to bring life to our websites: they help us tell stories and communicate what is happening at that moment. They naturally catch our attention so it’s important to learn how and when to apply them. If we use animations in the right way, we can improve our website’s usability, if we abuse them we can ruin the user experience.&lt;/p&gt;

&lt;p&gt;In this article we’ll show an example of interactive animations, the ones that appear right after the users take an action and can help them notice the results.&lt;/p&gt;

&lt;p&gt;A good case for using SVG interactions are form validations. We can let the user know what is happening at the time they interact with the inputs. This is an example that you can find at our &lt;a href="https://leniolabs.com/"&gt;Leniolabs&lt;/a&gt; website.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BuEYNk_o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://miro.medium.com/max/3268/1%2AXPFw4In3bxandeYGJGhXRA.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BuEYNk_o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://miro.medium.com/max/3268/1%2AXPFw4In3bxandeYGJGhXRA.gif" alt="Interaction with contact form" width="880" height="566"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example we need both inputs to be filled. As soon as the user types any letter the green check icon will confirm that the input is valid. This is a small interaction that we can achieve by adding the &lt;code&gt;required&lt;/code&gt; HTML5 attribute to our text &lt;code&gt;input&lt;/code&gt; or &lt;code&gt;textarea&lt;/code&gt; like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;”text”&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;”name”&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;”name”&lt;/span&gt; &lt;span class="na"&gt;aria-required=&lt;/span&gt;&lt;span class="s"&gt;”true”&lt;/span&gt; &lt;span class="na"&gt;autocorrect=&lt;/span&gt;&lt;span class="s"&gt;”off”&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In CSS we use the selector + pseudo-class: &lt;code&gt;input:valid&lt;/code&gt; or &lt;code&gt;textarea:valid&lt;/code&gt; with a SVG in the background that will show only when the element is valid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="nf"&gt;#name&lt;/span&gt;&lt;span class="nd"&gt;:valid&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;textarea&lt;/span&gt;&lt;span class="nd"&gt;:valid&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt; &lt;span class="nb"&gt;url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;/&lt;/span&gt;&lt;span class="n"&gt;svg&lt;/span&gt;&lt;span class="err"&gt;+&lt;/span&gt;&lt;span class="n"&gt;xml&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;
 &lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;svg&lt;/span&gt; &lt;span class="n"&gt;xmlns&lt;/span&gt;&lt;span class="err"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"http://www.w3.org/2000/svg"&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="err"&gt;=”&lt;/span&gt;&lt;span class="m"&gt;26&lt;/span&gt;&lt;span class="s1"&gt;" height=”26"&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;\&lt;/span&gt;
 &lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;circle&lt;/span&gt; &lt;span class="n"&gt;cx&lt;/span&gt;&lt;span class="err"&gt;=”&lt;/span&gt;&lt;span class="m"&gt;13&lt;/span&gt;&lt;span class="s1"&gt;" cy=”13"&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="err"&gt;=”&lt;/span&gt;&lt;span class="m"&gt;13&lt;/span&gt;&lt;span class="s1"&gt;" fill=”%23abedd8"&lt;/span&gt;&lt;span class="p"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;\&lt;/span&gt;
 &lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="n"&gt;fill&lt;/span&gt;&lt;span class="err"&gt;=”&lt;/span&gt;&lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt; &lt;span class="n"&gt;stroke&lt;/span&gt;&lt;span class="err"&gt;=”&lt;/span&gt;&lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt; &lt;span class="n"&gt;stroke-width&lt;/span&gt;&lt;span class="err"&gt;=”&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="s1"&gt;" d=”M5 15.2l5 5 10–12"&lt;/span&gt;&lt;span class="p"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;\&lt;/span&gt;
 &lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;/&lt;/span&gt;&lt;span class="n"&gt;svg&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;no-repeat&lt;/span&gt; &lt;span class="m"&gt;98%&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="no"&gt;lightgreen&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;background&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt; &lt;span class="m"&gt;0.2s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When adding an inline SVG in CSS is important to use the namespace &lt;code&gt;xmlns=”http://www.w3.org/2000/svg"&lt;/code&gt; or the image won’t be displayed.&lt;/p&gt;

&lt;p&gt;The transition of the background will make the SVG move from its initial position to 98% to the right, as defined in the background shorthand in CSS.&lt;/p&gt;

&lt;p&gt;In JavaScript we can check those validations and add a class to the form (and the SVGs) when both fields are completed, and another class if at least one input is empty. Each class will bind to a CSS animation: one will make the form shake and the envelop fall out of the &lt;em&gt;Send&lt;/em&gt; button; the other one will make the envelop fly directly to the mailbox and the red flag will be up.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="nx"&gt;sendBtn&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="nx"&gt;click&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
 &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;submitName&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;validity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;valid&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;submitText&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;validity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;valid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="nx"&gt;not&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;mailbox&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="nx"&gt;not&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;formshake&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the complete code:&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/marianab/embed/xywxNg?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>ux</category>
      <category>css</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
