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.
dotnet add package RecursiveAI.OneRender.ImageRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
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, then dotnet run.
form.png: 200x40
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:
input[type="radio"] { accent-color: #087850; }
Related recipes
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, 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.
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.