My Development Notes

Programming Made Easier


How to create moving text animation from right to left using CSS animation

Here’s how you can create a moving text animation using HTML and CSS using @keyframes keyword :

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Moving Text Panel Animation</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <div class="text-panel">
      <p>
        Lorem ipsum dolor sit amet consectetur, adipisicing elit. Facere omnis
        voluptatum quam numquam recusandae dolorum unde voluptates saepe!
        Laudantium ab fugiat, eos omnis modi, tempora magni tenetur dolores
      </p>
    </div>
  </body>
</html>
body {
  margin: 0;
  overflow: hidden;
}

.text-panel {
  background-color: antiquewhite;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
}

p {
  font-size: 25px;
}

.text-panel p {
  display: inline-block;
  animation: runningText 15s linear infinite;
}

@keyframes runningText {
  0% {
    transform: translateX(100%);
  }
  100% {
    transform: translateX(-100%);
  }
}

Posted

in

by

Tags:

Leave a Reply