Pratham Profile picture
25 May, 22 tweets, 5 min read
A complete introduction to CSS animations ๐Ÿš€

CSS animation is a module in CSS that lets you change the styling of elements and therefore creates an animate effect. It's little tricky but not much

Let's learn about it ๐Ÿงต๐Ÿ‘‡๐Ÿป
Before diving into it, we need to understand the importance of CSS animations

Animation can establish interaction between users and the user interface. This makes your website more interactive which ultimately attracts more visitors to your webpage.
CSS animations is little tricky but not too tough to master. In this thread, we will try to gain some decent knowledge about it.
Animation is all about changing one style to another at certain intervals or times. For doing that, we need to learn about `@ keyframes` at rule

The keyframe provides us animation by changing the style sequentially according to the mentioned interval.
The syntax of keyframes at-rule ๐Ÿ‘‡๐Ÿป
In order to bind the keyframe with a particular animation, we need to define few things like name and timing of animations.

We have several properties for that like animation-name, animation-timing, etc...
Either we can use each property of animation or we can use animation shorthand property which includes:

animation-name
animation-duration
animation-timing-function
animation-delay
animation-iteration-count
animation-direction
animation-fill-mode
animation-play-state
Lets create a simple animation which will solve all our doubts:

For example, suppose I want to move my element 500px left in four seconds. It's very easy
The output of above attached code:
Explanation:

Black box is going 500px from left boundary in 4 seconds because we have mentioned 4 seconds in animation property and 500px in keyframe at rule.
Alright moving further, we can also pass percentage in keyframes rule and make some amazing animations

For example, suppose I want on change the background-color of an element
You can also specify the delay in your animation using animation delay property.

It specifies a delay before the start of an animation
We have another cool property called "animation-iteration-count"

It specifies the number of times an animation should run repeatedly. You can pass a numeral value or "infinite" in this property
So far so good, But we can also change the speed curve of animation and can create more smooth animation. And we have animation-timing-function property for that.
You can pass following values in animation-timing function

- ease (slow start, then fast, then slow)
- linear (same speed)
- ease-in (slow start)
- ease-out (slow end)
- ease-in-out (slow start and slow end)
- cubic-bezier (customizable)
Here are some visual representation of speed curve ๐Ÿ‘‡๐Ÿป
See this video for better understanding or you can play with code here

codepen.io/prathkum/pen/Oโ€ฆ
One thing to note here is that animation do not affect element before or after the keyframes.

In order to persist the styling based on last or first keyframe, we have animation-fill-mode
It accepts following value

- forwards (element will retain last keyframe styling)
- backwards (element will get the first keyframe value even in animation-delay period)
- both (both of the above)
Let me explain animation-fill-mode by this video ๐Ÿ‘‡๐Ÿป

- As you can see blue box stopped at left: 500px becuase forwards is begin applied on it
- And orange box has black background even it's in a delay period of 2 seconds because backwards is being applied on it
This is the correct order to animation shorthand property ๐Ÿ‘‡๐Ÿป
And that's it. I tried my best to give a quick overview of how CSS animations works

If you like this thread, drop a like and retweet, means a lot to me โค๏ธ

Peace out ๐Ÿ˜‰

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Pratham

Pratham Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Prathkum

27 May
These 5 great tools can save you from writing CSS code if you're a front-end developer

๐Ÿงต๐Ÿ‘‡๐Ÿป
1๏ธโƒฃ CSS Accordion Slider Generator

- Create fully responsive, css only accordion sliders

๐Ÿ”— accordionslider.com Image
2๏ธโƒฃ Animate.css

- Animate is a CSS library for basic CSS animation. Its a browser friendly with a lot of pre built animations

๐Ÿ”— animate.style
Read 6 tweets
26 May
Cool things about HTML in this single thread ๐Ÿงต๐Ÿ‘‡๐Ÿป
2. Types of list marks Image
Read 11 tweets
26 May
5 great code snippet websites for every web developer and designer

๐Ÿงต๐Ÿ‘‡๐Ÿป Image
1๏ธโƒฃ 30 Seconds of Code

- Short code snippets for all your development needs

๐Ÿ”— 30secondsofcode.org Image
2๏ธโƒฃ Free Frontend

- Free hand-picked HTML, CSS and JavaScript (jQuery, React, Vue) code examples, tutorials and articles

๐Ÿ”— freefrontend.com Image
Read 6 tweets
26 May
Introduction to React Hooks โ†ช๏ธ

Hooks let you manage state and other React feature without writing the class component. It was first introduced in React 16.8

Let us try to understand it in more detail ๐Ÿงต๐Ÿ‘‡๐Ÿป Image
Starting with the discussion on some key point about React hooks ๐Ÿ‘‡๐Ÿป
๐Ÿ“Œ What exactly hooks are?

- We can consider hooks as a JavaScript functions which takes some parameter and return something accordingly. But they servers some complex functionality like managining state and other React features
Read 25 tweets
25 May
5 GitHub repositories for you if you're learning HTML, CSS and JavaScript

๐Ÿงต๐Ÿ‘‡๐Ÿป
1๏ธโƒฃ JavaScript questions

- A long list of (advanced) JavaScript questions, and their explanations

๐Ÿ”— github.com/lydiahallie/jaโ€ฆ Image
2๏ธโƒฃ Microsoft web dev course

- This is a super cool GitHub repo by Microsoft for learning web development for beginners

๐Ÿ”— github.com/microsoft/Web-โ€ฆ Image
Read 6 tweets
24 May
A long list of all CSS tips and tricks I shared here ๐Ÿงต๐Ÿ‘‡๐Ÿป
2. Change marker styling
Read 24 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(