In previous bootstrap chapters, we learned what is bootstrap? and how to setup bootstrap environment. Now, we will learn how to create a simple bootstrap hello world application by using bootstrap components with example.
To create a bootstrap web page template, first we need to include HTML5 doctype
at the beginning of the page, along with lang
and viewport
meta tags for proper responsive behavior as shown below.
If you observe the above HTML code, we added lang
and chartset
attributes to specify the language and chart encoding for the HTML document. We included HTML5 doctype
at the beginning of the page because Bootstrap requires HTML5 doctype
to render HTML elements and CSS properties without any styling problems.
As discussed, the Bootstrap framework is built with a mobile-first strategy to ensure that the design is responsive for mobile devices. So, to ensure proper rendering and touch zooming for all devices we included viewport
meta tag in <head>
element.
Here, the width=device-width
part is useful to adjust the page width based on the screen width of the device and initial-scale=1
part is useful to set the initial zooming level whenever the page is first loaded by the browser.
Along with the above meta tags, we need to include the required Bootstrap CSS and JS files to convert the above HTML template to a bootstrap template like as shown below.
This is the basic template format that we need to create to use a bootstrap framework in our application. Here, the JS files (jquery.js, popper.js, bootstrap.js) are optional, and those are required to add only when you try to use bootstrap JS components such as alerts, modals, buttons for toggling, carousel for sliding, tooltips, etc.
While adding JS files (jquery.js, popper.js, bootstrap.js), you need to make sure that the jQuery comes first, second Popper.js, and last bootstrap.js file like as we mentioned in the above code.
To improve the performance of your web pages, include your JavaScript files at the bottom of the page, right before the closing </body>
tag, instead of adding it in <head>
tag.
The above example will return the result as shown below.