BS4 Basic Template


Bootstrap 4 Basic Template is the foundation of a web page that includes all necessary components to start building a responsive and mobile-first website. It provides the HTML structure along with links to Bootstrap 4 CSS, JavaScript, and dependencies, so developers can immediately use the framework’s classes and utilities.

Using a basic template ensures that your website follows best practices in terms of responsiveness, alignment, and compatibility, allowing you to focus on designing content and layout rather than repeatedly adding the same links and scripts to every page.

Essential Components of a Bootstrap 4 Basic Template

A typical Bootstrap 4 basic template consists of:

  1. DOCTYPE and HTML Structure
    Every HTML page starts with the <!DOCTYPE html> declaration and <html>, <head>, and <body> tags.

  2. Meta Tags for Responsiveness
    The meta tag <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> ensures that the page scales correctly on different devices.

  3. Bootstrap 4 CSS
    Linking to the Bootstrap 4 CSS file provides access to all pre-defined styles, grids, and utilities.

  4. Optional JavaScript Dependencies
    Bootstrap 4 requires jQuery and Popper.js for interactive components like modals, tooltips, and dropdowns.

  5. Bootstrap 4 JavaScript
    Linking to the Bootstrap JS file enables all interactive elements to function properly.

Bootstrap 4 Basic Template Structure

Here’s a standard Bootstrap 4 basic template:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>Bootstrap 4 Basic Template</title>
  <!-- Bootstrap 4 CSS -->
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>

  <header class="bg-primary text-white p-3 text-center">
    <h1>Welcome to Bootstrap 4</h1>
  </header>

  <main class="container mt-5">
    <p>This is the main content area using a fixed-width container.</p>
  </main>

  <footer class="bg-dark text-white p-3 text-center mt-5">
    <p>Bootstrap 4 Template Footer</p>
  </footer>

  <!-- jQuery, Popper.js, Bootstrap JS -->
  <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>

Breaking Down the Bootstrap 4 Basic Template

1. The Head Section

The <head> section contains:

  • Meta tags for character set and viewport settings.

  • Page title for SEO and identification.

  • Bootstrap 4 CSS link to apply framework styling.

Properly setting the viewport ensures mobile-first responsiveness, which is one of the main advantages of using Bootstrap 4.

2. Header Section

Headers are often the first element visitors see. In the example:

<header class="bg-primary text-white p-3 text-center">
  <h1>Welcome to Bootstrap 4</h1>
</header>
  • .bg-primary applies a blue background.

  • .text-white sets the text color.

  • .p-3 adds padding.

  • .text-center centers the text horizontally.

Using Bootstrap 4 utility classes allows rapid styling without writing custom CSS.

3. Main Content Area

The main section usually uses a fixed-width container for better readability:

<main class="container mt-5">
  <p>This is the main content area using a fixed-width container.</p>
</main>
  • .container ensures the content remains centered and responsive.

  • .mt-5 adds margin at the top for spacing from the header.

  • Inside this container, you can use Bootstrap grids, cards, forms, and other components.

4. Footer Section

Footers typically span the full width or match the container width, depending on the layout. Example:

<footer class="bg-dark text-white p-3 text-center mt-5">
  <p>Bootstrap 4 Template Footer</p>
</footer>
  • .bg-dark gives a dark background.

  • .text-white ensures readability.

  • .text-center centers the text.

  • .p-3 provides padding.

  • .mt-5 separates the footer from the content above.

5. JavaScript Dependencies

Bootstrap 4 interactive components require jQuery and Popper.js, followed by the Bootstrap JS file:

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

This ensures components like dropdowns, modals, carousels, and tooltips function correctly.

6. Benefits of Using a Bootstrap 4 Basic Template

  1. Responsive foundation: The template automatically adjusts to all devices.

  2. Ready-to-use components: You can start adding headers, buttons, forms, and grids immediately.

  3. Consistent design: Provides a uniform look across multiple pages.

  4. Time-saving: Developers don’t need to set up CSS, JS, and meta tags repeatedly.

  5. SEO-friendly: Proper meta tags and structure improve page visibility in search engines.

Best Practices for Bootstrap 4 Basic Template

  • Always include the viewport meta tag for mobile responsiveness.

  • Use .container for main content and .container-fluid for full-width sections.

  • Include jQuery, Popper.js, and Bootstrap JS in the correct order.

  • Keep header, main, and footer sections organized for clear structure.

  • Use utility classes instead of custom CSS when possible for faster development.

Summary of the Tutorial

This tutorial explained how to set up a Bootstrap 4 Basic Template, covering all essential components: the HTML structure, meta tags for responsiveness, linking Bootstrap CSS and JS files, and creating a header, main content area, and footer. You learned how utility classes like .container, .container-fluid, .bg-primary, and .text-center make development faster and more consistent. By using this template, you can quickly start building responsive Bootstrap 4 web pages without repeatedly configuring foundational elements.


Practice Questions

  1. Create a new HTML page and link Bootstrap 4 CSS and JS files using the CDN.

  2. Build a header section with a background color, white text, and centered heading.

  3. Add a main content area inside a .container with a paragraph and margin at the top.

  4. Create a full-width footer using .container-fluid with centered text and padding.

  5. Use Bootstrap 4 utility classes to add spacing (.p-3, .m-4) to header and footer sections.

  6. Implement a responsive layout with two columns inside the main container using .col-md-6.

  7. Add a secondary heading in the main content area with .text-center and .text-primary.

  8. Include a Bootstrap 4 button inside the main content with .btn and .btn-success.

  9. Make a small navbar at the top using .navbar, .navbar-light, and .bg-light.

  10. Add a responsive image inside the main content area using .img-fluid.


Try a Short Quiz.

coding learning websites codepractice

No quizzes available.

Go Back Top