Open In App

Create Footers using NextJS and Tailwind CSS

Last Updated : 25 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The footer is an important part of any web application. It contains important links, social media icons, and copyright information, enhancing user experience and providing easy navigation. we will learn how to create a responsive footer using the Next.js application and Tailwind CSS.

Prerequisites

Approach for creating a footer

  • Identify the key components to include: logo, company information, social media links, and navigation sections.
  • Create a new Next.js application using the command npx create-next-app.
  • Create a new file named Footer.js in the components directory.
  • Structure the footer using semantic HTML, ensuring proper sections are created for content organization.
  • Use Tailwind CSS classes to apply styles such as background color, text color, padding, and margin.

Steps to create the Project and Install the required modules

Step 1: Create the NextJs App using the following command.

npx create-next-app@latest footer

Configuration which you should follow while creating the App:

file
Select the following options

Step 2: Move to the project folder from the Terminal

cd footer

Step 3: Install dependencies

npm install @fortawesome/fontawesome-svg-core @fortawesome/free-solid-svg-icons @fortawesome/react-fontawesome @fortawesome/free-brands-svg-icons

Project Structure:

file
Project Structure

Updated Dependencies:

 "dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.6.0",
"@fortawesome/free-brands-svg-icons": "^6.6.0",
"@fortawesome/free-solid-svg-icons": "^6.6.0",
"@fortawesome/react-fontawesome": "^0.2.2",
"next": "14.2.13",
"react": "^18",
"react-dom": "^18"
},
"devDependencies": {
"postcss": "^8",
"tailwindcss": "^3.4.1"
}

Step 4: Write the following code in different files(The name of the files is mentioned in the first line of each code block)

CSS
/* globals.css */

@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
    --background: #ffffff;
    --foreground: #171717;
}

@media (prefers-color-scheme: dark) {
    :root {
        --background: #0a0a0a;
        --foreground: #ededed;
    }
}

body {
    color: var(--foreground);
    background: var(--background);
    font-family: Arial, Helvetica, sans-serif;
}

@layer utilities {
    .text-balance {
        text-wrap: balance;
    }
}
JavaScript
// page.js

import Footer from ".//components/Footer";

const Home = () => {
    return (
        <div>
            <header className="bg-green-600 text-white py-10 text-center">
                <h1 className="text-4xl font-bold mb-4">
                Welcome to GeeksForGeeks!</h1>
            </header>

            <main className="bg-white rounded-lg shadow-md p-8">
                <h1 className="text-3xl font-bold mb-4">About GeeksforGeeks</h1>

                <p className="mb-4">
                    GeeksforGeeks (GFG) is a popular online platform 
                    that provides a wealth of resources for computer 
                    science and programming enthusiasts. Founded in 2009, 
                    it focuses on sharing knowledge through articles, 
                    tutorials, coding problems, and interview preparation materials.
                </p>

                <h2 className="text-2xl font-semibold mb-2">Key Features of GFG:</h2>
                <ul className="list-disc list-inside mb-4">
                    <li><strong>Programming Articles:</strong>
                    In-depth articles on various programming languages, 
                    algorithms, data structures, and software development concepts.</li>
                    <li><strong>Coding Challenges:</strong>
                    A wide array of coding problems, ranging 
                    from easy to hard, helping enhance problem-solving skills.</li>
                    <li><strong>Interview Preparation:</strong>
                    Provides interview questions, experiences, 
                    and tips for job seekers in tech.</li>
                    <li><strong>Courses and Tutorials:</strong> 
                    Offers courses on topics like web development, 
                    machine learning, and competitive programming.</li>
                    <li><strong>Community and Contributions:</strong> 
                    Users can contribute articles and solutions, 
                    fostering a community of learners and educators.</li>
                </ul>

                <p>
                    Overall, GFG is an invaluable resource for 
                    students, professionals, and anyone looking 
                    to improve their programming skills or prepare 
                    for technical interviews.
                </p>
            </main>

            {/* Footer Component */}
            <Footer />
        </div>
    );
};

export default Home;
JavaScript
// components/Footer.js

import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faFacebook, faTwitter, faInstagram } from "@fortawesome/free-brands-svg-icons";

const Footer = () => {
    return (
        <footer className="bg-white text-black py-10">
            {/* Top Line */}
            <div className="border-t-4 border-gray-200"></div>

            {/* Footer Content */}
            <div className="container mx-auto px-5 grid 
            grid-cols-1 md:grid-cols-4 gap-8 py-10">
                {/* Logo and description */}
                <div>
                    {/* Adding logo from URL */}
                    <img
                        src="https://media.geeksforgeeks.org/wp-content/
                        uploads/20210224040124/JSBinCollaborativeJavaScriptDebugging6
                        -300x160.png"
                        alt="GeeksforGeeks Logo"
                        className="mb-4 w-20"
                    />
                    <h2 className="text-2xl font-bold mb-4">GeeksForGeeks</h2>
                    <p className="text-gray-600">
                        Corporate & Communications Address: A-143, 9th Floor, 
                        Sovereign Corporate Tower,
                        Sector- 136, Noida, Uttar Pradesh (201305)
                    </p>
                    <p className="text-gray-600">
                        Registered Address: K 061, Tower K, Gulshan Vivante 
                        Apartment, Sector 137, Noida,
                        Gautam Buddh Nagar, Uttar Pradesh, 201305
                    </p>
                    <div className="flex mt-4 space-x-4">
                        {/* Social Media Icons */}
                        <a href="#" className="text-gray-600 hover:text-black">
                            <FontAwesomeIcon icon={faFacebook} size="lg" />
                        </a>
                        <a href="#" className="text-gray-600 hover:text-black">
                            <FontAwesomeIcon icon={faTwitter} size="lg" />
                        </a>
                        <a href="#" className="text-gray-600 hover:text-black">
                            <FontAwesomeIcon icon={faInstagram} size="lg" />
                        </a>
                    </div>
                </div>

                {/* Explore Column */}
                <div>
                    <h3 className="font-bold mb-4">Explore</h3>
                    <ul className="text-gray-600 space-y-2">
                        <li><a href="#" className="hover:text-black">
                        Hack-A-thon</a></li>
                        <li><a href="#" className="hover:text-black">
                        GFG Weekly Contest</a></li>
                        <li><a href="#" className="hover:text-black">
                        Master CP</a></li>
                        <li><a href="#" className="hover:text-black">
                        DSA in Java</a></li>
                        <li><a href="#" className="hover:text-black">
                        Master System Design</a></li>
                        <li><a href="#" className="hover:text-black">
                        Offline Classes</a></li>
                    </ul>
                </div>

                {/* Languages Column */}
                <div>
                    <h3 className="font-bold mb-4">Languages</h3>
                    <ul className="text-gray-600 space-y-2">
                        <li><a href="#" className="hover:text-black">
                        Python</a></li>
                        <li><a href="#" className="hover:text-black">
                        Java</a></li>
                        <li><a href="#" className="hover:text-black">
                        C++</a></li>
                        <li><a href="#" className="hover:text-black">
                        JavaScript</a></li>
                        <li><a href="#" className="hover:text-black">
                        GoLang</a></li>
                        <li><a href="#" className="hover:text-black">
                        SQL</a></li>
                    </ul>
                </div>

                {/* Competitive Exams Column */}
                <div>
                    <h3 className="font-bold mb-4">Competitive Exams</h3>
                    <ul className="text-gray-600 space-y-2">
                        <li><a href="#" className="hover:text-black">
                        SSC CGL</a></li>
                        <li><a href="#" className="hover:text-black">
                        IBPS PO</a></li>
                        <li><a href="#" className="hover:text-black">
                        SBI PO</a></li>
                        <li><a href="#" className="hover:text-black">
                        NDA</a></li>
                    </ul>
                </div>
            </div>

            {/* Footer Bottom */}
            <div className="text-center text-gray-500 mt-10">
                @GeeksforGeeks, Sanchhaya Education Private Limited, 
                All rights reserved
            </div>
        </footer>
    );
};

export default Footer;

Run your app by executing the below command:

npm run dev

Output:


Next Article

Similar Reads