Day 1: Bootstrap 4 CDN and Starter Template

Hello and welcome to the first day of the 14 days of Bootstrap 4 series 🙂 Today we will make the first step towards using Bootstrap 4!

In order to see the Bootstrap 4 capabilities and use it, you will need to import the Bootstrap 4 CSS and JS files into your HTML file. In this article you will find how to use the Bootstrap 4 CDN or download your files locally. You might have heard the phrase “how to install Bootstrap 4” before but there really isn’t anything to install. Getting started with Bootstrap 4 will just mean adding links to your page.

The article will be divided into the following parts:

Let’s get the party started!


Photo credit to YaroFlasherfor his shot.

Bootstrap 4 CDN

In order to use the Bootstrap 4 components, you need to import the CSS and JS files into your application. The fastest way is to use the Bootstrap 4 CDN. CDN is short “content delivery network”. You can read more about CDNs and how they work here.

You will need to add the CSS file between the <head></head> tags:

And you will need to add the JavaScript libraries inside <script></script>tags at the end of the document. The Bootstrap 4 Javascript relies on jQuery and PopperJs, so you first need to import these 2.

Taking into consideration all of the things mentioned above, we get the following template. You can use it as a Bootstrap 4 starter template in each of the following days (you first set up this structure and then add components).

Downloading Bootstrap 4 Files Locally

If you don’t want to depend on CDNs, you can download the necessary files and include them (using your local path). You can get the Bootstrap source files from here. Once you have your CSS and JS, you will need to import them like in the case of the CDN, only you will use your local path:

Using a Package Manager

If you are familiar with package managers, you can try one of the following. If you haven’t used one before skip to the next section for now.

Additional Required Tags for Your Page

You should be sure you have the following tags in your page (already included in the starter template):

  • HTML5 doctype – if you don’t have it, some unpredictable behaviour may occur.

  • the responsive meta tag.

This is ensures that the page displays correctly on mobile and that you will be able to zoom on in.

Ok, Now What?

Is starting a project with Bootstrap 4 different from creating a normal HTML file? Yes, because you will be able to add multiple pre-built components while creating your page. But also because Bootstrap 4 will overwrite the default browser styling that is displayed in a simple HTML file. This means that you will not have to add any special classes or components in order to start seeing changes.

Bootstrap 4 Reboot

Let’s start with a very simple example. I will write some simple HTML elements: headings, paragraphs, links, tables and links. The code will be the same for both files (with and without Bootstrap 4):

And the results will be different:

See the Pen HTML Starter Template by cristina (@cristinaconacel) on CodePen.dark

This is how the simple HTML page looks like.

See the Pen Bootstrap 4 Starter Template by cristina (@cristinaconacel) on CodePen.dark

And this is how the Bootstrap 4 page looks like.

If you look closely at the two examples, you will be able to see some differences:

  • the fonts are different;
  • the default spacing varies;
  • the styling for the link looks different.

Of course, these differences are not ground-breaking and you could easily write them yourself in a CSS file. But when you start creating complex pages, writing the CSS yourself becomes a much more difficult task.

You would need to test your code on all browsers and devices and make sure it is responsive. You would also need to design your components with a hierarchy in mind that will not make classes redundant. It is possible that you would end up trying to recreate what Bootstrap 4 is already doing. So it is much easier to go with their already implemented and tested library.

In the next days we will take a look at the most important parts of Bootstrap 4. We will see why they are useful and how to use them, so you don’t have to “reinvent the wheel”.

Further Reading

If you still have some time on your hands, I would suggest looking at the official Bootstrap 4 getting started guide too:

You can see the code for this day on Codepen. You can fork and edit the code and see how elements looks like in Bootstrap 4. If you have any questions, let me know in the comments below!

Sharing is caring!

Cristina Conacel

Cristina is a web developer and the owner of BootstrapBay. She likes foxes, clean design, writing blog posts and creating themes that are useful to other developers.