Javatpoint Logo
Javatpoint Logo

<header> Tag in HTML

What is <header> Tag?

The <header> element define a page or section header. A logo, a search bar, links for navigation, etc., are often included.

This tag doesn't introduce a new outline section. The heading (an h1>-h6> element) of the section it surrounds is frequently contained in a header> element. However, it's not necessary.

One of the HTML5 components is the <header> tag. Multiple <header> tags may be used in an HTML page and positioned anywhere in the content.

The <header> tag cannot be used between another <header> tag and the <address> and <footer> components.

Syntax:

Header tags are used in pairs. Between the opening (header) and closing (/header) tags is where the content is located.

HTML Document Structure

We have learned that a typical HTML document will have the following structure.

We will go into great detail about the header portion of this article, which is represented by the HTML head> tag. The "head" tag is a container for several significant tags, including <title>, <meta>, <link>, <base>, <style>, <script>, and <noscript>.

Header Elements for HTML

The head section of an HTML page, which provides information about the document, is defined by the <head> element. The <head> tag contains the header components, such as <title>, <meta>, <link>, <style>, and so on.

An HTML document's head is a section of the document whose content is not seen by the user when the page loads in the browser. Only HTML document metadata information about the HTML document is included.

1. <title> Element in HTML

A title for a web page is added using the title element in HTML. Search engines rank and index websites using the page title. In the example below, we've given a Hello World web page.

The output that appears in the browser when you run the HTML code above is as follows.

Output:

HTML Header Tag

The title of the document is specified via the HTML <title> element. The page's tab or the browser's title bar displays the title, which must only be text. HTML pages must have the <title> element.

  • Creates a title for the toolbar of the browser
  • It gives the page's title when it is added to your favorites.
  • It will show the page's title in search engine results.

Therefore, ensure the title is as precise and relevant as possible.

2. <style> Element in HTML

Internal styling for a web page is added using the HTML style element. In an HTML page, style components are always contained within the head tag. Internal styling is a fantastic choice if we only want to style a few items.

Example:

The output that appears in the browser when you run the HTML code above is as follows.

Output:

HTML Header Tag

3. <link> Element in HTML

Use the link element in an HTML page to link external files, stylesheets, icons, etc. The syntax is listed below.

The rel attribute in HTML is used to specify the connection between a linked document and an HTML document.

Example:

The above program will lead to the outcome shown below.

Output:

HTML Header Tag

4. <meta> Element in HTML

The HTML <meta> tag holds information or metadata utilized by browsers and search engines but isn't visible on the page. The <meta> element is often used to describe the character set, page description, keywords, document author, and viewport settings. Please look at the example below for a better understanding.

Output:

HTML Header Tag

5. <base> Element in HTML

A base URL is supplied for relative links using the HTML base> element. All relative links inside the document will utilize that URL as their beginning point if the base URL is set inside the page head element.

Every relative URL on the page will begin with www.abc.com/, for instance, if the URL defined by the base tag is www.abc.com. There may only be one base element in an HTML page, which must have the href and target attributes.

Example:

Output:

HTML Header Tag

6. <script> Element in HTML

Both internal and external scripts may be added using the HTML script element. In an HTML page, the script tag is always positioned within the body tag. The src attribute found inside a script opening element may be used to include external scripts.

Internal Script:

External Script:

Example:

Output:

HTML Header Tag

When we click on the button, we get the following result.

HTML Header Tag
Next TopicHTML hr Tag





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA