A transition animates a property smoothly when its value changes (for example on :hover).
.btn { transition: background-color 0.3s ease, transform 0.3s ease; }
.btn:hover { background-color: navy; transform: scale(1.05); }
Parts
transition-property— what to animate (all,opacity,transform)transition-duration— how long (0.3s,300ms)transition-timing-function—ease,linear,ease-in,ease-out,ease-in-outtransition-delay— wait before starting
Put the transition on the normal state, not only on :hover, so it animates both ways.
Example
Example — Hover transitions
HTML
<style>
.btn { background: #1f386b; color: white; border: none; padding: 12px 24px; border-radius: 6px; font-size: 16px; cursor: pointer; transition: background-color .3s ease, transform .3s ease; }
.btn:hover { background: #e8590c; transform: translateY(-3px); }
.grow { width: 100px; height: 40px; background: seagreen; margin-top: 16px; transition: width 1s ease-in-out; }
.grow:hover { width: 300px; }
</style>
<button class="btn">Hover me</button>
<div class="grow"></div>