Sub topic 5
Scale, rotate and translate on hover
This chapter assumes you can read Tailwind class lists and know what the hover: variant does. It also assumes you have seen transition, duration-* and ease-* utilities. Here you will use the transform utilities, which resize, turn and move an element without changing the layout around it.
What transform utilities do
Three families of utilities cover most hover effects:
| Family | Example classes | Effect |
|---|---|---|
| Scale | `scale-105`, `scale-x-95`, `-scale-100` | Grows or shrinks the element. 100 means normal size. |
| Rotate | `rotate-3`, `-rotate-6`, `rotate-180` | Turns the element by that many degrees. |
| Translate | `translate-x-1`, `-translate-y-2`, `translate-x-full` | Moves the element sideways or up and down. |
Skew (skew-3, skew-x-6) also exists, but it is rarely used for hover feedback.
Negative values use a leading dash, as in -translate-y-1 (move up) or -rotate-6 (turn counter-clockwise). Translate values follow the spacing scale, so translate-x-1 is 0.25rem with the default theme. Fraction and keyword values such as translate-x-1/2 and translate-x-full are percentages of the element's own size.
Transforms are drawn after layout is calculated. A scaled or moved element does not push its neighbors away, and the space it originally occupied stays reserved. That is why transforms are cheap, and it is also why a scaled card can overlap the cards beside it.
A transform on its own does nothing animated
Adding hover:scale-105 makes the element jump to 105% the instant the pointer enters. To animate it, add a transition that includes the transform property:
<div class="rounded-lg bg-white p-6 shadow transition duration-300 ease-out hover:-translate-y-1 hover:scale-105 hover:shadow-lg">
Card content
</div>This is the default transition utility. It animates a preset list of properties, including box-shadow and transform. So the card lifts one step, grows by 5% and gains a larger shadow, all over 300 milliseconds.
Choosing the right transition utility
The most common mistake is pairing a transform with the wrong transition utility. These two buttons look similar in code but behave differently:
<!-- Scale snaps instantly: transition-colors only covers color properties -->
<button class="bg-indigo-600 px-4 py-2 text-white transition-colors duration-200 hover:scale-110 hover:bg-indigo-700">
Snaps
</button>
<!-- Scale and color both animate -->
<button class="bg-indigo-600 px-4 py-2 text-white transition duration-200 hover:scale-110 hover:bg-indigo-700">
Animates
</button>The first button changes color smoothly, but its scale jumps. The transition-colors utility lists only color-related properties. Use transition-transform when the transform is the only thing changing, or plain transition when several things change at once.
<button class="rounded bg-slate-900 px-4 py-2 text-white transition-transform duration-150 ease-out hover:scale-105 active:scale-95">
Press me
</button>The active:scale-95 class gives a small pressed-in feel while the mouse button is down. Because it uses the same transition, both the grow and the shrink are animated.
What the transform utilities compile to
How transform classes combine depends on your Tailwind version.
- In Tailwind v3, each utility sets a CSS variable such as
--tw-scale-xor--tw-rotate. A singletransformdeclaration combines all of them. That is whyhover:scale-105andhover:rotate-3work together on one element. - In Tailwind v4, the utilities use the individual CSS properties
scale,rotateandtranslate. The browser combines them, andtransition-transformcovers all of them.
In both versions you can write hover:-translate-y-1 hover:scale-105 hover:rotate-1 on one element and get all three effects. The practical difference is mostly what you see in browser developer tools. Under v4 you will see separate scale and translate properties instead of one long transform value.
Translate for movement
Small translations are good for "lift" effects and for nudging icons. Keep the distances small. Moving an element 4 pixels signals interactivity, and moving it 40 pixels looks like a layout bug.
A common pattern moves a child when the whole link is hovered. It uses the group class from the next chapter's topic, but the transform part is what matters here:
<a href="#" class="group inline-flex items-center gap-2 text-indigo-600">
<span>Read more</span>
<span class="transition-transform duration-200 group-hover:translate-x-1">→</span>
</a>The arrow moves 0.25rem to the right when the pointer is anywhere over the link. The transition-transform class limits the animation to movement, which keeps the effect predictable.
Percentage translations
translate-x-full moves an element by 100% of its own width. This is the standard way to hide a panel just off screen and slide it in:
<div class="relative overflow-hidden rounded border">
<div class="absolute inset-y-0 left-0 w-full translate-x-full bg-indigo-600 transition-transform duration-300 ease-out hover:translate-x-0"></div>
<p class="relative p-4">Hover the area for a sliding fill</p>
</div>Here the panel starts one full width to the right. The parent has overflow-hidden, so the panel is clipped until it slides in. The hover is on the panel itself, which is hidden, so in a real design you would put the hover on the parent with group-hover. Treat this snippet as showing the percentage values and the clipping. The pointer cannot reach the hidden panel, so run it with the hover moved to the parent before relying on it.
Rotate for icons and playful cards
Rotation suits icons, chevrons and playful cards. For a disclosure chevron, 180 degrees flips it. For decorative tilt, 1 to 3 degrees is enough.
<button class="group inline-flex items-center gap-2 rounded border px-3 py-2">
<span>Settings</span>
<svg class="size-4 transition-transform duration-200 group-hover:rotate-90" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path d="M7 5l6 5-6 5z" />
</svg>
</button>An SVG is already a replaced element that accepts transforms. The next section covers the case that catches most people: inline elements.
Edge cases and gotchas
Inline elements ignore transforms
Browsers do not apply transforms to non-replaced inline elements such as a bare <span> or <a>. If a hover effect does nothing, check the display value. Add inline-block (or block, or flex):
<!-- No visible effect: spans are inline by default -->
<span class="transition-transform hover:rotate-6">Tilt</span>
<!-- Works -->
<span class="inline-block transition-transform hover:rotate-6">Tilt</span>In the group example above, the arrow <span> works because it is a flex item inside an inline-flex container, and flex items are blockified.
Transform origin
Transforms pivot around the center of the element by default. Use the origin-* utilities to change the pivot point:
<div class="origin-bottom-left transition-transform duration-300 hover:-rotate-6">
Swings from the bottom-left corner
</div>Other values include origin-top, origin-top-right and origin-center. For a menu that grows downward from its trigger, origin-top with scale-y-95 to scale-y-100 looks natural.
Hover flicker at the edges
If a hover effect moves the element out from under the pointer, the hover state ends, the element moves back, and the hover state returns. The result is a visible flicker. This happens with large translations and with -translate-y-* on short elements when the pointer is near the bottom edge.
The fix is to put the hover on a stable wrapper and animate the child:
<div class="group p-2">
<div class="rounded-lg bg-white p-6 shadow transition duration-200 group-hover:-translate-y-2 group-hover:shadow-lg">
Stable hover target
</div>
</div>The wrapper never moves, so the pointer stays over it, and the card moves inside it.
Overlap and stacking
A scaled element can overlap its neighbors, and later siblings may paint above it. Add relative and a z-index on hover when the grown element must stay on top:
<div class="relative transition duration-200 hover:z-10 hover:scale-110">
Stays above neighbors
</div>The z-index only applies to positioned elements or flex and grid items, so relative is needed for ordinary block elements. In fact, any element with an active transform creates its own stacking context, which can also trap child z-indexes. Keep this in mind when a dropdown inside a scaled card appears behind other content.
Blurry text when scaling
Scaling text and images can make them look soft during the animation, and sometimes after it ends, on certain displays. Small scale changes such as scale-105 are safest. Fractional pixel positions from translation can also blur text at rest. Where that happens, prefer whole-pixel offsets with arbitrary values, such as hover:-translate-y-[2px].
Touch devices
In Tailwind v4, hover: only applies on devices where the primary input can hover. This stops "stuck" hover states on phones. In v3, hover: applies on tap and stays until the user taps elsewhere, unless you enable the hoverOnlyWhenSupported future flag. Either way, do not hide essential information behind a hover transform. Touch users may never see it.
Arbitrary values
When the scale does not have the step you need, use square brackets:
<div class="transition-transform duration-200 hover:scale-[1.03] hover:-rotate-[1.5deg] hover:translate-y-[-3px]">
Fine-tuned hover
</div>Arbitrary values are good for one-off tuning. If you repeat the same value in many places, define it in your theme so the design stays consistent.
Respecting reduced motion
Hover transforms are motion, and some users ask their system to minimize it. Apply the effect only when motion is acceptable by prefixing it with motion-safe::
<div class="transition duration-300 motion-safe:hover:-translate-y-1 motion-safe:hover:scale-105">
Card content
</div>The variants stack, so motion-safe:hover:scale-105 applies only when the user has not requested reduced motion and the pointer is over the element. Small color or shadow changes can stay unconditional, because they give feedback without movement. The full treatment comes in a later chapter.
Summary checklist
- Add a transition that covers transforms:
transitionortransition-transform, nottransition-colors. - Keep the amounts small:
scale-105,-translate-y-1,rotate-3. - Make sure the element is not a plain inline element.
- Set
origin-*when the pivot point matters. - Hover a stable wrapper if the element moves away from the pointer.
- Gate movement with
motion-safe:and do not hide essential content behind hover.
Exercise
A button has the classes bg-teal-600 px-4 py-2 text-white transition-colors duration-200 hover:bg-teal-700 hover:scale-110. The color fades smoothly on hover, but the scale jumps instantly. Why does this happen, and what is the smallest change that fixes it?
Show answer
The transition-colors utility sets transition-property to color-related properties only, so transform (or scale) is not animated. Replace transition-colors with transition, which includes both colors and transforms. If only the transform needs animating, transition-transform also works, but then the color would change instantly, so transition is the right choice here.
Exercise
You add hover:rotate-6 transition-transform to a bare <span> inside a paragraph, and nothing visibly happens. What is the cause, and how do you fix it?
Show answer
A non-replaced inline element ignores transforms. Add inline-block (or make it a flex or grid item) so the span can be transformed, giving inline-block transition-transform hover:rotate-6.