Bootstrap Day 4: Building Smart Navigation & Interactive Forms

Introduction

Hey future web developer! Today we are going to tackle one of the most fun aspects of Bootstrap: Navigation Bars and Forms. They are the essential pieces in making websites actually user-friendly and interactive.

Since every good website will need to have Navigation and Form for the user to interact with the site. It has to have Navigation to find their way around or for a user to log in, sign up, etc. So every website will have a Navigation and Forms. You will learn to make professional responsive navbars and forms by the end of this tutorial. You will see navbars and forms used in every major site regardless of device being used.  

Step-by-Step Tutorial

Section 1: Building Your First Navigation Bar

Let’s start with the navigation bar – the roadmap of your website!

🌐
<nav class="navbar navbar-expand-lg navbar-light bg-light">
    <div class="container-fluid">
        <a href="day3.html" class="navbar-brand">
            <img src="images/mysitelogo1.png" class="navbar-brand bg-white" height="50px" width="100px">
        </a>

        <button type="button" class="navbar-toggler" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav ms-auto">
                <li class="nav-item">
                    <a href="day5.html" class="nav-link active">ℍ𝕆𝕄𝔼</a>
                </li>
                <li class="nav-item">
                    <a href="day6.html" class="nav-link">𝔸𝔹𝕆𝕌𝕋</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

What do we have going on here?

  • navbar: the primary container for our navigation 
  • navbar-expand-lg: collapses navigation on large or smaller devices.
  • navbar-toggler: creates the ‘hamburger’ or mobile menu
  • collapse navbar-collapse: controls hidden / shown navigation when toggled
  • ms-auto: aligned to the right side of navigation. 


Pro Tips:
Always wrap your navigation in a container-fluid to have proper spacing and responsiveness!

Section 2: Basic Form Controls

Now let’s take a look at other form elements:

🌐
<input type="text" class="form-control" placeholder="Name">
<select class="form-select">
    <option>Choose...</option>
    <option>One</option>
</select>
<textarea class="form-control" rows="4"></textarea>

Why use these classes?

  • form-control: Makes your inputs look neat and professional
  • form-select: Styles a dropdown menu nicely
  • Bootstrap manages all spacing and styling for you

Section 3: Advanced Form Features

🌐
<!-- Input Groups -->
<div class="input-group">
    <span class="input-group-text">@</span>
    <input type="text" class="form-control" placeholder="Username">
</div>

<!-- Checkboxes and Radio Buttons -->
<div class="form-check">
    <input type="checkbox" class="form-check-input" id="checkMe">
    <label for="checkMe" class="form-check-label">Check Me out</label>
</div>

<!-- Floating Labels -->
<div class="form-floating mb-3">
    <input type="email" placeholder="name@example.com" class="form-control" id="floatingInput">
    <label for="floatingInput">Email Address</label>
</div>

Beginner tips:

  • Always use form-check-input together with form-check-label
  • form-floating can be used by you to have a nice floating label
  • input-group can be used to add icons or text to your inputs

Section 4: Form Validation

Example:

🌐
<input type="text" class="form-control is-valid" value="valid value">
<input type="text" class="form-control is-invalid">
<div class="invalid-feedback">Please enter valid value</div>

Note: Bootstrap adds visual feedback with is-valid (green) and is-invalid (red) classes. Always add helpful messages with invalid-feedback tags!

Code Explanation Sections

Navigation Bar Structure Breakdown

🌐
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <div class="container-fluid">
        <a class="navbar-brand" href="#">Brand</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navContent">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navContent">
            <!-- Navigation content goes here -->
        </div>
    </div>
</nav>

How it works:

  • The data-bs-target=”#navContent” tells the toggle button where to open the collapsible content
  • navbar-dark bg-dark makes it a dark themed navbar
  • Bootstrap’s JavaScript automatically manages if it’s in a collapsed state


Grid-Based Form Layout

🌐
<form class="row g-3" action="day2.html">
    <div class="col-md-6">
        <label for="name" class="form-label">Name</label>
        <input type="text" class="form-control is-valid" id="name" placeholder="Your Name">
    </div>
    <div class="col-md-6">
        <label for="email" class="form-label">Email</label>
        <input type="email" class="form-control is-invalid" id="email" placeholder="email@example.com">
        <div class="invalid-feedback">Please enter a valid email.</div>
    </div>
</form>

Why this rocks: 

  • row g-3 creates a grid that has spacing and is always consistent
  • col-md-6 creates two equal columns on md screens and greater
  • Responsive design just works on all devices

Tables of Key Concepts

A. Components / Keywords Used

Name

Description

navbar

Main navigation bar container

navbar-brand

Company logo or brand name

navbar-toggler

Mobile menu toggle button

collapse

Collapsible content section

form-control

Styles form inputs consistently

form-select

Styles dropdown menus

input-group

Groups input with additional elements

form-check

Container for checkboxes/radio buttons

form-floating

Creates floating label effect

is-valid/is-invalid

Form validation styling

B. Key Properties / Features

Name

Description

navbar-expand-lg

Breakpoint when navbar expands

data-bs-toggle

Enables collapse functionality

data-bs-target

Links toggle to specific content

ms-auto/me-auto

Horizontal spacing utilities

form-label

Properly styles form labels

invalid-feedback

Displays validation messages

row g-3

Grid row with gutter spacing

col-md-6

Column that takes half width on medium screens

Different Form Layouts

Inline Form

🌐
<form class="d-flex">
    <input class="form-control me-2" type="search" placeholder="Search">
    <button class="btn btn-outline-success" type="submit">Search</button>
</form>

Horizontal Form

🌐
<form>
    <div class="row mb-3">
        <label for="inputEmail" class="col-sm-2 col-form-label">Email</label>
        <div class="col-sm-10">
            <input type="email" class="form-control" id="inputEmail">
        </div>
    </div>
</form>

Grid Form

🌐
<form class="row g-3">
    <div class="col-md-6">
        <label for="firstName" class="form-label">First name</label>
        <input type="text" class="form-control" id="firstName">
    </div>
    <div class="col-md-6">
        <label for="lastName" class="form-label">Last name</label>
        <input type="text" class="form-control" id="lastName">
    </div>
</form>

Useful References


Keep practicing and keep experimenting! Remember – every great developer was exactly where you’re at now! Happy coding!

What You Learned

Well done! Here’s what you’ve learned today: 

  • Mastery of Navigation: You can now create responsive headers/navigations that look great on mobile and desktop
  • Form Expertise: You understand all of the major controls related to forms and how to style them professionally 
  • Layout Skills: You can create inline, horizontal and grid heal based forms 
  • Validation Knowledge: You understand how to assist users by providing validation states 
  • Responsive Design: Everything you built behaves automatically on all screen sizes 


Key Takeaways:

  • Bootstrap makes complex components easy through built classes 
  • Responsive design becomes automatic when you use the right classes 
  • Consistency in styling gives your site a professional look and feel 
  • Forms and navigation are the backbone of user experience 


Next Steps:
Change colors, or add three more menu items, or even just a contact form – using all the elements you’ve learned today! 

OUTPUT:

Bootstrap form examples with form validation, navbar search bar, and input fields showing valid and invalid feedback.
Bootstrap inline form layout with search field and grid-based form elements.

Frequently Asked Questions FAQs

A Navbar is a responsive navigation header that includes links, logos, dropdowns, and togglers. Bootstrap provides ready-made classes to create mobile-friendly navigation menus.

Bootstrap uses JavaScript to enable dropdown functionality. You add dropdown and dropdown-menu classes to create interactive menus.

Bootstrap Forms provide pre-styled input fields, labels, buttons, validation messages, and layouts to simplify form development.

Bootstrap provides classes like is-valid and is-invalid to display visual feedback for form fields when validation passes or fails.

JavaScript is optional for basic styling but is required for advanced components like validation, dropdowns, and collapses.