17min remaining

If you’re creating a website for your business, then you probably have a long wish list.

You want the design to reflect the look and feel of your brand. You want to have the functionality required to meet the needs of your visitors without going over budget. And you want to create responsive layouts that display elements like buttons and forms consistently, no matter what device or browser the visitor is using.

By building with Bootstrap, you can check that last item off your list. Bootstrap is an open-source framework for quickly building responsive websites and mobile-first web projects. Because it offers a collection of reusable code, you won’t have to build a site from scratch.

To understand why over21 million websites on the internet use Bootstrap, let’s take a closer look at what it is.

Download Now: Free Intro Guide to HTML & CSS

Though Bootstrap is an open-source toolkit for developing withHTML, CSS, and JavaScript, it is often referred to as a CSS framework.

To understand why, you must first understand that CSS is generally easier to learn for people at all levels of technical experience and is faster in browsers than JavaScript. For these reasons, Bootstrap developers wrote in CSS (andHTML) over JavaScript whenever possible. The CSS library included in Bootstrap is therefore much larger than the JavaScript library.

Since Bootstrap makes it easier and faster to create responsive websites, it appeals to many front-end developers and beginners in particular. However, it’s not recommended by all. Below we’ll look at why Bootstrap is so popular and when it’s ideal to use — and when it’s not ideal.

Why Bootstrap?

Bootstrap is the go-to toolkit for many front-end developers. According toW3Techs, it's used by 22.1% of all websites on the internet.

There are a few factors driving Bootstrap’s popularity. First and foremost, it’s open-source and therefore free to download and use. It’s also fully customizable, and compatible with all modern browsers. This is true of many CSS frameworks, however.

What sets Bootstrap apart from other development toolkits is that it was developed mobile-first. Meaning, the code was optimized for mobile devices (i.e. the smallest screen size) first and then scaled up to display on larger screens. As a result, building with Bootstrap CSS ensures that your site supports proper rendering and touch zooming for all devices.

Another reason Bootstrap is so popular is that it’s easy to use. It comes bundled with templates for typography,forms, buttons, drop-down menus, navigation, and other interface components. Using these pre-styled templates, you can add features that enrich theuser experienceon your site without having to code them from scratch.

When to Use Bootstrap

There are many reasons to use Bootstrap. We’ve discussed some above but let’s take a closer look at these reasons below.

1. You want a responsive website.

Building a responsive site is much easier using Bootstrap than doing so from scratch. Bootstrap comes with responsive styles, like containers and media queries, to ensure your site adjusts to the viewport. That means you don’t have to worry about whether your visitors are using desktops, tablets, or mobile devices.

2. You want to save time.

You can build your site quickly with Bootstrap. Once you download the framework, you can get started with a basic template and then add the components you need. These components are fundamental HTML elements, like tables, forms, buttons, images, and icons, that are styled with a base class and extended with modifier classes. Using these pre-designed components significantly limits the amount of custom CSS you have to write.

ConsiderBootstrap buttonsfor example. The base class .btn is used for all the common styles you want for your buttons, like display, padding, border-width. With this class, you don’t have to keep repeating these CSS properties in your stylesheet to format every single button you add.

Modifier classes, like .btn-primary on the other hand, are used to add the more specific styles you want for your buttons, like color, background-color, and border-color of your buttons. This is just one example of how using Bootstrap components is much faster than coding them from scratch.

3. You’re familiar with HTML and CSS.

Though Bootstrap does simplify the process of building a site, you’ll have to be familiar with HTML and CSS to use the framework. For example, understanding theCSS box modelwill be important when using the container class and building your first Bootstrap grid.

The good news is you’ll only need abasic knowledge of codingto get started.

4. You have multiple people building out your site.

If you have multiple collaborators working on a site, then consistency is important. You don’t want buttons on your homepage to look different from buttons on your landing page, or to use a differentwebsite typographyon your blog than anywhere else on your site — and so on. Using Bootstrap and its default settings, utility classes, and component elements can help ensure the front end of your site looks consistent.

5. You want to be part of a community.

Since Bootstrap is open source, it has a global community of developers and designers dedicated to supporting the framework. These developers and designers modify and enhance Bootstrap's codebase onGitHub. They also answer questions onTwitter,Stack Overflow, and in adedicated Slack room. When using Bootstrap, you can leverage this active community to become a better Bootstrap user.

When Not to Use Bootstrap

While there are many benefits of using this CSS framework, there are some reasonsnotto use Bootstrap as well. Let’s take a closer look at these reasons below.

1. You want a unique website.

Since Bootstrap comes with pre-styled content, components, and templates, Bootstrap sites tend to look the same out-of-the-box. In fact, Bootstrap has been blamed forwhy websites today all look the same.

You can customize a Bootstrap site, but it’ll take time. Plus, if you have to override too much of the default styling, then it might make more sense to create your own stylesheet in the first place.

2. You want a theme.

The Bootstrap framework is not a theme — though there are Bootstrap themes available. Let’s compare the framework to aWordPress theme, for example.

When youinstall and activate a WordPress theme, it changes your entire site’s appearance. When you download the Bootstrap framework, aspects of your site’s appearance will change automatically, like the typography. But you still have to write the HTML and plug in the preset layouts, colors, and components you need to make up your website.

3. You want a fast-loading site.

Bootstrap can negatively impact the speed of your website. Why? Because it’s heavy — not in terms of KB, exactly, but in terms of how much the average userdoesn’tuse.

Bootstrap is less than 500KB. You can also take several steps to reduce that weight and mitigate its impact on load time. For example, you can use the minified CSS and JavaScript files Or you only download the CSS files, not the JavaScript ones.

But even with these steps, Bootstrap can still be too heavy for what you need. Most users don’t need all the components, utilities, and plugins that Bootstrap comes with, so they might be weighing down your site even if they’re not being used.

4. You don’t have time to learn and read through the Bootstrap documentation.

Bootstrap is considered an easy-to-use platform. It offers extensive documentation for every part of its framework, from its layout to content to components and more. That means virtually anyone can learn Bootstrap — it also means it will take time to read through the documentation and learn the framework. If you are looking to build a website as quickly as possible, then Bootstrap might not be as ideal as other solutions, likewebsite builders.

5. You want to master HTML and CSS.

Using the pre-designed components and templates that Bootstrap provides makes it much easier and faster to build a website — but it can also stunt your growth as a coder. Creating with Bootstrap is like using a calculator to do algebra: you can end up with the result you want without totally understanding how you got it. That's why it's good to spend time creating your own custom components, even if you also learn and use Bootstrap.

Now that we understand what Bootstrap CSS is and who should be using it, let’s briefly discuss the different download options you have.

How to Download Bootstrap CSS

Before we walk through the process of downloading Bootstrap, it’s important to note that you can load Bootstrap remotely viaBootstrapCDNorjsDelivrinstead of downloading it. This will require visitors to have an internet connection to visit your site and will require you to post more code, however. As a result, downloading Bootstrap is the more popular choice.

There are two different forms of Bootstrapavailable for download. Each version — a precompiled and a source code version — appeal to different users depending on whether they prioritize ease-of-use or flexibility. Let’s take a closer look at each below.

Precompiled Bootstrap

The precompiled version is the most basic form of Bootstrap. You’ll download precompiled CSS and JS files and minified CSS and JS files that are easy to drop in nearly any web project.

Once downloaded, you’ll unzip the compressed folder and see the following structure.

bootstrap/

├── css/

│ ├── bootstrap-grid.css

│ ├── bootstrap-grid.css.map

│ ├── bootstrap-grid.min.css

│ ├── bootstrap-grid.min.css.map

│ ├── bootstrap-reboot.css

│ ├── bootstrap-reboot.css.map

│ ├── bootstrap-reboot.min.css

│ ├── bootstrap-reboot.min.css.map

│ ├── bootstrap.css

│ ├── bootstrap.css.map

│ ├── bootstrap.min.css

│└──bootstrap.min.css.map

└── js/

├── bootstrap.bundle.js

├── bootstrap.bundle.js.map

├── bootstrap.bundle.min.js

├── bootstrap.bundle.min.js.map

├── bootstrap.js

├── bootstrap.js.map

├── bootstrap.min.js

└── bootstrap.min.js.map

Using the compiled version is easier and faster to use than the source code version — but it’s more difficult tocustomize. Any change you want to make to a pre-styled element or layout has to be applied with an override to the current styles.

If you want to customize the CSS and JS files included in Bootstrap as you please, then you’ll be better off downloading the source code version.

Bootstrap Source Code

The source code version includes the precompiled CSS, JS, and font assets as well as source files for the CSS, JS, and icon fonts respectively.

If you choose to download the Bootstrap source code, then you’ll unzip the folder and see the following structure.

bootstrap/

├── dist/

│ ├── css/

│ └── js/

├── site/

│ └──docs/

│ └── 4.6/

│ └── examples/

├── js/

└── scss/

The dist/ folder contains everything listed in the precompiled section above. The docs/ folder includes the source code for Bootstrap documentation and examples of Bootstrap usage. The js/ folder contains the source code for Bootstrap JS and the scss/ folder for Bootstrap CSS.

Since this version of Bootstrap requires you to haveAutoprefixerand a SASS compiler, the set-up process is longer and more difficult than setting up the pre-compiled version. Once set up, however, you can change and customize the files any way you want.

Each version of Bootstrap is ideal for different use cases, but because the precompiled Bootstrap is simpler and faster to use, we’ll focus on that version for the rest of the post.

Below let’s look at how you can use the precompiled Bootstrap to build a website.

Let’s break down this process step-by-step.

Loading Bootstrap CSS and JS

First, create a folder on your computer called “bootstrap.” Move the compiled CSS files from your Bootstrap download into that folder. If you are also using the JS part of Bootstrap, move the compiled JS files into the folder as well.

In that same folder, create another file and call it index.html. Open this file with a text editor of your choice, likeNotepad++. You can copy and paste thebasic HTML template on Bootstrap’s official siteinto the file or code it from scratch.

Below is an example of an HTML page coded from scratch.

Bootstrap Tutorial Sample Page



You’re now ready to load Bootstrap CSS into your project. Simply add the following line of code into the header of the index.html file, right before the tag.

If you plan to just use the CSS part of Bootstrap, then you’re all set.

If you plan to use the JS part as well, then you need to add two more lines of code. Components including alerts, toggle buttons,carousels, and dropdowns require the use of JavaScript to function so continue these steps if you want to add any of these elements to your site.

First, you’ll need to load the jQuery library. To do so,download jQueryonto your computer. Unzip the file and save it in the “bootstrap” folder along with the compiled CSS and JS files and index.html file.

You’ll then add the following line of code in the index.html file. This time, you’ll add it to the footer, instead of the header, right after the tag.

To load Bootstrap JavaScript, add the following line of code right after the call for jQuery.

Once you’ve completed these steps, this is what your index.html file should look like:

Bootstrap Tutorial Sample Page

Once you save the folder, you’ll have a basic Bootstrap layout that looks like this:

Basic Bootstrap layout with heading that says Hello, world!

This can now function as the homepage of your site.

Building a Basic Template

To continue building this page, you can add a navigation bar, header, footer, glyphicon font,favicon, and other interface components. Let’s walk through adding one component — a navigation bar — step-by-step so you understand how to use Bootstrap.

Say you want toadd a Bootstrap navbarthat looks something like this to the homepage:

Basic Bootstrap layout with dark navbar with search form and toggle buttonNow a prospect can arrive on your homepage and immediately find out more about your company, the features of your product, and your pricing — or they can search something else.

Below is the code for this Navbar example.

Let’s break this snippet down into its supported subcomponents: color scheme, brand, toggler, nav, and form.

色彩原理图eme

Take a closer look at that first line of code. Seenavbar-dark bg-dark? That calls for a dark background color. If you prefer a light color scheme, replace with navbar-light bg-light. It will look something like the following:

Basic Bootstrap layout with Bootstrap Navbar with light color schemeOr you can choose one of the otherdefault colors.

Brand

In that second line of code, seenavbar-brand? That designates your company, product, or project name. Simply replace “Navbar” before the tag with the correct name.

Toggler

Next, you’ll see a big chunk of code that denotes the toggle button. This button is hidden on desktop. It appears only on mobile, when the content of the navigation bar must be collapsed to fit the smaller screen.

In the code above, thenavbar-togglerstyle is defined so the brand name shows on the left of the mobile screen and the toggle button on the right. Clicking on the button will reveal the collapsed content, as shown below.

Bootstrap Navbar with toggle button displayed on mobile

Nav

In the next bit of code, seenavbar-nav? Using this subcomponent, you can add links in your navigation bar. You just need to wrap the appropriate modifier class (nav-link) around the word you want to hyperlink.

Form

You can also add a form, like a search box, in your navigation bar with theform-inline子组件。你可以看到这一些代码bottom of the template above.

Now that you know how to add Bootstrap’s responsive navigation header with branding, navigation, and more, you can follow a similar process to add other elements to the page. Let’s take a look at a few of those below.

Bootstrap CSS Examples

Bootstrap offers HTML and CSS templates, or “examples,” to help you start building your site quickly. While Bootstrap Source Code comes with more advanced examples with custom components and layouts that add onto the framework, we’re going to focus on examples that use built-in components available in both the precompiled and source code versions.

We’ve already touched on a few examples above, including the Navbar. Below we’ll take a closer look at a few additional examples.

Bootstrap Grid

CSS grid systemsare used for creating page layouts through a series of rows and columns that house content. In the Bootstrap grid system, rows must be placed within a .container (fixed-width) or .container-fluid (full-width) for properpositioningandpadding. These rows are used to create horizontal groups of columns.

由于引导是12日的一篇专栏系统,你会有to specify the number of twelve available columns you wish to span. Say you’d like to create three equal-width columns that are centered on the page across devices at any size. Then you need three “four-of-twelve” columns, as represented by the .col-4 class. Below is the grid example in full.

One of three columns

One of three columns

One of three columns

On the front-end of your site, it would look like this on mobile and desktop.

Bootstrap grid with three equa-widthl columns

But what if you want the grid to appear one way on desktop and another way on mobile? Let’s say you want the columns to appear side-by-side on desktop, but stack on top of each other on mobile.

Then you can specify the width of the columns with the prefix for “small.” This would make the columns 100% wide until the small breakpoint (576px). Below is the grid example in full.

One of three columns

One of three columns

One of three columns

The video below shows how it would look on desktop and then change on mobile.

Bootstrap grid with three columns displays differently on desktop and on mobile-min

Image Source

There are many more options you can play around with. Using Bootstrap’s grid system, you can create equal-width columns that span multiple lines. You can set the width of one column and have the sibling columns automatically resize around it. You can size columns based on the natural width of their content — and much more.

Bootstrap Alerts

You can add alerts to your Bootstrap site to provide important messages to your visitors. Bootstrap offers eight default colors for alert messages. Let’s say you want to add an alert to indicate that a visitor has successfully created an account, for example. Then you can use the example below.

It will look like this on the front-end of your site.

Basic Bootstrap layout with Bootstrap success alert

If you’ve loaded the compiled JS onto your site, you can alsoadd a dismiss buttonto let visitors close the alert once they’ve read it.

Bootstrap Buttons

With Bootstrap, you can choose from several predefined button styles to quicklyadd buttons to landing pages or forms on your Bootstrap site. Let’s say you want to add an “info” button to your site. Below is the example and how it would look on the front end.

Basic Bootstrap layout with heading and Info button

While the .btn classes are designed to be used with the