Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind
  • CSS Formatter
Open In App
Next Article:
How to Change Selected Text Background Color in CSS?
Next article icon

How to Change the Checkbox Background Color in CSS?

Last Updated : 28 Jun, 2024
Comments
Improve
Suggest changes
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 Content

  • Using Pseudo-elements
  • Using CSS appearance Property

Using Pseudo-elements

In 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:

Screencastfrom2024-06-1109-23-09-ezgifcom-video-to-gif-converter
output

Using CSS appearance Property

In 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:

Screencastfrom2024-06-1109-27-18-ezgifcom-video-to-gif-converter
Output

Next Article
How to Change Selected Text Background Color in CSS?
author
isandeep2183
Improve
Article Tags :
  • CSS
  • Web Technologies

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 Int
    2 min read
  • How to change Background Color in HTML ?
    The background color in HTML refers to the color displayed behind the content of a webpage. To change it, CSS (Cascading Style Sheets) is used, with various approaches available. In CSS, we define the background-color property within a CSS rule, specifying a color value such as a name, hexadecimal c
    3 min read
  • How to Change Background Color in WordPress?
    Changing the background color in WordPress can be achieved through various methods. It simply means modifying the website appearance by setting a different color for the site background. This can be done in various methods in this article we explain how to change the background color in WordPress wi
    2 min read
  • How to Change the Color of Button on Click ?
    Sometimes, on a web page, when a user clicks a button, it gets difficult to understand whether the button was clicked or not. In such cases, you can change the background color of the button to indicate that the button is clicked. Changing the color of a button when it's clicked can make your websit
    4 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
  • How to change the “checked” background color of toggle switch in Bootstrap 4?
    Bootstrap is a popular choice among web developers for building interactive webpage designs. Bootstrap has come along a long way with multiple releases and enriched content with every new release. Bootstrap has a wide community that has also contributed newer packages that have made working with Boo
    4 min read
  • How to change the background color of the active nav-item?
    In this article, we will learn how we can change the background of the active nav item with the help of CSS and jQuery. Given an HTML document containing a list of items, the task is to change the background color of a particular list item when it is active or clicked. We can change the background c
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences