How to Create a Two-Column Footer Layout in CSS

Introduction

A two-column footer layout is commonly used in web design to organize footer content like links, contact details, or other important information. This layout can be achieved using CSS Flexbox or CSS Grid, each offering unique advantages. 

In this guide, you’ll learn how to implement a two-column footer layout using both Flexbox and CSS Grid in separate sections, with responsive design adjustments.


Development Steps

  1. Create the HTML Structure: Set up the basic HTML for the two-column footer.
  2. Apply Flexbox to Create a Two-Column Layout: Use CSS Flexbox to align the footer content into two columns.
  3. Style the Footer Content: Add styles for the footer content, including padding, background color, and text alignment.
  4. Make the Layout Responsive: Use media queries to adjust the layout for smaller screen sizes.

Step 1: Create the HTML Structure

First, set up the HTML structure with two div elements inside a footer. These div elements will represent the two columns of the footer.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Flexbox Two-Column Footer</title>
</head>
<body>

    <!-- Step 1: Footer structure for Flexbox -->
    <footer class="footer">
        <div class="column">
            <h4>Column 1</h4>
            <p>Information for the first column.</p>
        </div>
        <div class="column">
            <h4>Column 2</h4>
            <p>Information for the second column.</p>
        </div>
    </footer>

</body>
</html>

Step 2: Apply Flexbox to Create a Two-Column Layout

Use Flexbox to create a responsive two-column layout. Flexbox is perfect for this because it easily aligns items horizontally.

/* Flexbox layout */
.footer {
    display: flex;
    justify-content: space-between;  /* Space between the two columns */
    padding: 20px;
    background-color: #333;
    color: white;
}

.column {
    width: 45%;  /* Each column takes 45% of the footer width */
}

Add additional styles to enhance the appearance of the footer content.

/* Footer content styling */
.footer h4 {
    margin-bottom: 10px;
    font-size: 1.2em;
}

.footer p {
    margin: 0;
}

.footer a {
    color: white;
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

Step 4: Make the Layout Responsive

To make the footer responsive, we’ll use media queries to stack the columns vertically on smaller screens.

/* Responsive design for smaller screens */
@media (max-width: 768px) {
    .footer {
        flex-direction: column;  /* Stack the columns vertically */
        text-align: center;  /* Center the text for better readability */
    }

    .column {
        width: 100%;  /* Columns take up the full width */
        margin-bottom: 20px;  /* Add space between the stacked columns */
    }
}

Complete Code (Flexbox)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Flexbox Two-Column Footer</title>
    <style>
        /* Flexbox layout */
        .footer {
            display: flex;
            justify-content: space-between;
            padding: 20px;
            background-color: #333;
            color: white;
        }

        .column {
            width: 45%;
        }

        /* Footer content styling */
        .footer h4 {
            margin-bottom: 10px;
            font-size: 1.2em;
        }

        .footer p {
            margin: 0;
        }

        .footer a {
            color: white;
            text-decoration: none;
        }

        .footer a:hover {
            text-decoration: underline;
        }

        /* Responsive design for smaller screens */
        @media (max-width: 768px) {
            .footer {
                flex-direction: column;
                text-align: center;
            }

            .column {
                width: 100%;
                margin-bottom: 20px;
            }
        }
    </style>
</head>
<body>

    <!-- Flexbox Two-Column Footer -->
    <footer class="footer">
        <div class="column">
            <h4>Column 1</h4>
            <p>Information for the first column.</p>
        </div>
        <div class="column">
            <h4>Column 2</h4>
            <p>Information for the second column.</p>
        </div>
    </footer>

</body>
</html>

Output

You can play with the above HTML in Online HTML Editor and Compiler. Here is the output of the above HTML page.:

Development Steps

  1. Create the HTML Structure: Set up the basic HTML structure for the two-column footer.
  2. Apply CSS Grid to Create a Two-Column Layout: Use CSS Grid to create the two-column layout.
  3. Style the Footer Content: Style the footer with padding, background color, and text alignment.
  4. Make the Layout Responsive: Use media queries to adjust the grid layout for smaller screens.

Step 1: Create the HTML Structure

The HTML structure will remain the same as the Flexbox method, with two div elements inside a footer.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Grid Two-Column Footer</title>
</head>
<body>

    <!-- Step 1: Footer structure for Grid -->
    <footer class="footer">
        <div class="column">
            <h4>Column 1</h4>
            <p>Information for the first column.</p>
        </div>
        <div class="column">
            <h4>Column 2</h4>
            <p>Information for the second column.</p>
        </div>
    </footer>

</body>
</html>

Step 2: Apply CSS Grid to Create a Two-Column Layout

CSS Grid allows you to define grid-based layouts easily. Let’s use it to create a responsive two-column footer.

/* CSS Grid layout */
.footer {
    display: grid;
    grid-template-columns: 1fr 1fr;  /* Two equal-width columns */
    gap: 20px;  /* Space between the columns */
    padding: 20px;
    background-color: #333;
    color: white;
}

The footer content styles remain the same as in the Flexbox method.

/* Footer content styling */
.footer h4 {
    margin-bottom: 10px;
    font-size: 1.2em;
}

.footer p {
    margin: 0;
}

.footer a {
    color: white;
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

Step 4: Make the Layout Responsive

For smaller screens, we’ll adjust the grid layout to stack the columns vertically.

/* Responsive design for smaller screens */
@media (max-width: 768px) {
    .footer {
        grid-template-columns: 1fr;  /* Single-column layout on small screens */
        text-align: center;  /* Center the text for readability */
    }
}

Complete Code (CSS Grid)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Grid Two-Column Footer</title>
    <style>
        /* CSS Grid layout */
        .footer {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 20px;
            padding: 20px;
            background-color: #333;
            color: white;
        }

        /* Footer content styling */
        .footer h4 {
            margin-bottom: 10px;
            font-size: 1.2em;
        }

        .footer p {
            margin: 0;
        }

        .footer a {
            color: white;
            text-decoration: none;
        }

        .footer a:hover {
            text-decoration: underline;
        }

        /* Responsive design for smaller screens */
        @media (max-width: 768px) {
            .footer {
                grid-template-columns: 1fr;
                text-align: center;
            }
        }
    </style>
</head>
<body>

    <!-- Grid Two-Column Footer -->
    <footer class="footer">
        <div class="column">
            <h4>Column 1</h4>
            <p>Information for the first column.</p>
        </div>
        <div class="column">
            <h4>Column 2</h4>
            <p>Information for the second column.</p>
        </div>
    </footer>

</body>
</html>


Conclusion

In this guide, you learned how to create a two-column footer layout using both Flexbox and CSS Grid. Both methods offer flexibility and can be made responsive with media queries to ensure the layout adjusts on smaller screens. You can choose the method that best suits your project needs based on the layout and complexity of your design.

Comments