File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed
Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < title > Background Color Changer</ title >
6+ < style >
7+ body {
8+ font-family : system-ui, Arial;
9+ text-align : center;
10+ transition : background-color 0.5s ease;
11+ height : 100vh ;
12+ display : flex;
13+ justify-content : center;
14+ align-items : center;
15+ flex-direction : column;
16+ }
17+ button {
18+ background : # 111827 ;
19+ color : white;
20+ border : none;
21+ padding : 10px 16px ;
22+ border-radius : 8px ;
23+ font-size : 16px ;
24+ cursor : pointer;
25+ margin-top : 20px ;
26+ }
27+ # colorCode {
28+ margin-top : 10px ;
29+ font-size : 20px ;
30+ font-weight : 600 ;
31+ }
32+ </ style >
33+ </ head >
34+ < body >
35+ < h2 > 🎨 Background Color Changer</ h2 >
36+ < button id ="changeColorBtn "> Change Color</ button >
37+ < p id ="colorCode "> #FFFFFF</ p >
38+
39+ < script >
40+ const button = document . getElementById ( "changeColorBtn" ) ;
41+ const colorCode = document . getElementById ( "colorCode" ) ;
42+
43+ function randomColor ( ) {
44+ // Generate random hex color
45+ const letters = "0123456789ABCDEF" ;
46+ let color = "#" ;
47+ for ( let i = 0 ; i < 6 ; i ++ ) {
48+ color += letters [ Math . floor ( Math . random ( ) * 16 ) ] ;
49+ }
50+ return color ;
51+ }
52+
53+ button . addEventListener ( "click" , ( ) => {
54+ const newColor = randomColor ( ) ;
55+ document . body . style . backgroundColor = newColor ;
56+ colorCode . textContent = newColor ;
57+ colorCode . style . color = newColor ;
58+ } ) ;
59+ </ script >
60+ </ body >
61+ </ html >
You can’t perform that action at this time.
0 commit comments