HTML - <header> Tag



The HTML <header> tag is used to represent introductory content for an HTML document or section. It specifies a header for the document.This element can define a global site header and some headings elements also includes a logo, company name, a search input field, an author name, global navigation, and other elements.

The <header> element originally existed at the beginning of HTML for headings and is the first to be seen on a webpage.

Syntax

Following is the syntax of the <header> tag −

<header>.....</header>

Example

The following program shows the usage of the HTML <header> tag.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML header tag</title>
</head>
<body>
   <!--create header tag-->
   <p>'header' element(tag) example</p>
   <header>
      <h1>HTML</h1>
      <p>Full form of above content: Hyper Text Markup Language.</p>
   </header>
</body>
</html>

When we run the above code, it will generate an output consisting of the ltext displayed on the webpage.

Example

Consider the following example, where we are going to use the <header> tag and applying the CSS properties.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML header tag</title>
   <style>
      header {
         color: green;
         font-style: italic;
      }
   </style>
</head>
<body>
   <!--create header tag-->
   <p>'header' element(tag) example</p>
   <header>
      <h1>Cricket</h1>
      <p>I love playing and watching cricket matches. My favorite player is Virat Kohli.</p>
   </header>
</body>
</html>

On running the above code, the output window will pop up, consisting of the text along with a CSS applied displayed on the webpage.

Example

In this example, we are going to use the <header> tag with the anchor element

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML header tag</title>
   <style>
      header {
         color: rgb(4, 78, 138);
         font-style: italic;
      }

      .demo {
         background: left / cover url("91442692.webp");
         height: 120px;
         display: flex;
         align-items: center;
         justify-content: center;
         color: white;
         font-size: 20px;
         text-decoration: none;
      }
   </style>
</head>
<body>
   <!--create header tag-->
   <p>'header' element(tag) example</p>
   <header>
      <a class="demo" href="#">Gaming laptop</a>
   </header>
   <article>
      <header>
         <h2>HTML</h2>
         <p>Hyper Text Markup Language</p>
      </header>
      <p>HTML is a standard markup language for documents designed to displayed in a web browser.</p>
   </article>
</body>
</html>

When we run the above code, it will generate an output consisting of the image along with a text displayed on the webpage.

Example

Let's look at the another scenario , where we are going to use the <footer> tag with the search input field.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML header tag</title>
</head>
<body>
   <!--create header tag-->
   <p>'header' element(tag) with search input field example</p>
   <header>
      <form>
         <input type="search">
      </form>
   </header>
   <article>
      <header>
         <p>Enter something to search in above input search field(it just demo example).</p>
      </header>
   </article>
</body>
</html>

When we run the above code, it will generate an output consisting of the input field along with a text displayed on the webpage.

html_tags_reference.htm
Advertisements