DEV Community

Aslam Shah
Aslam Shah

Posted on

10 2

πŸ’‘ Animate newly added HTML elements with CSS

We all have been in a situation where we need to animate newly added HTML elements. We tinker with timeouts, initial state or any other scripting logic to add/remove classes etc.

If you want a simple solution, here is one for you. It only uses a single animation keyframe to take care of the newly added elements. CSS Animations with take care of the default state based on the initial element styles.

@keyframes animate {
  100% {
    opacity: 1;
  }
}
Enter fullscreen mode Exit fullscreen mode

You can also play with the properties using css transforms to achieve the animation you need.

In the example below you have 2 versions.
Normal Item which uses opacity to create a fadeIn effect while the Fancy Item also has some transform properties attached to it.

Enjoy! :)

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay