Color Palette Generator
Home
Snippets
Color Palette Generator
HTML
CSS
JS
<div class="widget"> <h2>Color Palette Generator</h2> <div class="palette" id="palette"></div> <button id="generate">Generate Palette</button> </div>
body { font-family: Arial, sans-serif; background: #f5f5f5; display:flex; justify-content:center; align-items:center; height:100vh; margin:0; } .widget { background: #fff; border-radius: 12px; padding: 20px; box-shadow: 0 6px 18px rgba(0,0,0,0.1); width: 320px; text-align: center; } .widget h2 { margin-top:0; color: #333; } .palette { margin: 15px 0; display: flex; flex-wrap: wrap; gap: 5px; } .color-row { display: flex; align-items: center; cursor: pointer; padding: 6px 5px; border-radius: 6px; transition: transform 0.2s, background 0.2s; } .color-row:hover { transform: scale(1.02); background: rgba(0,0,0,0.03); } .color-box { width: 15px; height: 15px; border-radius: 6px; margin-right: 12px; flex-shrink: 0; border: 1px solid #ccc; } .color-code { font-size: 14px; color: #555; font-family: monospace; } button { background: #00bfa5; color: #fff; border: none; padding: 10px 16px; border-radius: 6px; cursor: pointer; transition: background 0.2s; margin-top: 10px; } button:hover { background: #008f7f; }
const paletteEl = document.getElementById('palette'); const generateBtn = document.getElementById('generate'); function randomColor() { return '#' + Math.floor(Math.random()*16777215).toString(16).padStart(6,'0'); } function generatePalette() { paletteEl.innerHTML = ''; for(let i=0;i<5;i++){ const color = randomColor(); const row = document.createElement('div'); row.className = 'color-row'; const box = document.createElement('div'); box.className = 'color-box'; box.style.background = color; const code = document.createElement('div'); code.className = 'color-code'; code.innerText = color; row.appendChild(box); row.appendChild(code); row.addEventListener('click', ()=> { navigator.clipboard.writeText(color).then(()=> { alert(color + ' copied to clipboard!'); }); }); paletteEl.appendChild(row); } } generatePalette(); generateBtn.addEventListener('click', generatePalette);
Ad #1
Ad #2
Scroll to Top