Gradient Generator in javascript by Nitin Kumar Output View Horizontal Vertical HTML CSS JS Tidy Direction To Top To Right Top To Right To Right Bottom To Bottom To Left Bottom To Left To Left Top Colors background-image: linear-gradient(to left top, #977DFE, #6878FF); Refresh Copy HTML CSS JS Tidy .wrapper { display: flex; flex-wrap:wrap; padding: 25px; background: #fff; border-radius: 7px; } .wrapper .gradient-box { height: auto; width: 50%; border-radius: 7px; background: linear-gradient(to left top, #5665e9, #a271f8); } .wrapper .row { width: 40%; margin: 20px 10px; } .column{margin:20px} .select-box select { width: 100%; font-size: 1.12rem; } .palette input { height: 41px; width: calc(100% / 2 - 20px); } .row textarea { width: calc(100% - 40px); color: #333; font-size: 1.05rem; resize: none; padding: 10px 15px; border-radius: 5px; border: 1px solid #ccc; } .buttons button { padding: 15px 0; border: none; outline: none; color: #fff; margin: 0 0 -15px; font-size: 1.09rem; border-radius: 5px; cursor: pointer; transition: 0.3s ease; } .refresh { background: #6c757d; width: calc(100% / 2 - 20px); } .refresh:hover { background: #5f666d; } .copy { background: #8a6cff; width: calc(100% / 2 - 20px); } .buttons .copy:hover { background: #704dff; } @media only screen and (max-width: 767px){ .wrapper { width: 100%!important; padding: 10px; } .wrapper .gradient-box{ width: 100%; height: 400px; } .wrapper .row { width: 100%; margin: 0px; } } HTML CSS JS Tidy const gradientBox = document.querySelector(".gradient-box"); const selectMenu = document.querySelector(".select-box select"); const colorInputs = document.querySelectorAll(".colors input"); const textarea = document.getElementById("textarea"); const refreshBtn = document.querySelector(".refresh"); const copyBtn = document.querySelector(".copy"); const getRandomColor = () => { const randomHex = Math.floor(Math.random() * 0xffffff).toString(16); return `#${randomHex}`; }; const generateGradient = (isRandom) => { if (isRandom) { colorInputs[0].value = getRandomColor(); colorInputs[1].value = getRandomColor(); } const gradient = `linear-gradient(${selectMenu.value}, ${colorInputs[0].value}, ${colorInputs[1].value})`; gradientBox.style.background = gradient; textarea.value = `background: ${gradient};`; }; const copyCode = () => { navigator.clipboard.writeText(textarea.innerHTML); copyBtn.innerText = "Code Copied!!"; setTimeout(() => (copyBtn.innerText = "Copy"), 1600); }; colorInputs.forEach((input) => { input.addEventListener("input", () => generateGradient(false)); }); selectMenu.addEventListener("change", () => generateGradient(false)); refreshBtn.addEventListener("click", () => generateGradient(true)); copyBtn.addEventListener("click", copyCode); >_Console Clear Console >_Console File Setting HTML Code Playground Setting Title Description Gradient Generator in JavaScript, HTML, and CSS. Without any external library. Catagory Javascript Tags Resource Add External Stylesheets and Script