
Discover a splash of inspiration with every click! Our Random Color Generator instantly gives you fresh, vibrant color codes — perfect for designers, developers, and creatives. Whether you’re building a palette or just exploring shades, it’s your go-to tool for colorful ideas. Just tap and create!
Day 7 Random Color Generator
Random Color Generator
body {
margin: 0;
font-family: cursive;
}
h1 {
text-align: center;
}
.container {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.color-container {
background-color: orange;
width: 300px;
height: 150px;
color: white;
margin: 5px;
display: flex;
justify-content: center;
align-items: center;
font-size: 25px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
border: solid black 2px;
border-radius: 10px;
}
const containerA = document.querySelector('.container');
for(index = 0; index < 12 ; index++){
const colorContainerA = document.createElement('div');
colorContainerA.classList.add("color-container");
containerA.appendChild(colorContainerA);
}
const colorContainers = document.querySelectorAll('.color-container');
generateColors();
function generateColors(){
colorContainers.forEach(colorContainerA => {
const newColorCode = randomColor();
colorContainerA.style.backgroundColor = "#" + newColorCode;
colorContainerA.innerText = "#" + newColorCode;
});
}
function randomColor(){
const chars = "0123456789ABCDEF";
const colorCodeLenght = 6;
let colorCode = "";
for (index = 0 ; index < colorCodeLenght; index++){
const randomNum = Math.floor(Math.random()* chars.length);
colorCode += chars.substring(randomNum, randomNum + 1);
}
return colorCode;
}
Ghulam Ahmad is an Excellent Writer, His magical words added value in growth of our life. Highly Recommended
- Fazal Rehman Tweet
2 Responses