Learn How the CSS @keyframes and animation Properties Work

Tell us what’s happening:

Your code so far


<style>
  div {
    height: 40px;
    width: 70%;
    background: black;
    margin: 50px auto;
    border-radius: 5px;
  }

  #rect {
    animation-name: rainbow ;
    animation-duration: 4s; 
    
  }
  @keyframes rainbow ;
  
  { 0% {background-color: blue; }
  50%{ background-color: green; }
  100% {background-color: yellow; }
  }

  
  
</style>
<div id="rect"></div>

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/responsive-web-design/applied-visual-design/learn-how-the-css-keyframes-and-animation-properties-work

remove the ; after the @keyframes rainbow;. the solution should be below.

#rect {
animation-name: rainbow;
animation-duration: 4s;
}

@keyframes rainbow{
    0%{
      background-color: blue;
    }
       50%{
      background-color: green;
    }
          100%{
      background-color: yellow;
    }
  }
1 Like

Your code would be: @ngngocthang

1 Like

Hi There,

I have just done the same but it is still giving me error as below:

“The @keyframes rule should use the animation-name of rainbow.”

Could anybody help me out here?

div { height: 40px; width: 70%; background: black; margin: 50px auto; border-radius: 5px; } #rect { animation-name: rainbow; animation-duration: 4s; } @Keyframes rainbow { 0% { background-color: blue; } 50% { background-color: green; } 100% { background-color: yellow; } }

Change property name from background to background-color.

.

That is wrong you should do #rect {
animation-name: rainbow;
animation-duration: 4s;
}
@keyframes rainbow{
0%{
background-color: blue;
}
50%{
background-color: green;
}
100%{
background-color: yellow;
}
}