CSS Float animation effect

CSS Float animation

We can achieve a simple floating CSS animation effect by applying the transform#translate CSS transform function.

<style> .float { /* Uncomment as needed. */ /* width: 100px; */ /* height: 100px; */ /* background-color: deeppink; */ animation-name: float; animation-duration: 4s; animation-iteration-count: infinite; } @keyframes float { 0% { transform: translate(0, 50%); } 20% { transform: translate(0, -50%); } 30% { transform: translate(0, -20%); } 50% { transform: translate(0, -50%); } 60% { transform: translate(0, -30%); } 80% { transform: translate(0, -60%); } 100% { transform: translate(0, -40%); } } </style>
    Hints:
  • If you cannot see your HTML element when using our code, you may need to set a width and or height, or background on your target HTML element using CSS. Just uncomment the CSS properties in our code as needed.
  • Remove the HTML style tag as needed.
  • Change values in the code such as animation-duration as needed.
Animation effects source code licenced under MIT Licence