CSS pick a random color from array

This is not possible in CSS, which is firmly deterministic. You could do this with client-side JavaScript, though:

var colors = ['#ff0000', '#00ff00', '#0000ff'];
var random_color = colors[Math.floor(Math.random() * colors.length)];
document.getElementById('title').style.color = random_color;

If you’re using jQuery, the last line could become

$('#title').css('color', random_color);

Leave a Comment

tech