---
title: "Render CSS accent-color on HTML form controls in C#"
url: https://recursiveai.org/onerender/cookbook/render-html-control-accent-color/
description: "Render HTML form controls with CSS accent-color in C#. Save a PNG with a custom checkbox and radio color, and see which control states use the accent."
version: "1.4.0"
---

# Render CSS accent-color on HTML form controls in C#

**OneRender** is a free, open-source HTML and CSS rendering library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneRender.Image) · [GitHub](https://github.com/recursive-ai-oss/onerender-csharp) · [Docs](https://recursiveai.org/onerender/docs/) · [Download example (.zip)](https://recursiveai.org/onerender/cookbook/render-html-control-accent-color/render-html-control-accent-color.zip)

CSS `accent-color` changes the highlight on controls such as checked boxes and radio buttons. Render the form to a still PNG; JavaScript doesn’t run.

```shell
dotnet add package RecursiveAI.OneRender.Image
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneRender.Image;

string html = """
<style>form{accent-color:#7038b0}</style>
<form>
  <label>
    <input type="checkbox" checked> Email
  </label>
  <label>
    <input type="radio" checked> Weekly
  </label>
</form>
""";
var image = HtmlRender.ToImage(html,
    new HtmlRenderOptions { Width = 200,
        Height = 40 });
File.WriteAllBytes("form.png", image.ToPng());
Console.WriteLine(
    $"form.png: {image.Width}x{image.Height}");
```

Unzip [the example](https://recursiveai.org/onerender/cookbook/render-html-control-accent-color/render-html-control-accent-color.zip), then `dotnet run`.

```text
form.png: 200x40
```

![A purple checked checkbox labeled Email and a purple selected radio button labeled Weekly](https://recursiveai.org/onerender/images/render-html-control-accent-color/form.png)

If a checkbox stays neutral, check that it’s checked and not disabled.

## Variations

**Override the radio color.** Add this rule after the form rule to keep the checkbox purple while making the radio green:

```css
input[type="radio"] { accent-color: #087850; }
```

![The Email checkbox stays purple and the Weekly radio button turns green](https://recursiveai.org/onerender/images/render-html-control-accent-color/form-green-radio.png)

## Related recipes

- [Convert HTML to PNG in C#](https://recursiveai.org/onerender/cookbook/html-to-png/)
- [Render dark-mode HTML controls in C#](https://recursiveai.org/onerender/cookbook/form-controls-dark-mode/)
- [Edit text in a rendered HTML form](https://recursiveai.org/onerender/cookbook/edit-text-in-rendered-form/)

## The short answer

Set `accent-color` on the form to give its controls a common color, or on an individual control to set its color separately. Include the state you want in the HTML, such as the `checked` attribute, then render with `HtmlRender.ToImage` and save with `ToPng()`. The PNG shows that state; clicking the image won’t change it.

## How do I change a checkbox or radio button color with CSS?

Use `accent-color` if you want to tint the built-in control without replacing its shape. The property is [inherited](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/accent-color#formal_definition), so the one declaration on the form colors both the checkbox and radio in the example. The variation overrides only the radio. Neither rule changes the text color of the labels.

The two checked controls use the color differently. The checkbox uses it for the filled box and picks a light or dark color for the checkmark based on contrast. The radio uses it for the outer ring and the dot and leaves a gap in between. These details are in the [OneRender forms docs](https://recursiveai.org/onerender/docs/forms/#themed-controls-color-scheme-accent-color).

## Why isn’t CSS accent-color showing on my form control?

Start with a checked, enabled checkbox so the area that takes the accent is visible. An unchecked checkbox has no checked fill to tint, and the OneRender forms docs say “Disabled controls ignore `accent-color`.” If the real form is populated by JavaScript, put the desired state directly in the source HTML you render. The static image call won’t run the script that normally sets it.

Also check the element type. In addition to checkboxes and radios, the forms docs describe accent fill and track contrast for range inputs and `<progress>`. `<meter>` ignores `accent-color`, so don’t substitute it for `<progress>` if you want the same styling. `accent-color` is not a page theme: it doesn’t choose the canvas color or turn on dark mode.
