CSS border color switch animation: “from” color not correct

According to the documenation steps(2,start) will give this timing output:

enter image description here

So you will spend 0 time on the first state, half the time on the 50% (light blue) and half the time on the 100% (blue). You will have a similar logic using end instead of start where you will spend 0 time on the last state. Actually what you are looking for is the frames function but it’s actually under draft and using frames(2) you will do exactly what you want:

enter image description here

An easy fix is to change the values of the keyframes to force each color to stay half the animation without using steps

.switch {
  width: 100px;
  height: 100px;
  border: 5px solid white;
  animation: switch-animation 2s infinite linear;
}

@keyframes switch-animation {
  0%,50% {
    border-color: white;
  }
  50.1%,100% {
    border-color: blue;
  }
}
<div class="switch"></div>

Leave a Comment