• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

IntenseClick

  • Home
  • WordPress
  • Ethical Hacking
  • Coding
Home » Change HTML webpage color randomly on refresh and interval

Change HTML webpage color randomly on refresh and interval

April 30, 2023 by ιnтenѕeclιcĸ Team Leave a Comment

Here’s an example JavaScript code that generates random background and text colors for an HTML document:

<!DOCTYPE html>
<html>
<head>
	<title>Random Color Change</title>
	<style>
		body {
			background-color: #ffffff;
			color: #000000;
			font-size: 36px;
			text-align: center;
			padding-top: 100px;
		}
	</style>
</head>
<body>
	<script>
		function getRandomColor() {
			var letters = "0123456789ABCDEF";
			var color = "#";
			for (var i = 0; i < 6; i++) {
				color += letters[Math.floor(Math.random() * 16)];
			}
			return color;
		}

		function changeColors() {
			var backgroundColor = getRandomColor();
			var textColor = getRandomColor();
			document.body.style.backgroundColor = backgroundColor;
			document.body.style.color = textColor;
		}

		setInterval(changeColors, 1000);
	</script>
</body>
</html>


The getRandomColor function generates a random hexadecimal color code, and the changeColors function sets the background and text colors of the HTML body element to random colors using the style property. The setInterval function is used to call the changeColors function every second, causing the colors to change randomly over time.

More tech articles

Generate secure and random password using PHP
Service host superfetch – slow pc ,high disk usage, disk full fix(svchost.exe)
Service Host Superfetch
What is Service Host Superfetch and How to Fix it
How To Fix Microsoft Compatibility Telemetry High Disk Usage Issue On Windows
PHP code for login page script
How to Install Maven on Windows 2023 | Project management tool for Java applications

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Footer

insightful tech editorials to distribute useful tech guides and resources for free.

[email protected]

  • About us
  • Guest Post/Content Writing
  • Terms & Conditions
  • Privacy Policy
  • Disclaimer
  • Contact us

ιnтenѕeclιcĸ · © 2025