How to Change the Checkbox Background Color in CSS? Last Updated : 28 Jun, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Change the checkbox background color in CSS by hiding the default checkbox and using custom styles with the ::before and ::after pseudo-elements. This involves creating a custom checkbox that looks and works just like a regular checkbox but with your own design.Below are the approaches to change the Checkbox Background Color in CSS:Table of ContentUsing Pseudo-elementsUsing CSS appearance PropertyUsing Pseudo-elementsIn this approach, we are creating a webpage with a custom-styled checkbox and an image. The CSS hides the checkbox and styles its label to show a custom box. When the checkbox is checked, the box turns red with a white square inside. An image and label with "Check me" text are displayed on a green background.Example: This example shows the change of background color of a checkbox using pseudo element. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Custom Checkbox</title> <style> img { display: flex; width: 200px; margin-bottom: 20px; height: 200px; } body { background: green; } input[type="checkbox"] { display: none; } input[type="checkbox"]+label { position: relative; padding-left: 25px; cursor: pointer; user-select: none; } input[type="checkbox"]+label::before { content: ""; position: absolute; left: 0; top: 0; width: 18px; height: 18px; border: 2px solid #555; background: white; } input[type="checkbox"]:checked+label::before { background: red; } input[type="checkbox"]:checked+label::after { content: ""; position: absolute; left: 5px; top: 5px; width: 8px; height: 8px; background: white; } </style> </head> <body> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20210511160813/g4g.jpg"> <input type="checkbox" id="checkbox" /> <label for="checkbox">Check me</label> </body> </html> Output:output Using CSS appearance PropertyIn this approach, we are creating a webpage with a custom-styled checkbox and an image. The CSS hides the default checkbox appearance and styles it to be a 20x20px white box with a gray border. When checked, the box's background turns blue. The page displays an image and uses a green background for the body. CSS appearance property is used to change the background of the checkbox.Example: This example shows the change of background of a checkbox using the appearance property. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Custom Checkbox Appearance</title> <style> img { display: flex; width: 200px; margin-bottom: 20px; height: 200px; } body { background: green; } input[type="checkbox"] { -webkit-appearance: none; -moz-appearance: none; appearance: none; width: 20px; height: 20px; border: 2px solid #555; background: white; } input[type="checkbox"]:checked { background: blue; } </style> </head> <body> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20210511160813/g4g.jpg"> <input type="checkbox" /> </body> </html> Output:Output Comment More infoAdvertise with us Next Article How to Change Background Color in HTML without CSS ? I isandeep2183 Follow Improve Article Tags : Web Technologies CSS Similar Reads How to Change Selected Text Background Color in CSS? Sometimes, we need to change the color and background color of the selected text. The ::selection pseudo-element is used to change the background color of the selected text in CSS. This pseudo-element allows you to style the portion of text that has been selected by the user. Using ::selection Pseud 2 min read How to Change Background Color in HTML without CSS ? In HTML, you can change the background color of an element using the bgcolor attribute. However, it's important to note that the bgcolor attribute is deprecated in HTML5 and should be avoided in favor of using CSS for styling. This article will cover various methods to change the background color of 2 min read How to Change the Background Color of Table using CSS? Changing the background color of a table using CSS can help improve the visual appearance of a website or web application. we will learn how to change the background color of the table using CSS with different approaches.These are the following approaches:Table of Content Using Inline CSSUsing Inter 2 min read How to change Background Color in HTML ? The background color in HTML sets the visual backdrop behind your webpage content. Around 85% of beginner developers start by customizing background colors to enhance design and readability. Using CSS (Cascading Style Sheets), you can easily apply colors through the background-color property. This c 3 min read How to Change the Checked Mark Color of a Checkbox using CSS? Checkboxes are commonly used on websites to enable users to make selections, such as agreeing to terms and conditions or choosing preferences. A checkbox is a small square box in forms that users can click to select or deselect an option. By default, the checkmark inside the checkbox has a basic sty 5 min read How to Change the Border Color on Hover in CSS ? Border color in CSS defines the color of an elementâs border. You can change the border color on hover using the :hover pseudo-class, allowing you to modify the borderâs appearance when a user hovers over the element. Using CSS hover Pseudo ClassThe hover pseudo-class in CSS is a powerful tool that 1 min read Like