JSFiddle - React, Tailwind, and code Playground
HTML
<html>
<body onload="scrollInView()">
<h1>Testing</h1>
<h1>Testing</h1>
<h1>Testing</h1>
<h1>Testing</h1>
<h1>Testing</h1>
<h1>Testing</h1>
<h1>Testing</h1>
<h1>Testing</h1>
<h1>Testing</h1>
<h1>Testing</h1>
<h1>Testing</h1>
<h1>Testing</h1>
<h1>Testing</h1>
<h1>Testing</h1>
<h1>Testing</h1>
<h1>Testing</h1>
<h1>Testing</h1>
v
<h1>Testing</h1>
<h1>Testing</h1>
<h1>Testing</h1>
<h1 id='testing'>Testing</h1>
<script>
function scrollInView() {
const url = window.location.href;
const hashIndex = url.lastIndexOf("#");
const id = url.substr(hashIndex+1, url.length - (hashIndex+1));
const elem = document.getElementById(id);
if(elem) {
elem.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'end' });
}
}
</script>
</body>
</html>