How to Make a Slide Image Animation (Step-by-Step)
In this article
To make a slide image animation, you move an image into view along a straight path using a CSS transform or keyframes, or a preset in a website builder. The shortest working method is a CSS keyframe that animates transform: translateX() from off-screen to its final position. This guide covers that method plus the practical details that make it look smooth and work on phones.
What You'll Need
- A web page or site builder where you can edit HTML and CSS (or a builder with animation presets).
- An image file, ideally compressed and sized close to how it will display.
- A code editor or the builder's custom code block.
- Basic familiarity with CSS selectors and class names.
Step-by-Step
- Choose the slide direction and distance. Decide whether the image slides in from the left, right, top or bottom, and how far. A common choice is 100% of the image width for a full slide, or 40–60px for a subtle slide. Write this down before coding so you do not guess later.
- Add the image to your page with a class. Give the image a class such as
slide-in. Keep the image in normal document flow so it reserves space; do not use absolute positioning unless you have a specific layout reason. - Set the starting state in CSS. Use
transformto move the image off its final position andopacity: 0if you want a fade. For a left slide, the start istransform: translateX(-60px); opacity: 0;. The element still occupies its space, so the layout does not jump. - Define the keyframes. Create a
@keyframesrule that ends attransform: translateX(0); opacity: 1;. Name it something clear likeslideInLeft. Keep only the properties you animate; do not animate layout properties such aswidthormarginbecause they are slower. - Apply the animation. On the
.slide-inclass, setanimation: slideInLeft 0.6s ease-out forwards;. Theforwardsfill mode keeps the final state after the animation ends. Adjust duration between 0.3s and 0.8s for UI elements; longer feels sluggish. - Trigger it at the right time. If the image is above the fold, the animation runs on page load. If it is further down, add a small script using
IntersectionObserverto add a class when the image enters the viewport, and put the animation on that class. This avoids animating content the visitor never sees. - Respect reduced motion. Wrap the animation in
@media (prefers-reduced-motion: no-preference), or add a@media (prefers-reduced-motion: reduce)block that setsanimation: none. Some people get motion sickness from sliding elements, and this setting is a standard accessibility expectation. - Test on a phone and a desktop. Resize the browser and check that the image does not cause horizontal scrolling. If it does, reduce the slide distance or add
overflow-x: hiddento the container, not the whole page unless necessary. - Check performance. Open the browser's developer tools and look for dropped frames while the animation runs. If it stutters, confirm you are animating only
transformandopacity, and that the image is not enormous. - Add a fallback. If the animation fails to load, the image should still be visible. The safest pattern is to set the final visible state as the default and only apply the hidden start state inside the animation context, so a CSS error does not leave the image invisible.
Common Mistakes
- Animating
leftormargininstead oftransform. These trigger layout on every frame and cause visible stutter on phones. - Forgetting
forwards. Without it, the image snaps back to its starting position when the animation ends. - Starting with
opacity: 0and no fallback. If the animation never runs, the image stays invisible. Always make the final state the safe default. - Sliding too far. A full-width slide on a large image looks dramatic once and annoying on repeat visits. Keep distances modest for content images.
- Animating every image on the page. Multiple simultaneous slides compete for attention. Animate one or two key images, or stagger them with small delays.
- Ignoring horizontal overflow. An element translated off-screen can widen the page on some mobile browsers, creating a sideways scrollbar.
Tips
- Use
ease-outfor entrances; it starts fast and settles, which reads as natural. - Keep durations consistent across a page so the motion feels like one system.
- Stagger multiple images with
animation-delayof 0.1s to 0.2s rather than animating them all at once. - If you use a site builder, look for its animation or motion settings on the image block; labels vary by builder and version, so describe the effect you want rather than hunting for an exact menu name.
- Compress and correctly size the image before adding animation; a slow-loading image undercuts a smooth slide.
- Test with the browser's reduced-motion emulation to confirm the fallback works.
Troubleshooting
- The image does not move. Check that the class name in the HTML matches the CSS selector exactly, that the keyframes name matches the
animationshorthand, and that no other rule overridestransform. - The image is invisible. The start state is probably applied without the animation running. Confirm the animation name and duration are valid, and that the element is not inside a container with
display: none. - The animation runs before the image is visible on screen. Move the trigger to an intersection observer or a scroll-based class rather than page load.
- There is a horizontal scrollbar on mobile. Reduce the translate distance, or clip overflow on the immediate parent container.
- It stutters on older phones. Shorten the distance and duration, ensure only
transformandopacityanimate, and check the image file size. - It looks fine in the editor but not on the live site. Caching or a minifier may be serving old CSS. Clear the site cache and hard-refresh the browser.
Frequently Asked Questions
Can I slide an image without code?
Yes, if your site builder offers animation presets on image blocks. The setting names differ by builder and version, so look for motion, animation or effects in the block settings. The result is the same CSS transform underneath.
Does a slide animation hurt SEO?
No, as long as the image is in the HTML and not hidden from crawlers. Avoid starting with display: none or relying on JavaScript to insert the image, because that can delay indexing.
Should the animation loop?
Usually no. Entrance animations should run once. Looping slides distract from reading and can be uncomfortable for some visitors.
What duration is best?
Between 0.3s and 0.8s for most content images. Anything longer feels slow, anything much shorter is easy to miss.
Can I slide a background image?
Yes, but animate a wrapper element's transform rather than the background-position property, which is slower. Keep the background image on the wrapper and slide the wrapper itself.
Why does the image jump at the end?
The animation is missing a fill mode. Add forwards to the animation shorthand so the final keyframe persists.