HTML - content Attribute



The HTML content attribute is used to display/contain the value for the name or HTTP-equiv attribute, depending on which is used.This attribute is used with the <meta> tag. Which sets the information for meta elements in an HTML document.

The HTTP-equiv attribute is used to provide an HTTP header for the value of the content attribute.

The HTTP-equiv attribute accepts a value as refresh. It defines a time interval for the document to refresh itself concerning the content attribute value.

Syntax

Following is the syntax for HTML content attribute −

<meta content = "value"></meta>

Example

In the following example, we are going to use the content attribute with the meta element.

<!DOCTYPE html>
<html lang="en">
<head>
   <meta content="Enroll course for free">
   <title>HTML 'content' attribute</title>
</head>
<body>
   <!--HTML 'content' attribute-->
   <p>Example of the HTML 'content' attribute</p>
   <h3>Course lists:</h3>
   <ul>
      <li>HTML</li>
      <li>CSS</li>
      <li>JavaScript</li>
      <li>Angular</li>
   </ul>
</body>
</html>

On running the above code, the output window will pop up displaying the list items in the bullet format on the webpage.

Example

The following is another example of the HTML ‘content’ attribute. Here, the ‘content’ attribute is used within the <meta> element to contain the value for the HTTP-equiv attribute.

We assign the ‘refresh’ string as a value to the HTTP-equiv attribute, which will refresh the document concerning the time interval (i.e. content attribute value).

<!DOCTYPE html>
<html lang="en">
<head>
   <!--content attribute-->
   <meta http-equiv="refresh" content="30">
   <title>HTML 'content' attribute</title>
</head>
<body>
   <!--HTML 'content' attribute-->
   <p>Example of the HTML 'content' attribute</p>
   <h1>Text within the h1 heading...</h1>
</body>
</html>

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

html_attributes_reference.htm
Advertisements