HTML Course | Building Header of the Website
Last Updated : 27 Nov, 2024
The header is the top part of the website and the important area for branding and navigation. In this chapter, you’ll learn how to build a header with the tags which we have already learnt.
Course Navigation

HTML Course : Building Header of the Website
So far, we have created the navigation bar for the header of our website. The next thing to complete the header is to include the image and text above the image as shown below.

HTML Course : Building Header of the Website
Let’s again look at the part of the code for the header in our index.html file. The highlighted part of the code shows the image menu of the header
HTML <!DOCTYPE html> <!-- Header Menu of the Page --> <header> <!-- Top header menu containing logo and Navigation bar --> <div id="top-header"> <!-- Logo --> <div id="logo"> <img src="images/logo.png" /> </div> <!-- Navigation Menu --> <nav> <ul> <li class="active"> <a href="#">Home</a> </li> <li> <a href="#">About Us</a> </li> <li> <a href="#">Our Products</a> </li> <li> <a href="#">Careers</a> </li> <li> <a href="#">Contact Us</a> </li> </ul> </nav> </div> <!-- Image menu in Header to contain an Image and a sample text over that image --> <div id="header-image-menu"> </div> </header>
Steps To Build Header of the Website
Step 1: Add an image in the header
To complete the image menu, we first need to add the image inside the div tag with id “header-image-menu” as shown in the above code.
- Click Here to download the given image.
- Add it to the images folder of your project.
- Include it inside the div with id = “header-image-menu”.
<div id="header-image-menu">
<img src="images/slider.jpg">
</div>
Step 2: Add the text on the image
Add the text inside an <h2> tag and give the tag an id = “image-text” which will be used for adding styles.
Below is the final HTML code for the header menu after adding the images and text
HTML <!DOCTYPE html> <!-- Header Menu of the Page --> <header> <!-- Top header menu containing logo and Navigation bar --> <div id="top-header"> <!-- Logo --> <div id="logo"> <img src="images/logo.png" /> </div> <!-- Navigation Menu --> <nav> <ul> <li class="active"> <a href="#">Home</a> </li> <li> <a href="#">About Us</a> </li> <li> <a href="#">Our Products</a> </li> <li> <a href="#">Careers</a> </li> <li> <a href="#">Contact Us</a> </li> </ul> </nav> </div> <!-- Image menu in Header to contain an Image and a sample text over that image --> <div id="header-image-menu"> <img src="images/slider.jpg"> <h2 id="image-text"> A Basic Web Design course by GeeksforGeeks </h2> </div> </header>
Output: Our webpage will now look like this.

HTML Course : Building Header of the Website
Can you point out what is wrong with the above image? The answer is that the text is below the image and not at its correct position as shown in the template.
We will have to use CSS to add styles to the text and image in order to place the text over the image.
Steps to add CSS in the Header
Step 1: Styling the main image menu(#header-image-menu)
Give the image menu parent a margin of top as 10px and set its position to relative.
CSS /*Add the below code to style.css*/ #header-image-menu{ top: 10px; position: relative; }
Step 2: Styling the image inside the image menu
Set the width of the image to 100% of the parent and remove the margins and padding.
CSS /*Add the below code to style.css*/ #header-image-menu img{ width: 100%; margin: none; padding: none; }
Step 3: Positioning the text(#image-text)
Set the position of the text to absolute first and give appropriate margins from left and top. Set the color and translate the text by 30% using the translate() function.
CSS /*Add the below code to style.css*/ #image-text{ position: absolute; top: 60%; left: 60%; font-family: 'Roboto'; color: #000; transform: translate(-30%, -30%); text-align: center; }
The complete CSS code for the image menu will look something as below
CSS /*****************************/ /* Styling Header Image Menu */ /*****************************/ #header-image-menu{ top: 10px; position: relative; } #header-image-menu img{ width: 100%; margin: none; padding: none; } #image-text{ position: absolute; top: 60%; left: 60%; font-family: 'Roboto'; color: #000; transform: translate(-30%, -30%); text-align: center; }
On opening the index.html in the browser now, you will see the exact same header as shown in the sample video at the start of the course.

HTML Course : Building Header of the Website
Now we have completed building the header of our website.
Similar Reads
Introduction to HTML and CSS | Learn to Design Your First Website in Just 1 Week
Ready to Design Your First Website in Just 1 Week? With this guide, learn how to build a simple yet stylish website in just one week to gain skills and confidence. This is an introduction course to HTML and CSS which will help you learn all about the basics of HTML and CSS needed to begin with Web D
4 min read
HTML Course | Structure of an HTML Document
HTML (Hypertext Markup Language) is the standard language used to create webpages. It forms the backbone of web development, providing the structure and content for websites. If you're new to web development, understanding HTML is the first step in creating web pages. What is an HTML Document?HTML i
4 min read
HTML Course | First Web Page Printing Hello World
So far, we have already learned about the structure of an HTML document, tags, etc in the previous module. Let us use this knowledge to create our first web page. Here, we are creating a simple webpage that displays a "Hello World" message as the perfect starting point. This exercise will help you u
2 min read
HTML Course | Basics of HTML
Now that you've created your first "Hello World" webpage, it's time to learn some important concepts of HTML. In this chapter, weâll cover basic elements that add content and structure, including paragraphs, images, lists, attributes, comments, and more. Table of Content HTML Paragraph HTML Horizont
6 min read
HTML Course | Starting the Project - Creating Directories
Now we have understood the important concepts of HTML, it's time to start building a structured web project. In this chapter, youâll learn how to set up directories and organize files efficiently. It is important to have a well-structured directory for both small and large projects, as it makes your
3 min read
HTML Course | Understanding and Building Project Structure
Now that you've already set up a basic directory structure, it's time to understand and build the basic structure of our project. Course Navigation We have already created all of the directories needed for our project. Let's just start writing our HTML code. Since we are designing a single-page webs
3 min read
CSS Introduction
CSS (Cascading Style Sheets) is a language designed to simplify the process of making web pages presentable. It allows you to apply styles to HTML documents by prescribing colors, fonts, spacing, and positioning.The main advantages are the separation of content (in HTML) and styling (in CSS) and the
5 min read
HTML Course | Creating Navigation Menu
A navigation menu is the first element we see in any website. It allows users to explore different pages and sections easily. In this chapter, youâll learn how to create a navigation menu in HTML. Course Navigation In the last chapter, we have created the entire structure of our website using HTML e
6 min read
HTML Course | Building Header of the Website
The header is the top part of the website and the important area for branding and navigation. In this chapter, youâll learn how to build a header with the tags which we have already learnt. Course Navigation So far, we have created the navigation bar for the header of our website. The next thing to
4 min read
HTML Course | Building Main Content - Section 1
The main content of a website is where you show the core information that visitors are looking for. This could be text, images, links, or any important details about your services, products, or ideas. Course Navigation We just completed building the header for our website. Let's start building the m
4 min read