Home › CSS Tutorial › Transitions and animations
Transitions and animations
Add smooth movement.
transition animates changes between states such as hover. @keyframes defines a repeating animation. Respect people who prefer reduced motion.
Example code
<style>
.b{display:inline-block;padding:12px 20px;background:#2e86de;color:#fff;transition:transform .2s}
.b:hover{transform:scale(1.15)}
.s{width:40px;height:40px;background:coral;animation:m 2s infinite alternate}
@keyframes m{to{transform:translateX(200px)}}
@media (prefers-reduced-motion:reduce){.s{animation:none}}
</style>
<div class="b">Hover me</div><br><br><div class="s"></div>