Random HTML Colors
Home
Snippets
Random HTML Colors
HTML
CSS
JS
<h1>HTML Colors Preview</h1> <div class="color-container" id="colorContainer"></div>
body { font-family: Arial, sans-serif; margin: 0; padding: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; background: #f4f4f4; } h1 { margin-bottom: 20px; color: #333; } .color-container { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 15px; padding: 20px; width: 90%; max-width: 800px; } .color-box { display: flex; flex-direction: column; align-items: center; justify-content: center; border: 1px solid #ddd; border-radius: 8px; padding: 15px; background: white; transition: transform 0.2s, box-shadow 0.2s; } .color-box:hover { transform: scale(1.05); box-shadow: 0 4px 10px #00000033; } .color-preview { width: 100%; height: 50px; margin-bottom: 10px; border-radius: 5px; } .color-name { font-size: 14px; font-weight: bold; text-transform: capitalize; color: #444; }
const htmlColors = [ "red", "blue", "green", "yellow", "orange", "purple", "pink", "cyan", "magenta", "lime", "teal", "gold", "silver", "brown", "coral", "khaki", "indigo", "salmon", "plum", "navy", "maroon" ]; const container = document.getElementById("colorContainer"); htmlColors.forEach(color => { const box = document.createElement("div"); box.className = "color-box"; const preview = document.createElement("div"); preview.className = "color-preview"; preview.style.backgroundColor = color; const name = document.createElement("p"); name.className = "color-name"; name.textContent = color; box.appendChild(preview); box.appendChild(name); container.appendChild(box); });
Ad #1
Ad #2
Scroll to Top