YouTip LogoYouTip

Prop Meta Httpequiv

## HTML DOM Meta httpEquiv Property The `httpEquiv` property sets or returns the value of the `http-equiv` attribute of a `` element. The `http-equiv` attribute provides an HTTP header for the information/value of the `content` attribute. It essentially allows developers to simulate HTTP response headers directly within the HTML document. --- ## Definition and Usage * The `httpEquiv` property is used to define an instruction that can alter the behavior of the browser or how the page is processed. * The value of the `http-equiv` attribute depends on what is specified in the companion `content` attribute. * **Note:** If the `name` attribute is already set on the `` tag, the `http-equiv` attribute should not be used. --- ## Syntax ### Get the httpEquiv property: ```javascript var x = metaObject.httpEquiv; ``` ### Set the httpEquiv property: ```javascript metaObject.httpEquiv = "HTTP-header"; ``` *(Note: In the DOM, this property is accessed via the `HTMLMetaElement` object).* --- ## Common HTTP-Header Values Below are the standard and commonly used values for the `http-equiv` attribute: | Value | Description | Example | | :--- | :--- | :--- | | **cache-control** | Controls the caching mechanism of the document.

**Allowed values:**
β€’ `public` - Anyone can cache the content (client and proxy servers).
β€’ `private` - Only the client browser can cache the content.
β€’ `no-cache` - The browser must revalidate with the server before using a cached copy.
β€’ `no-store` - The browser and proxies must not cache or store any part of the page. | `` | | **content-language** | Specifies the primary language of the document. | `` | | **content-type** | Declares the MIME type and character encoding of the document. | `` | | **date** | Specifies the date and time the document was generated. | `` | | **expires** | Specifies the date and time after which the document is considered expired. | `` | | **last-modified** | Specifies the date and time the document was last modified. | `` | | **location** | Used to redirect the client to another URL. | `` | | **refresh** | Defines a time interval (in seconds) after which the page should automatically reload or redirect to another URL. | `` *(Refreshes every 5 minutes)* | | **set-cookie** | Sets a cookie on the client side. Defines cookie name, value, expiration, and path. | `` | | **window-target** | Specifies the target window or frame in which the page should be loaded. | `` | --- ## Browser Support The `httpEquiv` property is fully supported by all major modern web browsers: * Google Chrome * Mozilla Firefox * Microsoft Edge / Internet Explorer * Safari * Opera --- ## Code Examples ### Example 1: Get the http-equiv Attribute Value The following example demonstrates how to retrieve the value of the `http-equiv` attribute from the first `` tag in the document. ```html YouTip - httpEquiv Example

Click the button below to display the value of the meta tag's http-equiv attribute.

``` ### Example 2: Dynamically Setting http-equiv You can also dynamically change or set the `httpEquiv` property using JavaScript: ```javascript // Select the meta element var metaTag = document.getElementsByTagName("meta"); // Set the http-equiv to refresh the page metaTag.httpEquiv = "refresh"; metaTag.content = "10"; // Refreshes the page every 10 seconds ``` --- ## Considerations and Best Practices 1. **HTML5 Standard:** In HTML5, setting the character encoding using `` is still supported, but the shorter syntax `` is highly recommended for simplicity and performance. 2. **Security Restrictions:** Modern browsers may ignore certain `http-equiv` directives (like `set-cookie`) when set via `` tags due to security policies (such as HTTPOnly cookies). It is always safer to set cookies and security policies (like CSP) via actual server-side HTTP headers. 3. **Performance:** Using `` for redirection is generally discouraged for SEO and accessibility reasons. A server-side 301 or 302 redirect is preferred.
← Prop Meta NameProp Meta Content β†’