Skip to content

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 equivalent content, use a 301 redirect. The code “301” is interpreted as “moved permanently” and is handled by the server. (Learn more about HTTP Status Codes).

If you need to perform a redirect directly within an HTML document (client-side), you can use the <meta> refresh tag.

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.

Example of how to redirect a web page in HTML with the <meta> tag

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

If you want the redirection to occur after a specific delay, set the content attribute to your preferred number of seconds. For example, to redirect after 7 seconds:

WARNING

Some browsers don't render the <meta> refresh tag correctly, so before the next page loads, the user might see a flash of the current page.

Example of how to redirect a web page in HTML after a delay

html
<meta http-equiv="refresh" content="7; url=https://www.w3docs.com" />

Some older browsers don't handle quick redirects correctly. In that case, you can add an anchor link to let the user navigate manually.

Example of redirecting a web page:

Example of how to redirect a web page in HTML

html
<!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>

If you want to open a link in a new window or tab without closing the current page, you can use the anchor tag with the target attribute set to _blank. Note that this is a navigation technique, not a page redirect.

Here's an example of how to use it:

Opening a link in a new tab

html
<!DOCTYPE html>
<html>
  <head>
    <title>Opening a link in a new tab</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 navigate to an HTML document instead of an external website, you can use the same method by setting the link's href attribute to the path of the HTML document.

Here's an example:

html
<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.

Dual-run preview — compare with live Symfony routes.