How to Redirect a Web Page in HTML

To tell search engines and website visitors that your web page has permanently moved to a new location with an equivalent content use a 301 redirect. The code “301” is interpreted as “moved permanently”. (Learn more about HTTP Status Codes).

How to redirect to another URL

The simplest way to redirect to another URL is to use an HTML <meta> tag with the http-equiv parameter set to “refresh”. The content attribute sets the delay before the browser redirects the user to the new web page. To redirect immediately, set this parameter to “0” seconds for the content attribute.

<meta http-equiv="Refresh" content="0; url='https://www.w3docs.com'" />

If you want your redirection to occur in an exact time, just specify your preferred parameter (in seconds) for the content. Let’s consider an example, where we set "7" seconds as redirection time.

Some browsers don't render the <meta> refresh tag correctly, so before the next page loads, the user can see a flash as a page.
<meta http-equiv="refresh" content="7; url='https://www.w3docs.com'" />

Some old browsers don't refresh correctly when you add a quick link. In that case, you can add an anchor link to let the user follow.

Example of redirecting a web page:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="refresh" content="7; url='https://www.w3docs.com'" />
  </head>
  <body>
    <p>You will be redirected to w3docs.com soon!</p>
  </body>
</html>

How to redirect to a new page without leaving the current page:

If you want to redirect to another website without leaving the current website and open a link that redirects to an HTML document, you can use the anchor tag with the "target" attribute set to "_blank". This will open the link in a new window or tab, while the current website remains open.

Here's an example of how to use it:

<!DOCTYPE html>
<html>
  <head>
    <title>Redirecting without leaving the current page</title>
  </head>
  <body>
    <a href="https://www.w3docs.com" target="_blank">Click here to go to W3docs.com</a>
  </body>
</html>

In this example, clicking on the link will open "https://www.w3docs.com" in a new window or tab, while the current website remains open.

If you want to redirect to an HTML document instead of a website, you can use the same method by setting the link's href attribute to the path of the HTML document you want to redirect to.

Here's an example:

<a href="example.html" target="_blank">Click here to open Example.html</a>

In this example, clicking on the link will open "example.html" in a new window or tab while the current website remains open.

Learn more about redirecting web pages with JavaScript, PHP, Apache and Node.js.