How to create a button with a background image in bootstrap?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

To create a button with a background image in bootstrap, put the css class .btn { background-image: url('image/button.jpg');}. it will create a button with a background image in bootstrap.

Today, I am going to show you. how to create a button with a background image in bootstrap with code example.

Table of contents

  • Includes bootstrap view
  • Includes bootstrap library
  • Define its css class

This article will guide you to creating a button with a background image in bootstrap with example.

Step 1: 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">

Step 2: 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>

Step 3: Define its css class

After that, to create a button with a background image, you have to use css class .btn. the included background-image:url('image/button.jpg'); and set the background size of the cover.

     .btn {
            background-image: url('image/button.jpg');
            background-size: 100px;
            background-repeat: no-repeat;
            background-position: center; 
       }

Example.

Let’s look at the following example to understand how it basically 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>
</head>
<body>
    <style>
        .btn {
            background-image: url('image/button.jpg');
            background-size: 100px;
            background-repeat: no-repeat;
            background-position: center;
        }
    </style>
    </head>
    <body>
        <div class="text-center">
         <h3>Create a button with a background image in bootstrap</h3>   
       <button class="btn">Button</button>
       </div>
    </body>
</html>

Check the output of the above code example.

Bootstrap, background, image

All the best 👍

Premium Content

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

Books

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.

I'm working on some more Cheat Sheets book on Jquery, TypeScript, React js and for other languages. I will send it once it's completed.

Stay tuned working on React Js Cheat Sheets Book

Related Posts