Customizing Bootstrap 4 Checkbox Styles

Looking for a way to customize a checkbox in Bootstrap 4? I've been struggling to change the background color with no success. Here is the code I'm working with:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<label class="custom-control custom-checkbox">
      <input type="checkbox" class="custom-control-input">
      <span class="custom-control-indicator"></span>
      <span class="custom-control-description">Check this custom checkbox</span>
</label>

I'm not sure what to target here to change the background color. Can someone provide some guidance on how to do this?

Appreciate any help or advice you can offer. Thank you.

Answer №1

This solution was successful for me:

.custom-checkbox .custom-control-input:checked~.custom-control-label::before {
    background-color: #caca4c;
}
.custom-control-input:checked~.custom-control-label::before {
    color: #fff;
    background-color: #caca4c;
}

Answer №2

.custom-control{
  background-color: grey;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<label class="custom-control custom-checkbox">
      <input type="checkbox" class="custom-control-input">
      <span class="custom-control-indicator"></span>
      <span class="custom-control-description">Check this custom checkbox</span>
</label>

Answer №3

To change the style of custom-control-indicator, you need to override it.

Here's how you can do it:

<!DOCTYPE html>
<html>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">

<style>
.custom-control-input:checked~.custom-control-indicator{
color:white;
background-color:red;
}
</style>
<body>

<label class="custom-control custom-checkbox">
      <input type="checkbox" class="custom-control-input">
      <span class="custom-control-indicator"></span>
      <span class="custom-control-description">Check this custom checkbox</span>
</label>
</body>

</html>

Answer №4

I created a small demonstration for you

<style>
        .custom-checkbox {
            padding: 0;
        }

            .custom-checkbox .fa-toggle-on,
            .custom-checkbox .fa-toggle-off {
                font-size: 135%;
                /*this icon is relatively small*/
            }

            .custom-checkbox input[type=checkbox] {
                visibility: collapse;
                width: 0px;
                margin-left: -0.25em;
            }

                .custom-checkbox input[type=checkbox] ~ .custom-check-on {
                    display: none;
                }

                ...

</style>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" rel="stylesheet"/>
<div class="container">
        <h3>Create custom checkbox with Bootstrap and Font Awesome</h3>
        <p>Here are some samples of custom checkboxes. You can use any shape or color to customize them as you like.</p>
        <label class="custom-checkbox">
            <input name="check" type="checkbox" autocomplete="off" >
            ...
            ...
        </label>

        ...

    </div>

<div class="container">
    <h3>Create custom checkbox with Bootstrap and Font Awesome</h3>
    <p>Here are some samples of custom checkboxes. You can use any shape or color to make them the way you want.</p>
    ...
    ...
</div>

https://jsfiddle.net/eghbaly/t4zvshdu/4/ https://github.com/eghbaly/BS-CustomCheckbox

Answer №5

I share the same query as olefrank. I am interested in implementing a different image. For instance, on our intranet's forms page, instead of using a checkbox to indicate a favorite form, I would like the user to choose a star symbol. I was able to achieve this with images following the guidelines outlined in Bootstrap 4 documentation:

<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="customCheck1">
<label class="custom-control-label" for="customCheck1">Select this custom checkbox</label>
</div>

Next, I included the following CSS:

.custom-checkbox .custom-control-label::before {border-color: transparent; background-color: transparent;}
.custom-checkbox .custom-control-label::after {background-image: url(five-pointed-star.svg); background-size: 100%;}
.custom-checkbox .custom-control-input:checked~.custom-control-label::before {border-color: transparent; background-color: transparent;}
.custom-checkbox .custom-control-input:checked~.custom-control-label::after {background-image: url(five-pointed-star-selected.svg); background-size: 100%;}

However, I am eager to learn how to specify an alternative image using a web font, though this is currently beyond my expertise!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensure that the input group is entirely visible and does not wrap within a table cell

I am facing an issue with an input group placed in a table cell where the button wraps below a certain size. I want to prevent this behavior specifically for this table cell and the rest of the column. The relevant html generated with added javascript elem ...

Using both .table-active and .table-stripped simultaneously will cause conflicts and not work properly

I have a .table-striped table and I want to highlight some rows in it. I am using the .table-active class, but it only works in about half of the cases - specifically when the row has a 'white stripe' background. Is there a way to highlight rows ...

Issue with Django Ajax Post functionality not working correctly

Hey everyone, I'm currently facing an issue with passing a variable from jQuery to the views. I've tried to get the value to show up in the DOM, but it isn't working for me. I could really use some assistance with this. Take a look at the ...

How to apply distinct CSS styles to individual pages in Orchard CMS?

If we have two pages within Orchard CMS - the homepage and the About Us page, is there a way to include a RoyalSlider on just the homepage without affecting the About Us page? Within Orchard CMS, I am utilizing the Contoso theme. Previously, I attempted t ...

Arranging the button next to the text input field in an Angular application

I added a button labeled "X" to a page, but it is currently positioned below a textfield. How can I use Bootstrap to align the button next to the textfield instead? https://i.sstatic.net/kbX5S.png <div class="form-group row"> <div class ...

Is there a way to adjust the width of my web layout without sacrificing its responsiveness?

Struggling with my website layout design as I encountered an issue. The overall width of the layout is too excessive, and I want to introduce some margins on the sides for a better visual appeal. Although the responsive design works well originally, adding ...

I'm looking to extract information from a webpage using Python by inputting specific criteria

Looking to gather information from a specific website - Link and save it either in a database or another location. The process involves providing input parameters such as entering the vehicle number, submitting it, then verifying if it matches your car. N ...

The lengthy string is not breaking into separate lines as expected in Internet Explorer

My querystring is quite long http://terra.cic.local/web/index.cfm//pm/uebersicht?sucheAufgeklappt=was%2Cwie%2Cwohin%2Cwann%2Cwer&sucheVon=&sucheBis=&sucheIstErsteSeiteAnzahlProdukteErmitteln=false&sucheIDReiseart=26&sucheHotelart=1081& ...

Retrieve JSON data within a service and provide it to a component

I am currently facing an issue with loading data from a JSON file into my component using a service. The data is successfully loaded in the service, as confirmed by the console log; however, when trying to access the data in the component, it does not disp ...

Looking for assistance with my website's navigation bar and logo

Looking for assistance in moving my navigation buttons to each side of the logo. As a beginner in web design and CSS, I've been struggling with this task. Essentially, I want the "home" and "about" buttons on the left side of the logo, 16px apart from ...

How can I make multiple elements change color when hovering with CSS?

Hey there! I have a little design challenge that I need help with. On my website (), I am trying to make multiple elements of a specific item change color when the user hovers over the text. If you hover over the "more" menu item, you'll notice that o ...

Transform input string containing newline characters into separate paragraphs

I utilize Contentful CMS for content management and fetch the content through their API. When the content is fetched, it comes in as a JSON object. One of the keys within this object pertains to the main text block for the entry I am retrieving. This stri ...

Searching for the class _XWk using BeautifulSoup: A beginner's guide

I have discovered a way to locate Google's "quick answer box" by searching for the "_XWk HTML Element using the code below: from bs4 import BeautifulSoup # Beautiful Soup is part of the bs4 package import requests URL = 'https://www.google.com/ ...

CSS techniques for positioning a header image

I'm having an issue with using a banner I created in CS6 Illustrator as a header on my website. Despite setting it as the background, positioned at the top and set to "no-repeat", it keeps appearing at the bottom of the header area with around 300px o ...

Issue with applying CSS properties of 'top' and 'left' to a dynamically created div using

After an extensive search on both the site and the internet, I have not had any luck so far. I am dealing with a series of dynamically-generated divs using JQuery, cloned from the original HTML source. While I can manipulate the positioning properties of ...

Using CSS :hover for elements with dual classes only

Is there a way to make the CSS :hover selector work only when two different classes are attached to a div? I have tried a couple of methods, but they eliminate the hover effect. For example: .accordionButton .cyan:hover{ color: cyan; } I cannot s ...

Looking to show an image when a checkbox is ticked and hide it when it is unticked in HTML?

How do I make a specific image appear when a user clicks on a checkbox? I'm unsure if I should use jQuery, Ajax, or another method. What is the best approach for this task? Your assistance would be greatly appreciated. I have successfully created the ...

What is the best way to align text at the center of a circular animation?

I stumbled upon this fascinating animation and I'm looking to incorporate it into my project. However, I'm facing a challenge in centering text inside the circle without resorting to using position absolute. My goal is to have the text with the ...

Need a guide to identify HTML elements with a particular attribute?

I attempted to find this information online, but I wasn't successful. Suppose I am interested in knowing all the HTML elements that contain a "background" attribute. I'm aware that some web browsers may not support certain elements. Off the top ...

Tips for retrieving data from a database with just one key press

There is a text field that triggers a JavaScript function when a key is pressed. <input type="text" class="text" id="txt_sh_vid" onKeyPress="vhc_record()" maxlength="4"> The function takes the input from the text field and searches for a result in t ...