<?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: Anonymous!</title>
    <description>The latest articles on DEV Community by Anonymous! (@anonymouser).</description>
    <link>https://dev.to/anonymouser</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%2F1563164%2F86f2c0c7-1d18-4ba3-8e60-f96b61b0a662.png</url>
      <title>DEV Community: Anonymous!</title>
      <link>https://dev.to/anonymouser</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anonymouser"/>
    <language>en</language>
    <item>
      <title>Pure SVG color change animation</title>
      <dc:creator>Anonymous!</dc:creator>
      <pubDate>Mon, 03 Jun 2024 18:41:57 +0000</pubDate>
      <link>https://dev.to/anonymouser/pure-svg-color-change-animation-25id</link>
      <guid>https://dev.to/anonymouser/pure-svg-color-change-animation-25id</guid>
      <description>&lt;p&gt;A first SVG animation, using the animate tag to change between several different colors.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Create the SVG shape.
&lt;/h2&gt;

&lt;p&gt;This one is just a square &lt;code&gt;&amp;lt;rect&amp;gt;&lt;/code&gt; 100 pixels long, with a color fill of blue &lt;code&gt;#0000ff&lt;/code&gt; and a stroke color black &lt;code&gt;#000000&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"&amp;gt;&lt;br&gt;
  &amp;lt;rect x="0" y="0" height="100" width="100" fill="#0000ff" stroke="#000000"&amp;gt;&lt;br&gt;
  &amp;lt;/rect&amp;gt;&lt;br&gt;
&amp;lt;/svg&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Add the animate code
&lt;/h2&gt;

&lt;p&gt;Add the &lt;code&gt;animate&lt;/code&gt; tag inside the square's &lt;code&gt;&amp;lt;rect&amp;gt;&lt;/code&gt;to flash between multiple colors using hex color codes held in &lt;code&gt;values&lt;/code&gt; (#00ff00 green, #ff00ff purple, #ff0000 red) and the timings for each is held by &lt;code&gt;keyTimes&lt;/code&gt;. The values in keyTimes must be between 0 and 1.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"&amp;gt;&lt;br&gt;
  &amp;lt;rect x="0" y="0" height="100" width="100" fill="#0000ff" stroke="#000000"&amp;gt;&lt;br&gt;
  &amp;lt;animate&lt;br&gt;
  attributeName="fill"&lt;br&gt;
  attributeType="XML"&lt;br&gt;
  keyTimes="0; 0.5; 1"&lt;br&gt;
  begin="0s" dur="5s" values="#00ff00;#ff00ff;#ff0000"&lt;br&gt;
  calcMode="discrete"&lt;br&gt;
  repeatCount="indefinite"/&amp;gt;&lt;br&gt;
  &amp;lt;/rect&amp;gt;&lt;br&gt;
&amp;lt;/svg&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Run it
&lt;/h2&gt;

&lt;p&gt;You can also embed it within a HTML document, eg in the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; tag or a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;.&lt;/p&gt;

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

</description>
      <category>svg</category>
      <category>animation</category>
      <category>color</category>
      <category>codepen</category>
    </item>
  </channel>
</rss>
