<?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: Vira Velmozhna</title>
    <description>The latest articles on DEV Community by Vira Velmozhna (@viravelmozhna).</description>
    <link>https://dev.to/viravelmozhna</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1154772%2Fb0ac94b5-3aea-4356-bb02-bd263c4a7bbd.jpg</url>
      <title>DEV Community: Vira Velmozhna</title>
      <link>https://dev.to/viravelmozhna</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/viravelmozhna"/>
    <language>en</language>
    <item>
      <title>How Vite resolves relative and absolute paths</title>
      <dc:creator>Vira Velmozhna</dc:creator>
      <pubDate>Fri, 11 Apr 2025 20:01:40 +0000</pubDate>
      <link>https://dev.to/viravelmozhna/how-vite-resolves-relative-and-absolute-paths-3f8n</link>
      <guid>https://dev.to/viravelmozhna/how-vite-resolves-relative-and-absolute-paths-3f8n</guid>
      <description>&lt;p&gt;Hello everyone!&lt;/p&gt;

&lt;p&gt;If you're working with Vite and handling static assets like fonts or images, path resolution can be tricky — especially when things work in one environment but not in others. In this article, I’ll explain you how Vite builds projects, the difference between absolute and relative paths, and share a real-life bug I encountered that illustrates why this stuff matters.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Vite Builds Projects
&lt;/h2&gt;

&lt;p&gt;When you run &lt;code&gt;vite build&lt;/code&gt;, Vite compiles, bundles, and optimizes your app into a production-ready folder called &lt;code&gt;dist/&lt;/code&gt;. This folder is what you deploy — everything else stays behind.&lt;/p&gt;

&lt;p&gt;Here’s an example of a project structure before build:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;project-folder/
├── public/
│   └── fonts/
│       └── icon-font.woff
│
├── src/
│   ├── main.js
│   ├── styles/
│   │   └── app.less
│   └── components/
│       └── ...
│
├── index.html
├── vite.config.js
└── package.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After building, your &lt;code&gt;dist/&lt;/code&gt; folder might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dist/
├── assets/
│   ├── app-9f3a2b4d.js
│   ├── style-2c1f6a7e.css
│   └── vendor-1a2b3c4d.js
└── fonts/
    └── icon-font.woff
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  What’s in the &lt;code&gt;dist/&lt;/code&gt; folder:
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;assets/&lt;/code&gt;: contains final, optimized JS and CSS files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;app-xxxx.js&lt;/code&gt; – main application bundle&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;style-xxxx.css&lt;/code&gt; – compiled styles from .less, .scss, or .css files&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;vendor-xxxx.js&lt;/code&gt; – third-party libraries&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;fonts/&lt;/code&gt;: Includes static assets (like fonts) copied from the &lt;code&gt;public/&lt;/code&gt; folder&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Notes:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;src/&lt;/code&gt; folder and any source files (like &lt;code&gt;app.less&lt;/code&gt;) are not included in the build.&lt;/li&gt;
&lt;li&gt;All filenames are hashed for cache busting, ensuring browsers load the latest version after deployments.&lt;/li&gt;
&lt;li&gt;This build is fully static and ready to be hosted on any static server (Netlify, Vercel, GitHub Pages, etc.)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How Absolute Paths Work in Vite
&lt;/h2&gt;

&lt;p&gt;In Vite, an absolute path starts with a &lt;code&gt;/&lt;/code&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;@icon-font-path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;"/fonts/icon-font.woff"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The leading slash tells the browser (and Vite) to look in the root of the site.&lt;/p&gt;

&lt;h4&gt;
  
  
  Here’s how Vite resolves it:
&lt;/h4&gt;

&lt;p&gt;In development (&lt;code&gt;vite dev&lt;/code&gt;): Vite serves files in the &lt;code&gt;public/&lt;/code&gt; directory at the root level. So &lt;code&gt;/fonts/icon-font.woff&lt;/code&gt; is resolved as &lt;code&gt;public/fonts/icon-font.woff&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In production (&lt;code&gt;vite build&lt;/code&gt;): Vite maintains this path, assuming that &lt;code&gt;fonts/icon-font.woff&lt;/code&gt; will be at the root of the deployed &lt;code&gt;dist/&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;This means that any asset placed in the &lt;code&gt;public/&lt;/code&gt; folder can be accessed directly using an absolute path that starts with &lt;code&gt;/&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Relative Paths Work in Vite
&lt;/h2&gt;

&lt;p&gt;A relative path points to a file based on the current file’s location. 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;@icon-font-path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;"../fonts/icon-font.woff"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Relative paths work well when you're referencing files inside the &lt;code&gt;src/&lt;/code&gt; folder, as long as the file structure matches and Vite can bundle those files correctly.&lt;/p&gt;

&lt;p&gt;However, issues can arise if the relative path doesn't correctly reflect the file system, especially if you're referencing something that lives outside of &lt;code&gt;src/&lt;/code&gt;, such as in &lt;code&gt;public/&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-life example: Why the relative path failed
&lt;/h2&gt;

&lt;p&gt;Let’s look at a bug I encountered on a new project.&lt;br&gt;
Here's the structure of the project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;project-folder/
│
├── public/
│    └── fonts/
│         └── icon-font.woff
│
├── src/
│    └── styles/
│         └── app.less
│
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Originally, in &lt;code&gt;app.less&lt;/code&gt; a relative path was used:&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;@icon-font-path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;"../fonts/icon-font.woff"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This path worked fine in production and some environments, but when I ran the project locally with &lt;code&gt;vite dev&lt;/code&gt;, the icon fonts didn’t load.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why it failed locally:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;font&lt;/code&gt; folder was in the &lt;code&gt;public/&lt;/code&gt; directory.&lt;/li&gt;
&lt;li&gt;Relative paths from within &lt;code&gt;src/&lt;/code&gt; can’t access files in &lt;code&gt;public/&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;So the file was simply not found.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Why it worked in production:
&lt;/h4&gt;

&lt;p&gt;Vite was bundling everything, and the compiled CSS or JS file (e.g. &lt;code&gt;app-9f3a2b4d.js&lt;/code&gt;) ended up inside the &lt;code&gt;dist/assets/&lt;/code&gt; folder. Meanwhile, the font file from the &lt;code&gt;public/fonts/&lt;/code&gt; directory was copied into &lt;code&gt;dist/fonts/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The resulting &lt;code&gt;dist/&lt;/code&gt; structure looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dist/
├── assets/
│   ├── app-9f3a2b4d.js
│   ├── style-2c1f6a7e.css
│   └── vendor-1a2b3c4d.js
└── fonts/
    └── icon-font.woff
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The path used in the compiled CSS or JS was relative — and since those files were in &lt;code&gt;dist/assets/&lt;/code&gt;, a path like &lt;code&gt;../fonts/icon-font.woff&lt;/code&gt; would still point correctly to &lt;code&gt;dist/fonts/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In other words, from &lt;code&gt;assets/style-2c1f6a7e.css&lt;/code&gt;, the browser goes one level up (&lt;code&gt;../&lt;/code&gt;) and finds the &lt;code&gt;fonts/&lt;/code&gt; folder right there at the root of &lt;code&gt;dist/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The path technically worked in production, but it was coincidental. The structure happened to align, not because the relative path was correct in source files, but because the build output ended up that way.&lt;/p&gt;

&lt;p&gt;This is why the path didn’t work in &lt;code&gt;vite dev&lt;/code&gt;, where files aren't organized the same way — which leads to the next point: using absolute paths ensures consistency across all environments.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Fix:
&lt;/h4&gt;

&lt;p&gt;Switching to an absolute path did the trick:&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;@icon-font-path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;"/fonts/icon-font.woff"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now Vite correctly served the font from &lt;code&gt;public/&lt;/code&gt;, and the path worked in all environments: Dev, Prod, and even when viewing the site locally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Path resolution in Vite is simple — but only once you know how it works.&lt;/p&gt;

&lt;h4&gt;
  
  
  Here’s the takeaway:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Use absolute paths (/...) for referencing files in &lt;code&gt;public/&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Use relative paths only for files inside &lt;code&gt;src/&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Always test both &lt;code&gt;vite dev&lt;/code&gt; and &lt;code&gt;vite build&lt;/code&gt; to ensure consistency&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This small path fix saved me hours of debugging — I hope it saves you some too! Let me know if you’ve run into similar issues or have tips of your own.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>vite</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Understanding Expensive Calculations in React for Beginners</title>
      <dc:creator>Vira Velmozhna</dc:creator>
      <pubDate>Tue, 19 Nov 2024 21:17:49 +0000</pubDate>
      <link>https://dev.to/viravelmozhna/understanding-expensive-calculations-in-react-for-beginners-30mm</link>
      <guid>https://dev.to/viravelmozhna/understanding-expensive-calculations-in-react-for-beginners-30mm</guid>
      <description>&lt;p&gt;Hey there 👋&lt;/p&gt;

&lt;p&gt;In React development, many factors influence the overall performance of an application. One key factor is the efficiency of calculations. But how can we determine if a calculation is expensive? And why is it so important to know?&lt;/p&gt;

&lt;p&gt;React developers, especially beginners, often overuse such hooks like &lt;code&gt;useState&lt;/code&gt; and &lt;code&gt;useEffect&lt;/code&gt;. Understanding whether a calculation is expensive can help you decide if state or effects are necessary, or if it is acceptable to re-calculate something on every render.&lt;/p&gt;

&lt;p&gt;Let's get straight to the point with key factors to consider. By the end, you’ll have a clear checklist to help you identify costly calculations in your React projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Theoretical analysis
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Time complexity
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Constant time &lt;code&gt;O(1)&lt;/code&gt;&lt;br&gt;
Operations like simple arithmetic or accessing a fixed element are considered cheap calculations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Linear time &lt;code&gt;O(n)&lt;/code&gt;&lt;br&gt;
Iterating over a list once. The cost depends on the size of the list.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Quadratic time &lt;code&gt;O(n^2)&lt;/code&gt; &lt;br&gt;
Nested loops where each element is compared or processed multiple times. These are generally considered as expensive calculations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Exponential time &lt;code&gt;O(2^n)&lt;/code&gt;&lt;br&gt;
Processes like deep recursion or brute-force searching. These are highly expensive calculations&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Data size
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;For small lists (&amp;lt; 100) - Calculations with &lt;code&gt;O(n)&lt;/code&gt; are usually fine and considered cheap.&lt;/li&gt;
&lt;li&gt;For large lists (&amp;gt;1000) - Even calculations &lt;code&gt;O(n)&lt;/code&gt; can become expensive.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Practical test
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Browser performance monitoring
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Console timing&lt;/strong&gt;&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name-of-the-process&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;process&lt;/span&gt; &lt;span class="nf"&gt;code &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;calculation&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timeEnd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name-of-the-process&lt;/span&gt;&lt;span class="dl"&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 time is less than 1-2 ms - the calculation is considered as inexpensive.&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 javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;setIsAuthenticated&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;setIsAuthenticated&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timeEnd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;setIsAuthenticated&lt;/span&gt;&lt;span class="dl"&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;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F42ur0akkdnie69709qsx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F42ur0akkdnie69709qsx.png" alt="console output" width="800" height="308"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance tab&lt;/strong&gt;&lt;br&gt;
The browser's performance tab provides a lot of useful information. While I'm not going to describe it in this article (it deserves its own article), I recommend to learn more about it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Frequency of calculation
&lt;/h3&gt;

&lt;p&gt;Even if a calculation isn't expensive, if it's being performed extremely frequently, it can still contribute to performance issue.&lt;/p&gt;

&lt;h3&gt;
  
  
  User experience and performance bottlenecks
&lt;/h3&gt;

&lt;p&gt;The user experience is the best indicator of performance. Ask yourself: Is UI sluggish and unresponsive or smooth and responsive? &lt;br&gt;
If your app has issues in these areas, it might be required to optimize expensive calculations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;I hope the topic became clearer for you. This article is a start to further exploration and learning about React and performance. Consider learning about React's optimization techniques like &lt;code&gt;useMemo&lt;/code&gt; and &lt;code&gt;React.memo&lt;/code&gt;, diving into browser performance tools, or strengthening your understanding of algorithms and data structures.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>react</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Adding Click Animation to a Button with CSS: A Step-by-Step Tutorial</title>
      <dc:creator>Vira Velmozhna</dc:creator>
      <pubDate>Wed, 24 Jan 2024 22:14:10 +0000</pubDate>
      <link>https://dev.to/viravelmozhna/adding-click-animation-to-a-button-with-css-a-step-by-step-tutorial-2f8a</link>
      <guid>https://dev.to/viravelmozhna/adding-click-animation-to-a-button-with-css-a-step-by-step-tutorial-2f8a</guid>
      <description>&lt;p&gt;If you are just starting with CSS, this guide will walk you through the basics of animation, explaining each concept in details. After looking at basics, we will use one of the approaches to add click animation to a button.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Understanding CSS Animation&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In the world of web development, CSS animation serves as a powerful tool to make your interface dynamic and engaging. Let's discuss the two fundamental methods of CSS animation: transitions and keyframes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Transitions:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What are Transitions?&lt;/strong&gt;&lt;br&gt;
Transitions offer a straightforward and intuitive approach to animating changes in CSS properties. This is a smooth effect, where an element is being changed from one state to another over a specified duration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Do Transitions Work?&lt;/strong&gt;&lt;br&gt;
Transitions work by defining the starting and ending states of an element. When a change occurs (like a hover or a click), the transition property steps in, smoothly interpolating between the old and new states. This is achieved by specifying the property to be transitioned, the duration of the transition, and the timing function defining the pace of the change.&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="c"&gt;/* Adding a transition to the width property */&lt;/span&gt;
&lt;span class="nc"&gt;.btn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&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;width&lt;/span&gt; &lt;span class="m"&gt;0.5s&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
  &lt;span class="c"&gt;/* 
  width - the property that will be animated
  0.5 - duration in seconds
  ease - timing function 
  */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.btn&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;250px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* New width on hover */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In this example, the button's width changes smoothly from 200px to 250px over 0.5 seconds when hovered.&lt;/p&gt;

&lt;h3&gt;
  
  
  Keyframes:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What are Keyframes?&lt;/strong&gt;&lt;br&gt;
Keyframes provide a more detailed control over the animation process. They allow you to define specific points (keyframes) in an animation sequence, each representing a unique state of the element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Do Keyframes Work?&lt;/strong&gt;&lt;br&gt;
You set up keyframes at different intervals, specifying the styles for each of them. The browser transitions between these keyframes, creating a more complex and customized animation sequence.&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="c"&gt;/* Defining keyframes for a bouncing animation */&lt;/span&gt;
&lt;span class="k"&gt;@keyframes&lt;/span&gt; &lt;span class="n"&gt;bounce&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="o"&gt;%&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;translateY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="err"&gt;50&lt;/span&gt;&lt;span class="o"&gt;%&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;translateY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-20px&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="err"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%&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;translateY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&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="c"&gt;/* Applying the keyframe animation to an element */&lt;/span&gt;
&lt;span class="nc"&gt;.element&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="n"&gt;bounce&lt;/span&gt; &lt;span class="m"&gt;2s&lt;/span&gt; &lt;span class="n"&gt;infinite&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
  &lt;span class="c"&gt;/* Bouncing animation lasting 2 seconds, repeating infinitely */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In this example, the element will smoothly bounce up and down in a loop.&lt;/p&gt;

&lt;h3&gt;
  
  
  Choosing Between Transitions and Keyframes:
&lt;/h3&gt;

&lt;p&gt;When deciding between transitions and keyframes, consider which effect do you want to achieve. Transitions are perfect for simple effects, like hovering over a button, while keyframes are preferable when creating more dynamic and complex animations, when you need more control.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;code&gt;transition&lt;/code&gt; and &lt;code&gt;transform&lt;/code&gt; properties&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now, let's take a closer look at the specific CSS properties we will be using in the tutorial – &lt;strong&gt;&lt;code&gt;transition&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;transform&lt;/code&gt;&lt;/strong&gt;. Understanding how these properties work will empower your control of the animations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;transition&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is it?&lt;/strong&gt;&lt;br&gt;
The transition property is a fundamental tool for facilitating smooth changes in CSS properties over a specified duration.&lt;br&gt;
&lt;strong&gt;How does it work?&lt;/strong&gt;&lt;br&gt;
In the example below, we use &lt;strong&gt;&lt;code&gt;transition&lt;/code&gt;&lt;/strong&gt; to set the animation's duration and easing function. The &lt;strong&gt;&lt;code&gt;duration&lt;/code&gt;&lt;/strong&gt; determines how long the transition takes, while the &lt;strong&gt;&lt;code&gt;easing function&lt;/code&gt;&lt;/strong&gt; influences the speed variations throughout the 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;.btn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&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;width&lt;/span&gt; &lt;span class="m"&gt;3s&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Duration: 3 seconds with an ease timing function */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.btn&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;250px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* New width on hover */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the button smoothly transitions its width over 3 seconds with an ease timing function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;transform&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is it?&lt;/strong&gt;&lt;br&gt;
The &lt;code&gt;transform&lt;/code&gt; property is a great tool that enables two-dimensional and three-dimensional transformations in CSS. It provides functionalities like rotation, scaling, skewing, or translating elements, allowing for dynamic adjustments in their appearance and position.&lt;br&gt;
&lt;strong&gt;How does it work?&lt;/strong&gt;&lt;br&gt;
In the example below, we use &lt;strong&gt;&lt;code&gt;transform&lt;/code&gt;&lt;/strong&gt; to give the checkmark icon a dynamic movement. By using &lt;strong&gt;&lt;code&gt;translate&lt;/code&gt;&lt;/strong&gt; in combination with &lt;strong&gt;&lt;code&gt;opacity&lt;/code&gt;&lt;/strong&gt;, we create a visually appealing transformation when the icon appears.&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;.icon&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&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;transform&lt;/span&gt; &lt;span class="m"&gt;2s&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;opacity&lt;/span&gt; &lt;span class="m"&gt;2s&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt; &lt;span class="m"&gt;3s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.icon.done&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&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;translate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-50%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;-180%&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;In this example, the icon smoothly translates upwards and becomes visible over 2 seconds, with a delay of 3 seconds.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Let's add a click animation to a button&lt;/strong&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Breaking Down the Requirements:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;We will create a button with a rounded border and some text inside.&lt;/li&gt;
&lt;li&gt;When the user clicks on it, we want the text to disappear, making room for a checkmark icon.&lt;/li&gt;
&lt;li&gt;As an extra touch, let's make the border gradually narrow until it forms a circle.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4vdr60nqsjgxoe0alke9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4vdr60nqsjgxoe0alke9.png" alt="button before being clicked" width="800" height="798"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjb96dk4sqyu3nt28uhf4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjb96dk4sqyu3nt28uhf4.png" alt="button after being clicked" width="796" height="794"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s start with HTML structure. &lt;br&gt;
We need a div wrapper, and a button and an icon inside it.&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"wrapper"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn-text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      Click on me!
    &lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"icon"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;✔️&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add some css styles for the button and icon.&lt;br&gt;
For the button, we will be animating width and border-radius properties. Initial values of these properties we set for the class name &lt;code&gt;.btn&lt;/code&gt;, and the new values for the class name &lt;code&gt;.btn.clicked&lt;/code&gt;, which will be applied after clicking on the button. The same is for the icon.&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;.wrapper&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&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;translate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-50%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;-50%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.btn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&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="m"&gt;#FFB3CB&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;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;pointer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&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;width&lt;/span&gt; &lt;span class="m"&gt;2s&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;border-radius&lt;/span&gt; &lt;span class="m"&gt;2s&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.btn.clicked&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#FFB3CB&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&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;span class="nc"&gt;.btn.clicked&lt;/span&gt; &lt;span class="nc"&gt;.btn-text&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.icon&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;110%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    
  &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&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;transform&lt;/span&gt; &lt;span class="m"&gt;1s&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;opacity&lt;/span&gt; &lt;span class="m"&gt;1s&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt; &lt;span class="m"&gt;1s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.icon.done&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&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;translate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-50%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;-180%&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 add event listener in JS, so that the animations will be working.&lt;br&gt;
We will be adding the additional classes to the button and the icon, when clicking on the button.&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="cm"&gt;/* choose the elements */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.btn&lt;/span&gt;&lt;span class="dl"&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;icon&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.icon&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cm"&gt;/* add callback function, which will be executed after clicking on the button */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&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="nx"&gt;button&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="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;clicked&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;icon&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="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;done&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="cm"&gt;/* add event listener */&lt;/span&gt;
&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! The animation is ready. &lt;/p&gt;

&lt;p&gt;I have prepared a live presentation of the transition animation for you in codepen sandbox. Use this &lt;a href="https://codepen.io/vivecodes/pen/BavPyQb" rel="noopener noreferrer"&gt;link&lt;/a&gt; to find it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusions:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Mastering CSS animation with the &lt;code&gt;transition&lt;/code&gt; and &lt;code&gt;transform&lt;/code&gt; properties provides for developers the essential tools for creative web design.&lt;br&gt;
After this tutorial, transitioning between styles should feel more intuitive, empowering developers to effortlessly enhance user experiences with dynamic and engaging web animations.&lt;/p&gt;

&lt;p&gt;If you have any questions, don't hesitate to ask me in the comments section.&lt;/p&gt;

</description>
      <category>css</category>
      <category>frontend</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
