
In this tutorial i shall show you how to redirect from one page to another in html on button click.
Step 1 – Create a html document
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Step 2 – Create button in html document
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button>Click me</button>
</body>
</html>
In our above code example I have added a button. Now let’s redirect to another page using onclick attribute.
Step 3 – Add onclick attribute to button
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button onclick="location.href='https://www.google.com/'">Click me</button>
</body>
</html>
In above code you will see I have added onclick attribute with a “location.href” property and added a web address to that property to redirect to that webpage.
These were the steps to redirect from one page to another in html on button click.
You may also like: