<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic Font and Color Change</title>
<style>
body {
font-family: Arial, sans-serif;
}
#userInput {
margin-bottom: 20px;
width: 100%;
padding: 10px;
font-size: 16px;
}
#output {
font-size: 24px;
}
</style>
</head>
<body>
<input type="text" id="userInput" placeholder="Type something to change font and color">
<div id="output">This text will change based on your input.</div>
<script>
const inputElement = document.getElementById('userInput');
const outputElement = document.getElementById('output');
inputElement.addEventListener('input', function() {
const userInput = inputElement.value;
outputElement.textContent = userInput;
// Change font style
outputElement.style.fontFamily = 'Arial, sans-serif';
// Change text color
outputElement.style.color = getRandomColor();
});
function getRandomColor() {
const letters = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
</script>
</body>
</html>
Comments
Post a Comment