<?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: miral suthar</title>
    <description>The latest articles on DEV Community by miral suthar (@miral182000).</description>
    <link>https://dev.to/miral182000</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%2F653029%2F24c6acfd-f679-45d3-bfca-c421347fb68f.png</url>
      <title>DEV Community: miral suthar</title>
      <link>https://dev.to/miral182000</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/miral182000"/>
    <language>en</language>
    <item>
      <title>SVG Animation in Tailwindcss</title>
      <dc:creator>miral suthar</dc:creator>
      <pubDate>Tue, 13 Jul 2021 14:01:45 +0000</pubDate>
      <link>https://dev.to/miral182000/svg-animation-in-tailwindcss-3ip4</link>
      <guid>https://dev.to/miral182000/svg-animation-in-tailwindcss-3ip4</guid>
      <description>&lt;p&gt;If you have ever used the &lt;a href="https://tailwindcss.com/" rel="noopener noreferrer"&gt;tailwindcss&lt;/a&gt; for your project and tried to do the custom SVG animation so you know it's a bit grumpy to use.&lt;/p&gt;

&lt;p&gt;So, in this blog, I'm going to show you the best and easiest way to do the SVG animation using tailwindcss.&lt;/p&gt;

&lt;p&gt;So what we are going to build?&lt;/p&gt;

&lt;p&gt;This amazing minimal animation.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1625369604828%2FU8eKyDm6W.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1625369604828%2FU8eKyDm6W.gif" alt="ezgif.com-gif-maker.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First thing first you are going to need an SVG image you can download it online from any website you like or you can create your own. I'm using  &lt;a href="https://www.figma.com/" rel="noopener noreferrer"&gt;Figma&lt;/a&gt;  to create my own SVG image&lt;br&gt;
and the most important thing about the SVG image is that you have to name every part you want to animate to get them as an id(having an id is the easiest way to find that part) when we are implementing them in the front end.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1626098458347%2FS39pTErEG.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1626098458347%2FS39pTErEG.png" alt="Group 5.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then export the file in SVG format.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1626098678914%2FJWH830B4gl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1626098678914%2FJWH830B4gl.png" alt="Group 6.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the front-end part of the project, we will use &lt;code&gt;Nextjs&lt;/code&gt; and install tailwindcss and some other npm packages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -D tailwindcss@latest postcss@latest autoprefixer@latest animated-tailwindcss
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add tailwindcss@latest postcss@latest autoprefixer@latest animated-tailwindcss -D
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;/p&gt;

&lt;p&gt;you can clone this file from &lt;a href="https://github.com/miralsuthar/SVG-Animation-tutorial" rel="noopener noreferrer"&gt;Github File&lt;/a&gt; and it comes with an SVG file. Just run &lt;code&gt;yarn&lt;/code&gt; or &lt;code&gt;npm install&lt;/code&gt; in the file and it will download the dependencies in your file. Then generate the &lt;code&gt;tailwind.config.js&lt;/code&gt; and &lt;code&gt;postcss.config.js&lt;/code&gt; files by running this command in the terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx tailwindcss init -p
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then replace your &lt;code&gt;tailwind.config.js&lt;/code&gt; code with this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const withAnimations = require("animated-tailwindcss");

module.exports = withAnimations({
  purge: ["./pages/**/*.{js,ts,jsx,tsx}", "./components/**/*.{js,ts,jsx,tsx}"],
  darkMode: false, // or 'media' or 'class'
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as you can see we are using the &lt;code&gt;animated-tailwindcss&lt;/code&gt; npm package to implement the animate.css classes in our tailwind className.&lt;/p&gt;

&lt;p&gt;and add this code in your &lt;code&gt;global.css&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@tailwind base;
@tailwind components;
@tailwind utilities;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure that your &lt;code&gt;global.css&lt;/code&gt; file is imported into your &lt;code&gt;_app.js&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;After replacing the above code make a component of your SVG image to make your code easy to implement while applying the animation class.&lt;/p&gt;

&lt;p&gt;So pass the props in your SVG file for the selected id like &lt;code&gt;skeleton&lt;/code&gt; and &lt;code&gt;bolts&lt;/code&gt; for the className.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example:
&lt;/h2&gt;

&lt;p&gt;As you can see on line 23 I have passed the skeleton props to the &lt;code&gt;id=Skeleton&lt;/code&gt; so you have to pass the props to every part you want to animate that you can find easily if you gave them the proper name for id.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1626101009548%2F4TtMJqOxh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1626101009548%2F4TtMJqOxh.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then import the component in the file you want the animation to happen as I am only implementing the animation I will just import the component in the &lt;code&gt;index.js&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// pages/index.js

import PhoneSvg from "../components/PhoneSvg";

export default function Home() 
{
  return &amp;lt;PhoneSvg skeleton="" bolt1="" bolt2="" bolt3="" bolt4="" bolt5="" /&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can pass the  &lt;a href="https://animate.style/" rel="noopener noreferrer"&gt;Animate.css&lt;/a&gt; class names to your props to animate them as you want.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// pages/index.js

import PhoneSvg from "../components/PhoneSvg";

export default function Home() {
   return (
     &amp;lt;PhoneSvg
       skeleton=" animate-animated animate-fadeInUp animate-fast animate-repeat-1"
       bolt1="animate-animated animate-fadeInDown animate-slow animate-delay-1s"
       bolt2="animate-animated animate-fadeInDown animate-slow"
       bolt3="animate-animated animate-fadeInDown animate-slow"
       bolt4="animate-animated animate-fadeInDown animate-slow animate-delay-1s"
       bolt5="animate-animated animate-fadeInDown animate-slow animate-delay-1s"
     /&amp;gt;
   );
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and walla your animation is ready.&lt;/p&gt;

&lt;p&gt;To know more about the Animate.css classes visit their &lt;a href="https://animate.style/#documentation" rel="noopener noreferrer"&gt;Documentation&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Leave a comment if you find this article helpful or give me feedback if you found any flaws this will help me in my future article.&lt;/p&gt;

</description>
      <category>tailwindcss</category>
      <category>tutorial</category>
      <category>css</category>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
