How to Implement These CSS Codes
How to Implement These Animations on a Button?
For CSS animations to work, they need to have two properties: the keyframe, which is the definition of how the animation moves, and the animation property, which defines how much time the animation should run, the delay before the animation starts, etc. Above in the examples, you’ll see the animation keyframes (@keyframes); you can copy those directly to your CSS. The second part you’ll need is the animation property, which you place in a particular element selector.
If you want to expand your knowledge about the subject, I left direct links that expand on each subject:
But if you want to get straight to the point, let’s get to it
Here’s a bare-bones HTML file structure with an example animation. Technically, you can copy this into a text file and rename it to myAnimation.html; double-click it, and it will run the animation. Let’s focus on the relevant components of the animation.
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.animation-box {
padding: 12px 34px;
background: linear-gradient(135deg, #f97316 0%, #fb923c 100%);
display: flex;
color: #1c1917;
font-weight: 800;
justify-content: center;
align-items: center;
border-radius: 999px;
letter-spacing: 0.08em;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.fadeIn { animation: fadeIn 1.2s infinite; }
</style>
</head>
<body>
<div class="animation-box fadeIn">BUTTON</div>
</body>
</html>
This is the section of the code dedicated to the animations themselves. And when you need an animation you can just copy one of them into your CSS
This is the selector section of the animation, where you can see that it has an animation class of fadeIn. You can switch this class selector to any other type of animation you would like to use.
The animation property has multiple values you can change and adjust to your needs, If you don’t define one of the animation values it will use its default animation value.
animation: duration easing-function delay iteration-count direction fill-mode play-state name;
animation: (Animation1), (Animation2), (Animation3);
animation: 1.2s forwards fadeIn, 1s 2.4s bounce;
Default values, If a animation shorthand value is not defined, it defaults to these values.
- animation-name: none
- animation-duration: 0s (when not defined, you won’t see the animation moving)
- animation-timing-function: ease
- animation-delay: 0s
- animation-iteration-count: 1
- animation-direction: normal
- animation-fill-mode: none
- animation-play-state: running
- animation-timeline: auto
Time to use the button animations above on your own buttons. Just copy and paste the code and refine the properties, Remember that for the CSS animation to work on your button, you have 3 things that need to be true. One is the animation itself which is defined in @keyframes, and second selector that is connected to that animation needs to exist and be placed on the element that need to be animated.