HTML - content Attribute



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

<meta content = "text"></meta>

Applies On

Below listed elements allow using of the HTML content attribute

Element Description
<meta> HTML <meta> tag is used to provide such additional information.

Example of HTML content Attribute

Bellow examples will illustrate the HTML content attribute, where and how we should use this attribute!

Mentioning content of HTML document

In the following example, we used content attribute of meta tag to mention the additional information of document. On running the below code, the output will be displaying list items in the bullet format on the webpage.

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

Content attribute to refresh webpage

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>

Supported Browsers

Attribute Chrome Edge Firefox Safari Opera
content Yes Yes Yes Yes Yes
html_attributes_reference.htm
Advertisements