If you want to create a smooth color transition without specifying a duration but adding a delay, you can do so by using the following CSS code:
html { background: red; transition: background 0s 5s; }
However, since there is no state change in this scenario, the transition won't take place. To achieve this effect, consider using JavaScript like the example below:
$('html').addClass('loaded');
With the corresponding CSS:
html { background: red; transition: background 0s 5s; }
html.loaded { background: blue; }
For a demonstration, check out this Fiddle
Remember to account for vendor prefixes when using the transition
property.
Using animations
To accomplish a color change without requiring JavaScript, you can utilize keyframes in CSS like so:
html {
background: blue;
animation: switchColor 5s;
}
@keyframes switchColor {
0% {
background: red;
}
99.9999% {
background: red;
}
100% {
background: blue;
}
}
Check out the demonstration on this Fiddle
Using pure jQuery
Alternatively, if you only wish to change the color instantly with no transition, you can use the setTimeout()
function in JavaScript:
setTimeout(function() {
$('html').css('background', 'blue');
}, 5000);
View the example on this Fiddle