Animate CSS padding-left property

The CSS padding-left property can be animated to create smooth transitions that change the left padding of an element over time. This creates a visual effect where content moves horizontally as the padding increases or decreases.

Syntax

selector {
    animation: animation-name duration timing-function;
}

@keyframes animation-name {
    from { padding-left: initial-value; }
    to { padding-left: final-value; }
}

Example

The following example animates the padding-left property from 0px to 50px and back −

<!DOCTYPE html>
<html>
<head>
<style>
    .animated-box {
        width: 300px;
        height: 100px;
        background-color: #3498db;
        color: white;
        display: flex;
        align-items: center;
        border: 2px solid #2980b9;
        animation: paddingAnimation 2s ease-in-out infinite;
    }
    
    @keyframes paddingAnimation {
        0% { padding-left: 10px; }
        50% { padding-left: 60px; }
        100% { padding-left: 10px; }
    }
</style>
</head>
<body>
    <h2>Animated Padding Left</h2>
    <div class="animated-box">Watch me move!</div>
</body>
</html>
A blue box with white text "Watch me move!" appears. The text smoothly moves from left to right and back as the padding-left animates from 10px to 60px continuously over 2 seconds.

Conclusion

Animating the padding-left property creates smooth horizontal movement effects. Use keyframes to define different padding values at various points in the animation timeline for dynamic visual effects.

Updated on: 2026-03-15T13:35:28+05:30

532 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements