How to add a background image to the navbar in bootstrap 5?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

To add a background image to the navbar in bootstrap 5, use the background-image: url("image/flower.jpg");. It will add a background image to the navbar in bootstrap 5.

Today, I am going to show you. how to add a background image to the navbar in bootstrap 5 with code example.

Table of contents

  • Includes bootstrap view
  • Includes bootstrap library
  • Example of background image to the navbar in bootstrap

This article will guide you to add a background image to the navbar in bootstrap 5 with an example.

Includes bootstrap view

To ensure proper rendering and touch zooming for all devices, add the responsive viewport meta tag to your <head>.

<meta name="viewport" content="width=device-width, initial-scale=1">

Includes bootstrap library

First of all, load the Bootstrap framework CSS into the head tag of your webpage.

<!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>

Example of background image to the navbar in bootstrap

In this example, we will add the navigation bar with this code background-image: url("image/flower.jpg"); and background-repeat: no-repeat; and background-size: cover;.

Let’s look at the following example to understand how it works:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Create a button with a background image in bootstrap</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>

    <style>
      .container-fluid{
      background-image: url("image/flower.jpg");
      background-repeat: no-repeat;
      background-size: cover;
      }
      </style>
</head>
  <body>
    <nav class="navbar navbar-expand mt-3">
        <div class="container-fluid bg-dark">
            <div class="navbar-nav">
                <a class="nav-link text-light">One</a>
                <a class="nav-link text-light">Two</a>
                <a class="nav-link text-light">Three</a>
                <a class="nav-link text-light">Four</a>
            </div>
            <div class="w-100"></div>
        </div>
    </nav>
    </body>
</html>

Check the output of the above code example.

Bootstrap, background, image

Try the below codesandbox link to customize the above example as per your requirement.

Try it Yourself

All the best 👍

Premium Content

You can get all the below premium content directly in your mail when you subscribe us

Books

Interview Questions

Soon You will get CSS, JavaScript, React Js, and TypeScript So Subscribe to it.

Portfolio Template

View | Get Source Code

Cheat Sheets

Cheat Sheets Books are basically Important useful notes which we use in our day-to-day life.

Related Posts