How to create a responsive header with CSS.

To create a responsive header with CSS, you’ll need to use media queries and some basic CSS styling. Here’s a step-by-step guide:

  • HTML Structure:

Start by creating the HTML structure for your header. Typically, a header consists of a container element with a logo, navigation menu, and possibly other elements. Here’s a basic example:

  <div class="container">
    <div class="logo">
      <!-- Your logo content here -->
      <!-- Your navigation menu here -->
  • CSS Styling:

Next, apply some basic CSS styling to your header elements. You can customize the styles as per your requirements. Here’s an example:

/* Set the height and background color of the header */
header {
  height: 60px;
  background-color: #f2f2f2;

/* Center the content within the header */
.container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 20px;

/* Style the logo */
.logo {
  font-size: 24px;
  font-weight: bold;

/* Style the navigation menu */
nav {
  /* Add your navigation menu styles here */
  • Media Queries:

To make the header responsive, you can use media queries to define different styles for different screen sizes. Here’s an example of how you can adjust the header styles for smaller screens:

/* Styles for screens smaller than 600px */
@media (max-width: 600px) {
  header {
    height: 80px;

  .logo {
    font-size: 20px;

  nav {
    /* Adjust navigation styles for smaller screens */

You can add more media queries and adjust the styles as needed for different screen sizes.

So, With these steps, you have created a basic responsive header using CSS. Remember to customize the styles according to your design and add any additional elements or functionality as required.

Leave a Comment