How to change the color or the accent color of the interactive HTML elements on a webpage using CSS?
Tags: css
Published: 2022-12-12 05:24:34

---
  title: How to change the color or the accent color of the interactive HTML elements on a webpage using CSS?
  published: true
  tags: CSS
  date: Mon Dec 12 2022 10:54:34 GMT+0530 (India Standard Time)
  canonical_url: https://melvingeorge.me/blog/change-color-or-accent-color-of-interactive-html-elements-on-webpage-using-css
  cover_image: https://res.cloudinary.com/df8e3k5he/image/upload/blog/main_c9720c9333.jpg
  ---
  [Originally posted here!](https://melvingeorge.me/blog/change-color-or-accent-color-of-interactive-html-elements-on-webpage-using-css)
  To change the color or the accent color of the interactive HTML elements on a webpage using CSS, you can use the `accent-color` CSS property on the `html` selector in the CSS styles and set its value to the color of your choice.

### TL;DR

```html
<!-- A simple webpage with a radio `input` and a checkbox `input` HTML element -->
<html>
  <style>
    html {
      /* setting all the HTML elements accent color to `red` */
      accent-color: red;
    }
  </style>
  <body>
    <input type="radio" />
    <input type="checkbox" />
  </body>
</html>
```

For example, let's say we have a radio `input` and a checkbox `input` HTML element on the webpage like this,

```html
<!-- A simple webpage with a radio `input` and a checkbox `input` HTML element -->
<html>
  <body>
    <input type="radio" />
    <input type="checkbox" />
  </body>
</html>
```

The webpage now looks like this,

![webpage with a simple radio input and checkbox input HTML element](/uploads/Screenshot_2022_12_01_at_1_16_01_AM_22a15cdbc1.png)

If you see the above screenshot, the radio and the checkbox HTML elements have the default color or the accent color (blue color in the case of Safari browser) applied to them.

We aim to change the color or the accent color of both the interactive HTML elements to `red` color.

To do that first, let's select the `html` selector in the CSS styles like this,

```html
<!-- A simple webpage with a radio `input` and a checkbox `input` HTML element -->
<html>
  <style>
    html {
      /* CSS style here */
    }
  </style>
  <body>
    <input type="radio" />
    <input type="checkbox" />
  </body>
</html>
```

Now let's apply the accent color to all the HTML elements by using the `accent-color` CSS property inside the `html` selector and setting the value as `red`.

It can be done like this,

```html
<!-- A simple webpage with a radio `input` and a checkbox `input` HTML element -->
<html>
  <style>
    html {
      /* setting all the HTML elements accent color to `red` */
      accent-color: red;
    }
  </style>
  <body>
    <input type="radio" />
    <input type="checkbox" />
  </body>
</html>
```

Now both the input HTML element's accent colors are changed to `red` color.

A visual representation of the webpage HTML elements is shown below,

![webpage with a simple radio input and checkbox input HTML element having accent color set to red](/uploads/01_d13e6e39ca.gif)

We have successfully changed the accent color of the interactive HTML element using CSS. Yay 🥳!

See the above code live in [codesandbox](https://codesandbox.io/s/change-color-or-accent-color-of-interactive-html-elements-on-webpage-using-css-lyeu6q?file=/index.html).

That's all 😃.