Fade Out Div After Page Load Using HTML / CSS / Vanilla Javascript
Posted: Sun Mar 02, 2025 11:14 pm
Code: Select all
<!DOCTYPE html>
<html>
<head>
<title>Fade Out Div</title>
<style>
#myDiv {
background-color: lightblue;
padding: 20px;
transition: opacity 1s ease-in-out;
}
</style>
</head>
<body>
<div id="myDiv">
This div will fade out after 3 seconds.
</div>
<script>
window.addEventListener('load', function() {
setTimeout(function() {
const myDiv = document.getElementById('myDiv');
myDiv.style.opacity = 0;
}, 3000);
});
</script>
</body>
</html>