<!DOCTYPE html>
<html>
<head>
<style>
#scrollUpButton {
display: none;
position: fixed;
bottom: 20px;
right: 30px;
z-index: 99;
border: none;
outline: none;
background-color: #007bff;
color: white;
cursor: pointer;
padding: 10px 20px;
border-radius: 5px;
}
#scrollUpButton:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<button id="scrollUpButton" onclick="scrollToTop()">Up</button>
<script>
function scrollToTop() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
}
window.onscroll = function() {
scrollFunction();
};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
document.getElementById('scrollUpButton').style.display = 'block';
} else {
document.getElementById('scrollUpButton').style.display = 'none';
}
}
</script>
</body>
</html>