background-color

Class Description

bg

Sets the background color via --bg.

CSS Rules

.bg {
  background-color: var(--bg);
}

Usage

The .bg class is flagged as a value-driven selector. The variable --bg is required.
<element class="bg" style="--bg: /* value */;" />

Responsive & Dark Mode

Prefix .bg utility with a breakpoint variant (e.g., md:) to apply styles at specific screen sizes (Supported breakpoints are xm through 2xl). If dark mode is applied, the dark: prefix always comes first.

<element class="md:bg" style="--md-bg: /* value */;" />

<element class="dark:sm:bg" style="--dark-sm-bg: /* value */;" />

States

States are generated dynamically at runtime and always come last. Append a state like :hover or :focus to the end of the class. This works in conjunction with breakpoints and dark mode.

Supported pseudo-classes: :hover, :active, :focus, :focus-visible, :focus-within, :target, :checked, :disabled, and :group-hover.

<element class="bg:hover" style="--bg-hover: /* value */;" />

<element class="dark:sm:bg:hover" style="--dark-sm-bg-hover: /* value */;" />

Group Hover Example

The :group-hover state applies styles when a parent element with the .group class is hovered.

<element class="group">
  <element class="bg:group-hover">...</element>
</element>

Pseudo-Elements

The ::before and ::after utility classes are supported too. Granted that you add the mandatory content-before or content-after class in order for them to work.

<element class="content-before bg::before" style="--bg-before: /* value */;" />

<element class="content-after bg::after" style="--bg-after: /* value */;" />

Shorthand

Value-driven classes support a shorthand syntax like bg=pink or p=4. The runtime processes this for you. Unlike :hover that is generating CSS on the fly, shorthand only splits it and appends the corresponding style.

<!-- Input -->
<element class="bg=value" />

<!-- Output -->
<element class="bg" style="--bg: value;" />

CLS Alert

This feature may cause CLS (Cumulative Layout Shift). Make sure to include a z-not-ready class in your <head> tag.

.bg Sets the background color via --bg.

bg/o

Sets background color + opacity via --bg and --bg-o independently.

CSS Rules

.bg\/o {
  background-color: color-mix(in oklab, var(--bg) var(--bg-o, 100%), transparent);
}

Usage

The .bg/o class is flagged as a value-driven selector. The variables --bg and --bg-o are required.
<element
  class="bg/o"
  style="
    --bg: /* value */;
    --bg-o: /* value */;
  "
></element>

Responsive & Dark Mode

Prefix .bg/o utility with a breakpoint variant (e.g., md:) to apply styles at specific screen sizes (Supported breakpoints are xm through 2xl). If dark mode is applied, the dark: prefix always comes first.

<element
  class="md:bg/o"
  style="
    --md-bg: /* value */;
    --md-bg-o: /* value */;
  "
></element>

<element
  class="dark:sm:bg/o"
  style="
    --dark-sm-bg: /* value */;
    --dark-sm-bg-o: /* value */;
  "
></element>

States

States are generated dynamically at runtime and always come last. Append a state like :hover or :focus to the end of the class. This works in conjunction with breakpoints and dark mode.

Supported pseudo-classes: :hover, :active, :focus, :focus-visible, :focus-within, :target, :checked, :disabled, and :group-hover.

<element
  class="bg/o:hover"
  style="
    --bg-hover: /* value */;
    --bg-o-hover: /* value */;
  "
></element>

<element
  class="dark:sm:bg/o:hover"
  style="
    --dark-sm-bg-hover: /* value */;
    --dark-sm-bg-o-hover: /* value */;
  "
></element>

Group Hover Example

The :group-hover state applies styles when a parent element with the .group class is hovered.

<element class="group">
  <element class="bg/o:group-hover">...</element>
</element>

Pseudo-Elements

The ::before and ::after utility classes are supported too. Granted that you add the mandatory content-before or content-after class in order for them to work.

<element
  class="content-before bg/o::before"
  style="
    --bg-before: /* value */;
    --bg-o-before: /* value */;
  "
></element>

<element
  class="content-after bg/o::after"
  style="
    --bg-after: /* value */;
    --bg-o-after: /* value */;
  "
></element>

Shorthand

Value-driven classes support a shorthand syntax like bg=pink or p=4. The runtime processes this for you. Unlike :hover that is generating CSS on the fly, shorthand only splits it and appends the corresponding style.

<!-- Input -->
<element class="bg/o=value" />

<!-- Output -->
<element class="bg/o" style="--bg: value;" />

CLS Alert

This feature may cause CLS (Cumulative Layout Shift). Make sure to include a z-not-ready class in your <head> tag.

.bg/o Sets background color + opacity via --bg and --bg-o independently.