Lesson 3: Introduction to Bootstrap

45 minutes
Ages 8-18+
Back to Lessons
Lesson Progress 10%

What You'll Learn Today

Today, we're going to learn a powerful shortcut for making beautiful websites: Bootstrap! It's a free toolkit of pre-made CSS and JavaScript components that lets you build professional-looking pages without writing a lot of custom style code.

Why Use a CSS Framework?

Imagine building a castle with individual bricks versus using large, pre-built wall sections. A CSS framework like Bootstrap is like having those pre-built sections. It saves a huge amount of time and ensures your website looks great on all devices, from phones to big-screen TVs.

Learning Objectives

  • Understand what a CSS framework is and why they are so popular.
  • Include Bootstrap in a project using a CDN link.
  • Use Bootstrap's grid system and pre-styled components like cards and buttons.

How to Add Bootstrap to Your Page

Imagine you want to build a giant LEGO castle. You could make every single brick yourself, or you could use special, pre-made castle wall pieces that someone else designed. Bootstrap is like a giant box of pre-made LEGO pieces for your website!

But how do we get that box of pieces? We use a special HTML tag called <link> to connect to a CDN.

<link> Connects to other files
This tag, which goes in your <head> section, creates a connection to another file. We use it to link to our Bootstrap CSS file. Think of it as telling your webpage: "Hey, go use all the cool styles from this other file!"
CDN Content Delivery Network
The Bootstrap file is hosted on the internet on something called a CDN. A CDN is like a super-fast online library for code. By linking to the CDN, we don't have to download the file ourselves. Our webpage can just borrow it from the library whenever it needs it! You can see the CDN link in the editor inside the <head>.

Understanding Bootstrap Classes

Bootstrap works by providing you with a huge library of CSS classes. Instead of writing your own styles, you just add these classes to your HTML elements.

.container Page Layout
This class provides a centered, fixed-width container for your content, making it look neat and organized.
.row & .col-md-6 Grid System
The grid is the foundation of Bootstrap layouts. You create a .row and then place columns (like .col-md-6) inside it. This example creates two columns that each take up half the screen on medium-sized devices and larger.
.card & .alert Components
Bootstrap comes with dozens of pre-styled components. .card is perfect for showing content in a neat box, and .alert is great for displaying messages.
.btn & .btn-primary Utility Classes
Utility classes are simple, single-purpose classes. .btn styles a button, and .btn-primary gives it a blue color. You can combine many utility classes to style elements quickly.

Your Mission: Build with Bootstrap

Your mission is to use Bootstrap classes to structure and style the plain HTML in the editor. You don't need to write any CSS in the <style> tag for this lesson!

Pro Tip

Notice the Bootstrap CSS file is already linked in the <head>. All you have to do is add the correct classes to the HTML elements in the <body>.

  • Step 1: Create the main container. Wrap everything inside the <body> with a <div class="container mt-5">. The mt-5 is a utility class that adds margin to the top.
  • Step 2: Add the title. Give the <h1> the classes text-center and text-primary to center it and make it blue.
  • Step 3: Build the grid. Wrap the two inner <div>s with a <div class="row">. Then, give each of the inner <div>s the class col-md-6. Let's break that down:
    • col stands for Column.
    • md stands for "medium". This means the rule applies to medium-sized screens (like tablets and desktops) and larger. On smaller screens, the columns will stack on top of each other.
    • 6 means the column should take up 6 of the 12 available units in the row. So, two col-md-6 divs will each take up half the space (6 + 6 = 12).
  • Step 4: Style the card. For the first column, add the card class to the outer div and card-body to the inner div. Add the classes card-title to the h5, card-text to the p, and btn btn-primary to the button.
  • Step 5: Style the alert. For the second column, add the classes alert alert-success to the div.

Take It Home

Experiment with other Bootstrap components! Try adding an <div class="alert alert-warning"> or a <button class="btn btn-danger">. In our next lesson, we'll bring our pages to life with JavaScript!

Bootstrap Editor

Activity: Using Bootstrap Classes
index.html
Live Preview