The HEADER element in HTML5 with examples

The <header> element, as the name implies, is usually placed on the top of the page.

Let’s see an example of a <header> element in use:

HTML

Example of the header element in HTML5.

CSS

The styles of the previous html code.

Result:

How the previous example of a header element renders on a browser.

The use of <header> is not limited to the top of the web page.

We can also use it in the start of an article or a section where it can provide introductory content

Example of code with the header element used in two different parts of the body.

As a result we can use multiple headers, one as a main header of the web page and a lot of other headers for the different sections or/and the articles of that web page.

NOTE - We cannot use a <header> element inside a <footer> elelment.

For example:

Example of a footer element mistakenly include a header element.

And if we try to validate our code:

Image of how the code is validated.

We get an error. This is not valid code!

Of course, we may not nest a <header> element inside another <header> element either.

Although my blog doesn’t support comments, feel free to reply via email or X.