# A color field as a CSS variable

> A color picked in the admin becomes a CSS variable on the page.

Source: https://uglydev.com/recipes/a-colour-field-as-a-css-variable/
Updated: 19 November 2026

```php
<?php
$accent = ugly_get( 'accent' );

if ( preg_match( '/^#[0-9a-fA-F]{6}$/', (string) $accent ) ) {
	echo '<style>:root { --accent: ' . esc_html( $accent ) . '; }</style>';
}
```

Check it before you put it in a `<style>` tag. The field cleans it when saving, but a style tag is a place to be careful.
