Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind
  • CSS Formatter
Open In App
Next Article:
HTML Course | Building Main Content - Section 1
Next article icon

HTML Course | Building Header of the Website

Last Updated : 27 Nov, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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-building-header

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-header-image

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-header-output

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-header-final

HTML Course : Building Header of the Website

Now we have completed building the header of our website. 



Next Article
HTML Course | Building Main Content - Section 1
author
harsh.agarwal0
Improve
Article Tags :
  • CSS
  • HTML
  • Web Technologies
  • CSS-Basics
  • HTML Course Basic

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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences