Skip to content
geeksforgeeks
  • 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
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • BS5 Tutorial
  • BS5 Interview Questions
  • BS5 Layout
  • BS5 Content
  • BS5 Components
  • BS5 Helpers
  • BS5 Utilities
  • BS4 Tutorial
  • BS Tutorial
  • Bootstrap Cheatsheet
  • Tailwind
  • CSS Frameworks
  • HTML Formatter
Open In App
Next Article:
How to Create Multipage Website Using Bootstrap?
Next article icon

How to create a web page using Bootstrap ?

Last Updated : 05 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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 user data submission.

In this article, we will create a nice-looking web page consisting of a navbar, an article, and a form with input validation using only Bootstrap and no CSS.

Bootstrap Setup:

Step 1: Create a file with the name index.html and add the initial HTML5 boilerplate code to it.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <title>Web Page using Bootstrap</title> </head>  <body></body>  </html> 

Step 2: Now to add bootstrap you need to include the following script and link tag in the body element of your HTML code.

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" />

Example:

HTML
<!DOCTYPE html> <html lang="en">  <head>     <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"            rel="stylesheet" /> </head>  <body>     <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js">      </script> </body>  </html> 

Creating a navbar: To create a basic navbar first add the navbar, navbar-expand, navbar-dark, & bg-color class to a nav element inside the HTML file.

Also, create a ul element with the class of navbar-nav and inside it add li elements with a class of nav-item and with links to different pages using anchor tags. After doing this your index.html file should look like this.

Example:

HTML
<!DOCTYPE html> <html lang="en">  <head>     <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"            rel="stylesheet" /> </head>  <body>     <!-- NAVBAR -->     <nav class="navbar navbar-expand navbar-dark bg-success">         <div class="container-fluid">             <a class="navbar-brand" href="./">                 GeeksForGeeks             </a>             <ul class="navbar-nav me-auto mb-2 mb-lg-0">                 <!-- NAVBAR LINKS -->                 <li class="nav-item">                     <a class="nav-link active" href="#">About Us</a>                 </li>                 <li class="nav-item">                     <a class="nav-link" href="#">Contact</a>                 </li>             </ul>         </div>     </nav>     <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js">      </script> </body>  </html> 

Output:

Navbar with 2 links

Adding Searchbar and dropdown menu to the navbar: To add a dropdown add the nav-item dropdown class to the anchor li tag and a data-bs-toggle="dropdown" attribute to the anchor tag inside it along with the class of nav-link dropdown-toggle.

To add dropdown options add a new list to the li tag with the class of dropdown-menu and dropdown-items for different pages inside the dropdown. To add a search box outside the ul and inside the nav element use, a normal form tag with input and a button, and bootstrap will style it. After doing this your code should look like this.

Example:

HTML
<!DOCTYPE html> <html lang="en">  <head>     <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"            rel="stylesheet" /> </head>  <body>     <!-- NAVBAR -->     <nav class="navbar navbar-expand navbar-dark bg-success">         <div class="container-fluid">             <a class="navbar-brand" href="./">GeeksForGeeks</a>             <ul class="navbar-nav me-auto mb-2 mb-lg-0">                  <!-- NAVBAR LINKS -->                 <li class="nav-item">                     <a class="nav-link active" href="#">About Us</a>                 </li>                 <li class="nav-item">                     <a class="nav-link" href="#">Contact</a>                 </li>                  <!--DROPDOWN  -->                 <li class="nav-item dropdown">                     <a class="nav-link dropdown-toggle" href="#"                         id="navbarDropdown" role="button"                         data-bs-toggle="dropdown">                         Coding Articles                     </a>                      <!-- DROPDOWN OPTIONS -->                     <ul class="dropdown-menu">                         <li><a class="dropdown-item" href="#">                                 Page 1                             </a>                         </li>                         <li><a class="dropdown-item" href="#">                                 Page 2                             </a>                         </li>                     </ul>                 </li>             </ul>              <!-- SEARCH BOX -->             <form class="d-flex">                 <input class="form-control me-2"                         type="search"                         placeholder="Search site" />                 <button class="btn btn-primary" type="submit">                     Search                 </button>             </form>         </div>     </nav>     <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js">      </script> </body>  </html> 

Output:

Adding Article: To add an article or any other content we can make use of the bootstrap grid system to make our web pages responsive and have a well-defined layout. The grid system has a row and each row will have columns of different sizes (max is 12) which can be specified by adding col-sm-size class to a div. The following code adds an article to our webpage.

Example:

HTML
<!DOCTYPE html> <html lang="en">  <head>     <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"            rel="stylesheet" /> </head>  <body>     <!-- NAVBAR -->     <nav class="navbar navbar-expand                  navbar-dark bg-success">         <div class="container-fluid">             <a class="navbar-brand" href="./">                 GeeksForGeeks</a>             <ul class="navbar-nav me-auto mb-2 mb-lg-0">                  <!-- NAVBAR LINKS -->                 <li class="nav-item">                     <a class="nav-link active" href="#">                         About Us</a>                 </li>                 <li class="nav-item">                     <a class="nav-link" href="#">                         Contact                     </a>                 </li>                  <!--DROPDOWN  -->                 <li class="nav-item dropdown">                     <a class="nav-link dropdown-toggle"                         href="#"                         id="navbarDropdown"                         role="button"                        data-bs-toggle="dropdown">                         Coding Articles                     </a>                      <!-- DROPDOWN OPTIONS -->                     <ul class="dropdown-menu">                         <li>                             <a class="dropdown-item" href="#">                                 Page 1                             </a>                         </li>                         <li>                             <a class="dropdown-item" href="#">                                 Page 2                             </a>                         </li>                     </ul>                 </li>             </ul>              <!-- SEARCH BOX -->             <form class="d-flex">                 <input class="form-control me-2"                         type="search"                         placeholder="Search site" />                 <button class="btn btn-primary" type="submit">                     Search                 </button>             </form>         </div>     </nav>      <!-- ARTICLE -->     <div class="container mt-5">         <div class="row">             <div class="col-sm-2">Author Name</div>             <div class="col-sm-8">                 <h2>Article Title</h2>                 <h5>Created on 20 Jan 2022</h5>                 <p>                     GeeksForGeeks is a Computer Science portal                     for geeks.It contains well written, well                     thought articles. This platform has been designed                     for every geek wishing to expand their knowledge,                     share their knowledge and is ready to grab their                     dream job. We have millions of articles, live as                     well as online courses, thousands of tutorials and                     much more just for the geek inside you.                 </p>              </div>         </div>     </div>     <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js">     </script> </body>  </html> 

Output:

Adding Form with user validation: To learn more about how to use forms in bootstrap refer to this post on Bootstrap Forms. To add an input validated form to the webpage add this code to your index.html file.

Example:

HTML
<!DOCTYPE html> <html lang="en">  <head>     <link href= "://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"            rel="stylesheet" /> </head>  <body>     <!-- NAVBAR -->     <nav class="navbar navbar-expand                  navbar-dark bg-success">         <div class="container-fluid">             <a class="navbar-brand" href="./">                 GeeksForGeeks             </a>             <ul class="navbar-nav me-auto mb-2 mb-lg-0">                  <!-- NAVBAR LINKS -->                 <li class="nav-item">                     <a class="nav-link active" href="#">                         About Us                     </a>                 </li>                 <li class="nav-item">                     <a class="nav-link" href="#">                         Contact                     </a>                 </li>                  <!--DROPDOWN  -->                 <li class="nav-item dropdown">                     <a class="nav-link dropdown-toggle"                         href="#"                         id="navbarDropdown"                         role="button"                        data-bs-toggle="dropdown">                         Coding Articles                     </a>                     <!-- DROPDOWN OPTIONS -->                     <ul class="dropdown-menu">                         <li>                             <a class="dropdown-item" href="#">                                 Page 1                             </a>                         </li>                         <li>                             <a class="dropdown-item" href="#">                                 Page 2                             </a>                         </li>                     </ul>                 </li>             </ul>             <!-- SEARCH BOX -->             <form class="d-flex">                 <input class="form-control me-2"                         type="search"                         placeholder="Search site" />                 <button class="btn btn-primary" type="submit">                     Search                 </button>             </form>         </div>     </nav>      <!-- ARTICLE -->     <div class="container mt-5">         <div class="row">             <div class="col-sm-2">Author Name</div>             <div class="col-sm-8">                 <h2>Article Title</h2>                 <h5>Created on 20 Jan 2022</h5>                  <!-- ARTICLE TEXT -->                  <p>                     GeeksForGeeks is a Computer Science portal                     for geeks.It contains well written, well                     thought articles. This platform has been designed                     for every geek wishing to expand their knowledge,                     share their knowledge and is ready to grab their                     dream job. We have millions of articles, live as                     well as online courses, thousands of tutorials and                     much more just for the geek inside you.                 </p>              </div>         </div>          <!-- FORM -->         <form class="was-validated">             <!-- Email Address Input -->             <div class="mb-3">                 <label for="email" class="form-label">                     Email Address:                 </label>                 <input type="email" class="form-control"                         id="email"                         placeholder="Enter your email id" required />                 <div class="valid-feedback">                     Valid Email id                 </div>                 <div class="invalid-feedback">                     Please fill out this field.                 </div>             </div>             <!-- Password Input -->             <div class="mb-3">                 <label for="password" class="form-label">                     Password:                 </label>                 <input type="password" class="form-control"                        id="password" placeholder="Enter your password"                     minlength="8" required />                 <div class="form-text" id="password-help-block">                     Password needs to be 8 characters long.                 </div>                 <div class="valid-feedback">                     Valid Password.                 </div>                 <div class="invalid-feedback">                     Please fill out this field.                 </div>             </div>             <!-- Checkbox -->             <div class="form-check mb-3">                 <input class="form-check-input"                         type="checkbox"                         id="checkbox" required />                 <label class="form-check-label" for="checkbox">                     I agree on T & C.                 </label>                 <div class="valid-feedback">                     You Agree to the T & C.                 </div>                 <div class="invalid-feedback">                     Check this checkbox to continue.                 </div>             </div>             <button type="submit" class="btn btn-primary">                 Submit             </button>         </form>     </div>      <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js">     </script> </body>  </html> 

Output:


Next Article
How to Create Multipage Website Using Bootstrap?

C

cjain8060
Improve
Article Tags :
  • Web Technologies
  • Bootstrap
  • Bootstrap-Questions

Similar Reads

  • How to Create Multipage Website Using Bootstrap?
    To create a multipage website using Bootstrap and HTML structure utilize Bootstrap's navbar component to create navigation links between pages. Incorporate Font Awesome icons for visual enhancements and use Bootstrap classes for responsive design. Output Preview: ApproachFirst, create a basic HTML s
    5 min read
  • How to create a Simple Footer using Bootstrap 5 ?
    Bootstrap 5 Footers can be used for displaying Contact links, Social media links, Service links, Company Logos, and other sections. The <footer> tag can be used with built-in classes for making the responsive footer layout. For accomplishing this task, there are 2 approaches, i.e., by using Bo
    4 min read
  • How to create Jumbotron using Bootstrap 5 ?
    Bootstrap Jumbotron is a responsive component whose main goal is to draw the visitor's attention or highlight a special piece of information. Inside a Jumbotron, you can make use of almost any other Bootstrap code to further increase its engagement value. Uses of Jumbotron: Image showcaseHighlightin
    2 min read
  • Create a Single Page Responsive Website Using Bootstrap
    Everyone wants to create the website which is compatible with all the devices like computer, laptops, tablets, and mobiles. So for making a website responsive the best way is to make a website using Bootstrap. Since it is a single-page website when you click on any menu on the website it will reach
    6 min read
  • How to create Call to Action Template using Bootstrap 5 ?
    In this article, we will create a Call to Action (CTA) Template using Bootstrap 5. The main purpose of a Bootstrap Call to Action(CTA) template is to encourage the user to perform a specific action when the user visits the webpage. A simple CTA may consist of the image, content, button, etc, that wi
    2 min read
  • Create a Portfolio Gallery using Bootstrap
    The portfolio gallery is useful when your website contains different types of content or so much content. With the help of a portfolio gallery, you can easily display all the content on your front page to the user. We are going to build a Portfolio Gallery using Bootstrap. PrerequisitesHTMLCSSBootst
    3 min read
  • How to create a vertical or basic form using Bootstrap ?
    Forms are used on almost every website that you visit. It is generally used to collect data from the users. It consists of various interactive controls that enable users to input the data. These controls are wrapped in the <form> tag and also can be designed or styled according to the need by
    4 min read
  • How to create a Bootstrap panel with a heading ?
    A panel is a rectangular component of Bootstrap, typically used to add content to the website. It can also have a header or footer, or both. Bootstrap also provides various classes to add padding to the content or multiple colors to make it more attractive. CDN Link: First, include the style sheet t
    1 min read
  • How to create a form within dropdown menu using Bootstrap ?
    A Dropdown menu is used to allow the user to choose the content from the menu as per their requirement and it is used to save screen space and avoid the long scrolling of the web pages. In web design, we often come in a scenario where we need to create a form within the dropdown menu to get some use
    3 min read
  • How to create a navbar in Bootstrap ?
    Bootstrap Navbar is a navigation header that is located at the top of the webpage which can be extended or collapsed, depending on the screen size. Bootstrap Navbar is used to create responsive navigation for our website. We can create standard navigation bar with <nav class="navbar navbar-defaul
    2 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