background-size

Class Description

bg-size

Sets background-size via --bg-size. E.g. 50%, 200px.

CSS Rules

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

Usage

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

Responsive

Prefix .bg-size utility with a breakpoint variant (e.g., md:) to apply styles at specific screen sizes (Supported breakpoints are xm through 2xl).

<element class="md:bg-size" style="--md-bg-size: /* 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 .

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

<element class="bg-size:hover" style="--bg-size-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-size: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-size::before" style="--bg-size-before: /* value */;" />

<element class="content-after bg-size::after" style="--bg-size-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-size=value" />

<!-- Output -->
<element class="bg-size" style="--bg-size: 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-size Sets background-size via --bg-size. E.g. 50%, 200px.

bg-auto

Displays the background image at its original size.

CSS Rules

.bg-auto {
  background-size: auto;
}

Usage

<element class="bg-auto" />

Responsive

Prefix .bg-auto utility with a breakpoint variant (e.g., md:) to apply styles at specific screen sizes (Supported breakpoints are xm through 2xl).

<element class="md:bg-auto" />

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 .

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

<element class="bg-auto:hover" />

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-auto: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-auto::before" />

<element class="content-after bg-auto::after" />
.bg-auto Displays the background image at its original size.

bg-cover

Sets background-size: cover. Image fills the entire container.

CSS Rules

.bg-cover {
  background-size: cover;
}

Usage

<element class="bg-cover" />

Responsive

Prefix .bg-cover utility with a breakpoint variant (e.g., md:) to apply styles at specific screen sizes (Supported breakpoints are xm through 2xl).

<element class="md:bg-cover" />

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 .

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

<element class="bg-cover:hover" />

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-cover: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-cover::before" />

<element class="content-after bg-cover::after" />
.bg-cover Sets background-size: cover. Image fills the entire container.

bg-contain

Sets background-size: contain. Image fits within the container.

CSS Rules

.bg-contain {
  background-size: contain;
}

Usage

<element class="bg-contain" />

Responsive

Prefix .bg-contain utility with a breakpoint variant (e.g., md:) to apply styles at specific screen sizes (Supported breakpoints are xm through 2xl).

<element class="md:bg-contain" />

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 .

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

<element class="bg-contain:hover" />

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-contain: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-contain::before" />

<element class="content-after bg-contain::after" />
.bg-contain Sets background-size: contain. Image fits within the container.