Skip to content

Change the color of a webpage dynamically using JS and CSS

The Valley of Code

Your Web Development Manual

Hereโ€™s how to dynamically change a web pageโ€™s colors using the CSS filter property and JavaScript:

<a href='javascript:document.querySelector("html").setAttribute("style","filter: saturate(60%) brightness(80%);")'>
  pastel
</a>

<a href='javascript:document.querySelector("html").setAttribute("style","filter: grayscale(100%); ")'>
  grayscale
</a>

<a href='javascript:document.querySelector("html").setAttribute("style","filter:  ")'>
  normal
</a>
โ†’ Get my JavaScript Beginner's Handbook
โ†’ Read my JavaScript Tutorials on The Valley of Code
โ†’ Read my TypeScript Tutorial on The Valley of Code
  • THE VALLEY OF CODE (+ PRO), your web development manual
  • I wrote 15+ free coding BOOKS, download them here
  • SOLOPRENEUR LAND the missing MBA for wannabe solopreneurs craving a life with more freedom, control, fulfillment and purpose (summer 2024)