Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • 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
  • React Tutorial
  • React Exercise
  • React Basic Concepts
  • React Components
  • React Props
  • React Hooks
  • React Router
  • React Advanced
  • React Examples
  • React Interview Questions
  • React Projects
  • Next.js Tutorial
  • React Bootstrap
  • React Material UI
  • React Ant Design
  • React Desktop
  • React Rebass
  • React Blueprint
  • JavaScript
  • Web Technology
Open In App
Next Article:
How to use Bootstrap with NextJS?
Next article icon

How to use Bootstrap with NextJS?

Last Updated : 30 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Next.js is an open-source web development framework based on React and has gained significant popularity due to its amazing features. It is developed by Vercel and Next.js stands out for its robust capabilities, including server-side rendering(SSR) and enhanced search engine optimization (SEO). Next.js provides built-in routing, making it simple to create dynamic routes and handle navigation within your application.

In this article, we will learn how to use Bootstrap 5 with Nextjs. Bootstrap 5 is a powerful free framework that helps developers like you build modern webpages faster and easier. It provides pre-built components and styles for things like buttons, navigation bars, and forms.

Steps to use Bootstrap 5 with Next JS

Step 1: Create a Next Js App

You can create a new Next application using the command below.

npx create-next-app app-name
or
yarn create next-app app-name
or
pnpm create next-app app-name

Step 2 : Install Bootstrap

Once your next project is created, open the project’s root directory and install the bootstrap dependencies with the following command.

npm install bootstrap

Step 3 : Import the Bootstrap module in the project

Add the below code to the layout.js to add the styling to project

import  "bootstrap/dist/css/bootstrap.min.css"

Project Structure:

Project-Structure
Project Structure

Updated Dependencies:

 "dependencies": {
"bootstrap": "^5.3.3",
"next": "14.2.3",
"react": "^18",
"react-dom": "^18"
}

Example: The App contains the Navbar .heading along with some buttons styled using Bootstrap 5

JavaScript
//page.js  export default function Home() {   return (     <div>       {/* navbar */}       <nav className="navbar navbar-expand-lg bg-body-tertiary">         <div className="container-fluid">           <a className="navbar-brand" href="#">             Navbar           </a>           <button             className="navbar-toggler"             type="button"             data-bs-toggle="collapse"             data-bs-target="#navbarSupportedContent"             aria-controls="navbarSupportedContent"             aria-expanded="false"             aria-label="Toggle navigation"           >             <span className="navbar-toggler-icon"></span>           </button>           <div className="collapse navbar-collapse" id="navbarSupportedContent">             <ul className="navbar-nav me-auto mb-2 mb-lg-0">               <li className="nav-item">                 <a className="nav-link active" aria-current="page" href="#">                   Home                 </a>               </li>               <li className="nav-item">                 <a className="nav-link active" aria-current="page" href="#">                   Contact-us                 </a>               </li>               <li className="nav-item">                 <a className="nav-link active" aria-current="page" href="#">                   About Us                 </a>               </li>               <li className="nav-item">                 <a className="nav-link" href="#">                   Link                 </a>               </li>             </ul>             <form className="d-flex" role="search">               <input                 className="form-control me-2"                 type="search"                 placeholder="Search"                 aria-label="Search"               />               <button className="btn btn-outline-success" type="submit">                 Search               </button>             </form>           </div>         </div>       </nav>       <h2 className="text-center text-bg-primary m-2 p-2">         Bootstrap 5 with Next.js       </h2>       <div className="container-fluid m-2 border border-success text-center">         <h4>Components</h4>{" "}         <div className="row m-2 ">           <div className="col-sm">First Component</div>           <div className="col-sm">Second Component</div>           <div className="col-sm">Third Component</div>         </div>       </div>       <div className="container-fluid m-2 border text-center">         <h4>Buttons</h4>         <div className="row m-2 justify-content-between ">           <div className="col-sm-auto">             <button type="button" className="btn btn-primary">               Primary             </button>           </div>           <div className="col-sm-auto">             <button type="button" className="btn btn-secondary">               Secondary             </button>           </div>           <div className="col-sm-auto">             <button type="button" className="btn btn-success">               Success             </button>           </div>           <div className="col-sm-auto">             <button type="button" className="btn btn-danger">               Danger             </button>           </div>         </div>       </div>     </div>   ); } 
JavaScript
//layout.js import  "bootstrap/dist/css/bootstrap.min.css" import AddBootstrap from "./AddBootstrap";  export const metadata = {   title: "NextJs and Bootstrap 5",   description: "Generated by create next app", };  export default function RootLayout({ children }) {   return (     <html lang="en">       <body >         <AddBootstrap/>         {children}</body>     </html>   ); } 
JavaScript
//  AddBootstrap.js   "use client";  import { useEffect } from "react";  export default function AddBootstrap() {     useEffect(()=>{         import( "bootstrap/dist/js/bootstrap.bundle.js")     },[])     return <></> } 

Explanantion

  • Paje.js contains the navbar ,header , components and buttons which are styled using the bootstrap classes.
  • In layout.js we have imported the " Bootstrap module" which is used to add style to the children elements ,which add styles to whole project.
  • In AddBootstrap.js we have used useEffect hook to add the functionality to toggle the navbar using the " bootstrap/dist/js/bootstrap.bundle.js"

Output:

Bootstrap-5-in-NextJs
Bootstrap 5 with Next Js

Next Article
How to use Bootstrap with NextJS?

P

pritamfulari27
Improve
Article Tags :
  • Web Technologies
  • Bootstrap
  • ReactJS

Similar Reads

    How To Setup Multiple Themes In NextJS With React-Bootstrap?
    Multiple themes mean providing users with different visual styles or color schemes for an application, enhancing user experience and personalization. In this article, we'll explore how to set up multiple themes in a Next.js application using React-Bootstrap. We'll explore through creating a theme co
    3 min read
    How to use bootstrap 4 in angular 2?
    Bootstrap is an open-source toolkit for developing with HTML, CSS, and JS. The Bootstrap framework can be used together with modern JavaScript web & mobile frameworks like Angular. Bootstrap 4 is the newest version of Bootstrap, which is the most popular HTML, CSS, and JavaScript framework. This
    2 min read
    How to install Bootstrap 5?
    Bootstrap 5, a popular front-end framework, empowers developers to create sleek and responsive websites with minimal effort. To install Bootstrap 5, you can choose from three methods including CDN links for quick integration, employ package managers like npm for seamless dependency management, or ma
    5 min read
    How to use Material-UI with Next.js ?
    Integrating Material-UI (now known as MUI) with Next.js allows you to build modern, responsive user interfaces with a comprehensive set of React components. In this article, we will learn some additional necessary steps to be performed to integrate Material-UI with the Next.js project.Prerequisites:
    4 min read
    How to create a web page using Bootstrap ?
    Bootstrap is an open-source CSS framework for creating a responsive and customizable frontend for websites and web applications. Using Bootstrap's grid system one can easily create a web page very fast. Any webpage these days needs to have a navbar for user navigation, some content & a form for
    6 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