HTML - http-equiv Attribute



The HTML http-equiv attribute is used to define the pragma directive. Pragma directives correspond to headers for describing metadata.

This attribute is named http-equiv, because all the allowed values are names of particular HTTP headers.

If the value of the http-equiv attribute is set to refresh and the content attribute accepts the time interval and URL of any website or page, it will refresh the page and redirect it to the given URL after the time interval.

The refresh instruction specifies the number of seconds until the page should be reloaded, only if the content attribute contains a non-negative value.

Following are the list of values supported by the http-equiv –

  • content-security-policy
  • content-type
  • default-style
  • x-ua-compatible
  • refresh

Syntax

Following is the syntax for HTML http-equiv attribute −

<meta http-equiv = "value"></meta>

Example

In the following example, the HTML 'http-equiv' attribute is used within an <meta> element to define a pragma directive. We specify the string "refresh" as the value of this attribute which defines that the page should refresh with respect to the time interval.

<!DOCTYPE html>
<html lang="en">
<head>
   <!--http-equiv attribute-->
   <meta http-equiv="refresh" content="10">
   <title>HTML 'http-equiv' attribute</title>
</head>
<body>
   <!--HTML 'content' attribute-->
   <p>Example of the HTML 'http-equiv' attribute</p>
   <h3>The page should be refreshed automatically with respect to the time interval.</h3>
</body>
</html>

When we run the above code, it will generate an output consisting of the text on the webpage. after certain time interval the webpage gets refreshed on its own.

Example

Cponsider the another scenario, where we are going to use the ‘http-equiv’ attribute within the <meta> tag to define the pragma directive.

<!DOCTYPE html>
<html lang="en">
<head>
   <!--http-equiv attribute-->
   <meta http-equiv="refresh" content="10; url = https://www.tutorialspoint.com/index.htm">
   <title>HTML 'http-equiv' attribute</title>
</head>
<body>
   <!--HTML 'http-equiv' attribute-->
   <p>Example of the HTML 'http-equiv' attribute</p>
   <p>The page will redirect to the Tutorialspoint website after the given time interval.</p>
</body>
</html>

On running the above code, the output window will pop up displaying the text on the webpage it will gets refreshed for evry 10seconds on its own and redirects.

html_attributes_reference.htm
Advertisements