The Wayback Machine - https://web.archive.org/web/20240715150843/https://www.geeksforgeeks.org/css-website-layout/
Open In App

CSS Website Layout

Last Updated : 08 Apr, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

CSS Website Layout plays a crucial role in defining its visual structure, organization, and responsiveness when designing a website. In this article, we’ll learn various CSS techniques to create effective website layouts with CSS.

A website can be divided into various sections comprising of header, menus, content, and footer based on which there are many different layout designs available for developers. Different layouts can be created by using a div tag and using CSS property to style it. 

Structure of Website Layout

Structure of Website Layout

1. Header Section

The header section typically appears at the top of a website or just below the top navigation menu. It often includes the website name or logo. Here’s an example of how to style the header using CSS:

Example: 

html
<!-- This code describes the header section
of website layout -->
<!DOCTYPE html>
<html>

<head>
    <title>
        Website Layouts
    </title>

    <style>
        .header {
            background-color: green;
            padding: 15px;
            text-align: center;
        }
    </style>
</head>

<body>
    <div class="header">
        <h2 style="color:white;">
            GeeksforGeeks
        </h2>
    </div>
    <br>

    <center style="font-size:200%;">
        Remaining Section
    </center>
</body>

</html>

Output: 

Website Header Section

2. Navigation Menu

A navigation bar/menu provides links for easy website navigation. Here’s an example of creating a simple navigation menu:

Example: 

html
<!DOCTYPE html>
<html>

<head>
    <title>
        Website Layout
    </title>

    <style>
        /* CSS property for header section */
        .header {
            background-color: green;
            padding: 15px;
            text-align: center;
        }

        /* CSS property for navigation menu */
        .nav_menu {
            overflow: hidden;
            background-color: #333;
        }

        .nav_menu a {
            float: left;
            display: block;
            color: white;
            text-align: center;
            padding: 14px 16px;
            text-decoration: none;
        }

        .nav_menu a:hover {
            background-color: white;
            color: green;
        }
    </style>
</head>

<body>

    <!-- header of website layout -->
    <div class="header">
        <h2 style="color:white;font-size:200%;">
            GeeksforGeeks
        </h2>
    </div>

    <!-- navigation menu for website layout -->
    <div class="nav_menu">
        <a href="#">Algo</a>
        <a href="#">DS</a>
        <a href="#">Language</a>
    </div><br>

    <center style="font-size:200%;">
        Remaining Section
    </center>
</body>

</html>

Output: 

Website Navigation Menu Section

3. Content Section

The content section is the main body of the website. The user can divide the content section in an n-column layout. 
The most common layouts are: 

  • 1 Column Layout: It is mostly used for mobile layout. 

1-Column Content

  • 2 Column Layout: This website layout is mostly used for tablets or laptops. 

2-Column Content

  • 3 Column Layout: This website layout is mostly used for desktops. 

3- Column Content

The user can also create a responsive layout where the layout will get changed as per screen size. Consider the below example where if the idth of the screen is more than 600px then there will be a 3-column layout and if the width of the screen is between 400px to 600px then there will be a 2-column layout and if the screen size is less than 400px then the 1-column layout will display.

Example: 

html
<!DOCTYPE html>
<html>

<head>
    <title>
        Website Layout
    </title>
    <style>
        * {
            box-sizing: border-box;
        }

        /* CSS property for header section */
        .header {
            background-color: green;
            padding: 15px;
            text-align: center;
        }

        /* CSS property for navigation menu */
        .nav_menu {
            overflow: hidden;
            background-color: #333;
        }

        .nav_menu a {
            float: left;
            display: block;
            color: white;
            text-align: center;
            padding: 14px 16px;
            text-decoration: none;
        }

        .nav_menu a:hover {
            background-color: white;
            color: green;
        }

        /* CSS property for content section */
        .columnA,
        .columnB,
        .columnC {
            float: left;
            width: 31%;
            padding: 15px;
            text-align: justify;
        }

        h2 {
            color: green;
            text-align: center;
        }

        /* Media query to set website layout 
            according to screen size */
        @media screen and (max-width:600px) {

            .columnA,
            .columnB,
            .columnC {
                width: 50%;
            }
        }

        @media screen and (max-width:400px) {

            .columnA,
            .columnB,
            .columnC {
                width: 100%;
            }
        }
    </style>
</head>

<body>

    <!-- header of website layout -->
    <div class="header">
        <h2 style="color:white;font-size:200%">
            GeeksforGeeks
        </h2>
    </div>

    <!-- navigation menu of website layout -->
    <div class="nav_menu">
        <a href="#">Algo</a>
        <a href="#">DS</a>
        <a href="#">Language</a>
    </div>

    <!-- Content section of website layout -->
    <div class="row">

        <div class="columnA">
            <h2>Column A</h2>

            <p>
                  Prepare for the Recruitment drive of product
                based companies like Microsoft, Amazon, Adobe
                etc with a free online placement preparation
                course. The course focuses on various MCQ's
                & Coding question likely to be asked in the
                interviews & make your upcoming placement
                season efficient and successful.
            </p>

        </div>

        <div class="columnB">
            <h2>Column B</h2>

            <p>
                  Prepare for the Recruitment drive of product
                based companies like Microsoft, Amazon, Adobe
                etc with a free online placement preparation
                course. The course focuses on various MCQ's
                & Coding question likely to be asked in the
                interviews & make your upcoming placement
                season efficient and successful.
            </p>

        </div>

        <div class="columnC">
            <h2>Column C</h2>



            <p>
                  Prepare for the Recruitment drive of product
                based companies like Microsoft, Amazon, Adobe
                etc with a free online placement preparation
                course. The course focuses on various MCQ's
                & Coding question likely to be asked in the
                interviews & make your upcoming placement
                season efficient and successful.
            </p>

        </div>
    </div>
</body>

</html>

Output: The width of the screen size greater than 700px: 

Content Section

The width of screen size greater then 400px and less than 600px:  

Content Section

The width of screen size less than 400px:  

Content Section

4. Footer Section

A footer section is placed at the bottom of the webpage and it generally consists of information like contact info, copyrights, About us etc.

Example: 

html
<!DOCTYPE html>
<html>

<head>
    <title>
        CSS Website Layout
    </title>

    <style>
        /* Style for footer section */
        .footer {
            background-color: green;
            padding: 15px;
            text-align: center;
        }
    </style>
</head>

<body>
    <center style="font-size:200%;">
        Upper section
    </center>

    <!-- footer Section -->
    <div class="footer">
        <a href="#">About</a><br>
        <a href="#">Career</a><br>
        <a href="#">Contact Us</a>
    </div>
</body>

</html>

Output: 

Foooter of Website

Important Points to Remember

  • Header section contains a website logo, a search bar and profile of user.
  • Navigation menu contains link to various categories of articles available.
  • Content section is divided into 3 parts(columns) with left and right sidebar containing links to other articles and advertisements.
  • Main content section is the one containing this article.
  • Footer at the bottom there is a footer section which contains address, links, contacts etc. 

In conclusion, CSS, or Cascading Style Sheets, is a powerful tool that brings life to our web pages. This separation of layout (HTML) and formatting (CSS) enhances the sustainability, adaptability, and extendibility of web implementations. Whether you’re a beginner or an experienced professional, understanding CSS is crucial for creating attractive, user-friendly websites.



Previous Article
Next Article

Similar Reads

Create a Blog Website Layout using HTML and CSS
The Blog layout consists of a header, navigation menu, main content area, and footer. The header contains the website logo, name, and its tagline. The navigation menu is used to allow users to easily navigate through the different sections of the blog. The main content area contains the list of blog posts with title, author name, published date, an
4 min read
Difference between Responsive Website and Mobile Website
Responsive Website: Responsive websites are websites that are designed to fit all types of devices and adjust website layout to best fit screen size. There is no need to make any other device version of the website to fit small devices. Mobile Website: Mobile websites are websites that are designed to fit especially small devices screen such as mob
3 min read
CSS table-layout Property
The table-layout property in CSS is used to display the layout of the table. This property is basically used to sets the algorithm that is used to lay out &lt;table&gt; cells, rows, and columns. Syntax: table-layout: auto|fixed|initial|inherit;Default Value: Its default value is auto. Property Value: auto: It is used to set the automatic table layo
2 min read
Advance CSS layout with flexbox
It is also called a flexible box model. It is basically a layout model that provides an easy and clean way to arrange items within a container. Flexbox is different from the block model which is vertically bias and the inline which is horizontally bias. Flexbox was created for small-scale layouts and there's another standard called grids which is g
6 min read
CSS Layout - Horizontal &amp; Vertical Align
The Layout in CSS is used to control the flow of element inside another element. It sets the position of element in the web page. The position of element can be set by using horizontal and vertical alignment. There are many ways to set the position of element which are listed below: Using Position Property: Use position property to absolute to set
4 min read
Primer CSS Layout Sidebar Positioning
Primer CSS is a free and open-source CSS framework that is built using the GitHub design system for providing support to the broad spectrum of GitHub websites. It helps in creating the foundation of the basic style elements such as spacing, components, typography, color, etc. In this article, we'll see about Layout Sidebar positioning. We can chang
2 min read
Can I Create Masonry Layout using Tailwind CSS Utility Classes ?
Yes, you can create a Masonry layout using Tailwind CSS utility classes. A Masonry layout is a popular design pattern used for displaying images or other elements in a grid-like structure where each item is of varying height and width. This layout creates a visually appealing and dynamic design that helps to break the monotony of a traditional grid
3 min read
How to hide elements in responsive layout using CSS ?
CSS can be used to hide or display elements of the page. This can be used in a responsive website to show certain elements that are only possible to interact with a larger screen size for a good user experience. Media queries are the technique introduced in CSS3 to help to design responsive websites. A media query has two parts, one is the optional
3 min read
Foundation CSS Top Bar Advanced Layout
Foundation CSS is an open-source &amp; responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to design beautiful responsive websites, apps, and emails that look amazing &amp; can be accessible to any device. It is used by many companies such as Facebook, eBay, Mozilla, Adobe, and even Disney. The framework is
4 min read
What are the usage of "table-layout" property in CSS ?
In this article, we are going to learn the usages of the table-layout property in CSS, The table-layout property in CSS specifies the layout of the table which consists of table cells, rows, and columns. It can have two values: "auto," which allows the table to adjust its layout based on content, and "fixed," which sets a fixed layout ignoring cont
3 min read
three90RightbarBannerImg