Animation on Page Load: NEED HELP!

I’m making a site that has animations on the screen load. The first animation I created was on a h1. I’m trying to make it not show up for a second before playing the animation.

CSS Snipet:

@keyframes slideLeftandFadeIn {
  0% {
    transform: translateX(-100%);
    opacity: 0;
  }
  100% {
    transform: translateX(0);
    opacity: 1;
  }
}

section.pt1 {
  background-image: url("imgs/bg-img-1.jpeg");
  background-size: cover;
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

h1.pt1 {
  color: white;
  font-family: "Tektur";
  font-weight: "Black";
  animation: 1.5s ease-in-out 1s slideLeftandFadeIn;
  /* margin-bottom: -5px; */
}

Link: https://replit.com/@RedCoder/Trying-to-make-new-website?v=1

Just set the opacity to 0

h1.pt1 {
  color: white;
  font-family: "Tektur";
  font-weight: "Black";
  opacity: 0; /*  set the opacity to 0 */
  animation: 1.5s ease-in-out 1s forwards slideLeftandFadeIn; /* and add forwards to persist the end state */
  /* margin-bottom: -5px; */
}
2 Likes

I tried that but after the animation plays, it sets back to 0 opacity

Did you use forwards?

Without forwards , the h1 will become invisible again because of the opacity: 0 rule outside the animation.

1 Like

Great, it works! Thank you so much for all the help!

1 Like

This one. That’s why I included forwards.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.