---
title: "Script to Dynamically Change Background Color"
url: "https://www.marrisonlab.com/script-to-dynamically-change-background-color/"
type: "post"
published: "2025-10-21T19:45:01+02:00"
modified: "2026-07-06T13:39:27+02:00"
author: "Angelo Marra"
---

This JavaScript snippet automatically assigns a random background color to every element with the class ***bg-change**.*

It selects all matching elements, generates a new hexadecimal color for each, and applies it directly to the style, adding a dynamic and vibrant visual touch to the page. Ideal for creating eye-catching UI effects with just a few lines of code.

 
