Open In App

How to redirect to another webpage in HTML?

Last Updated : 06 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

It is often required to redirect to another webpage on loading a webpage, for example, due to the contents being moved to the new webpage. Demonstrated here are two simple methods to redirect to another webpage on load.

Method-1: Using http-equiv attribute of the meta tag in HTML.

Syntax:

<meta http-equiv="refresh" content="seconds; url=URL">

Example-1:

html
<!DOCTYPE HTML>
<html>

<head>
    <title>
        Redirect to GeeksforGeeks
    </title>
    <!-- meta tag to redirect to 
     ide.geeksforgeeks.org after 2 seconds -->
    <meta http-equiv="refresh"
          content="2; 
                url=https://www.geeksforgeeks.org/community/">
</head>

<body>
    <!-- Link to the destination page 
      in case the refresh does not work -->
    You will be redirected to GeeksforGeeks in a moment.
    <br> 
    If you are not redirected automatically, 
    <a href="https://www.geeksforgeeks.org/community/">
      click here
    </a>.
</body>

</html>

Output:

Redirect-Page

Redirect to anther webpage In HTML


Note: In some older browsers, like Internet Explorer 6, refresh may cause unexpected results and impair the browser’s Back button. This is compensated for in most modern browsers (Internet Explorer 7 and higher, Google Chrome, Mozilla Firefox, Microsoft Edge).

Method-2: Using location.href in JavaScript

Syntax:

window.location.href = "URL"

Example-2:

html
<!DOCTYPE HTML>
<html>

<head>
    <title>
        Redirect to GeeksforGeeks
    </title>
    <script type="text/javascript">
      
        /* location.href used to
        redirect to ide.geeksforgeeks.org */
        window.location.href =
          "https://www.geeksforgeeks.org/community/"
    </script>
</head>

<body>
    <!-- Link to the destination page in
     case the redirect does not work -->
    You will be redirected to GeeksforGeeks in a moment.
    <br>
    If you are not redirected automatically, 
  <a href="https://www.geeksforgeeks.org/community/">
    click here 
   </a>.
</body>

</html>

Output:

RedirecttoanotherPage

Redirect to another webpagae in HTML

Note: This method works fine for any JavaScript enabled browser.




Next Article
Article Tags :

Similar Reads