The minimal preset for UnoCSS, providing essential utilities for atomic CSS generation with modular theme, rules, and variants.
—
Comprehensive variant system supporting responsive breakpoints, pseudo-classes, dark mode, arbitrary selectors, and advanced CSS targeting for conditional utility application.
Creates the complete collection of variant handlers for the preset.
/**
* Creates variants collection with configuration-based customization
* @param options - Preset configuration options affecting variant behavior
* @returns Array of variant handlers for the preset
*/
function variants(options: PresetMiniOptions): Variant[];Usage Example:
import { variants } from "@unocss/preset-mini/variants";
import type { PresetMiniOptions } from "@unocss/preset-mini";
const options: PresetMiniOptions = {
dark: 'class',
attributifyPseudo: false,
};
const variantHandlers = variants(options);Responsive design variants using mobile-first approach with theme-defined breakpoints.
Breakpoint Variants:
sm: - @media (min-width: 640px)md: - @media (min-width: 768px)lg: - @media (min-width: 1024px)xl: - @media (min-width: 1280px)2xl: - @media (min-width: 1536px)Custom range variants:
<sm: - @media (max-width: 639px)<md: - @media (max-width: 767px)@md: - @media (min-width: 768px) and (max-width: 1023px)Vertical breakpoint variants (height-based):
verticalBreakpoints are defined in themeUsage Examples:
<!-- Responsive width -->
<div class="w-full md:w-1/2 lg:w-1/3">
Responsive width
</div>
<!-- Responsive text size -->
<h1 class="text-xl md:text-2xl lg:text-3xl">
Responsive heading
</h1>Dark mode support with configurable detection method.
Dark Mode Variants:
dark: - Applied in dark mode contextlight: - Applied in light mode context (when using custom selectors)Configuration-dependent behavior:
// Class-based (default)
dark: 'class' // Uses .dark ancestor selector
// Media query-based
dark: 'media' // Uses @media (prefers-color-scheme: dark)
// Custom selectors
dark: {
dark: '.dark-theme',
light: '.light-theme'
}Usage Examples:
<!-- Class-based dark mode -->
<div class="bg-white dark:bg-gray-900 text-black dark:text-white">
Content with dark mode
</div>
<!-- Works with any utility -->
<button class="border border-gray-300 dark:border-gray-700 hover:bg-gray-100 dark:hover:bg-gray-800">
Button with dark mode
</button>Comprehensive pseudo-class support for interactive states and element targeting.
Interactive States:
hover: - :hoverfocus: - :focusactive: - :activevisited: - :visitedfocus-within: - :focus-withinfocus-visible: - :focus-visibleForm States:
checked: - :checkeddisabled: - :disabledenabled: - :enabledrequired: - :requiredinvalid: - :invalidvalid: - :validin-range: - :in-rangeout-of-range: - :out-of-rangeStructural Pseudo-classes:
first: - :first-childlast: - :last-childodd: - :nth-child(odd)even: - :nth-child(even)first-of-type: - :first-of-typelast-of-type: - :last-of-typeonly: - :only-childonly-of-type: - :only-of-typeUsage Examples:
<!-- Interactive states -->
<button class="bg-blue-500 hover:bg-blue-600 focus:ring-2 focus:ring-blue-300 active:bg-blue-700">
Interactive button
</button>
<!-- Form validation states -->
<input class="border border-gray-300 valid:border-green-500 invalid:border-red-500" />
<!-- Structural targeting -->
<ul>
<li class="first:font-bold odd:bg-gray-100">Item 1</li>
<li class="odd:bg-gray-100">Item 2</li>
<li class="last:border-b-0 odd:bg-gray-100">Item 3</li>
</ul>Pseudo-element variants for content generation and styling.
Available Pseudo-elements:
before: - ::beforeafter: - ::afterfirst-line: - ::first-linefirst-letter: - ::first-letterbackdrop: - ::backdropplaceholder: - ::placeholderfile: - ::file-selector-buttonmarker: - ::markerselection: - ::selectionUsage Examples:
<!-- Decorative elements -->
<div class="before:content-[''] before:absolute before:inset-0 before:bg-gradient-to-r before:from-blue-500 before:to-purple-500">
Content with gradient overlay
</div>
<!-- Form styling -->
<input class="placeholder:text-gray-400 placeholder:italic" placeholder="Enter text..." />Support for ARIA states and custom data attributes.
ARIA Variants:
aria-checked: - [aria-checked="true"]aria-disabled: - [aria-disabled="true"]aria-expanded: - [aria-expanded="true"]aria-hidden: - [aria-hidden="true"]aria-pressed: - [aria-pressed="true"]aria-readonly: - [aria-readonly="true"]aria-required: - [aria-required="true"]aria-selected: - [aria-selected="true"]Data Attribute Variants:
data-*: - Custom data attribute matchingdata configurationUsage Examples:
<!-- ARIA-based styling -->
<button class="aria-expanded:bg-blue-100 aria-pressed:bg-blue-200" aria-expanded="false">
Expandable button
</button>
<!-- Data attribute styling -->
<div class="data-[state=open]:bg-green-100" data-state="closed">
State-dependent styling
</div>Advanced selector combinators for targeting related elements.
Child Combinators:
*: - > * (direct children)first-child: - > :first-childlast-child: - > :last-childGroup Variants:
group-hover: - Applied when ancestor with group class is hoveredgroup-focus: - Applied when ancestor with group class is focusedgroup-active: - Applied when ancestor with group class is activeUsage Examples:
<!-- Group interaction -->
<div class="group">
<img class="group-hover:scale-110 transition-transform" />
<p class="group-hover:text-blue-600">Hover the parent to transform both</p>
</div>
<!-- Child targeting -->
<nav class="*:px-4 *:py-2 *:rounded">
<a href="#">All children get padding and rounded corners</a>
<a href="#">Automatically applied</a>
</nav>Modern container query support for component-based responsive design.
Container Variants:
@container: - Container query support@xs:, @sm:, @md:, @lg:, @xl: - Container-based breakpointsUsage Example:
<div class="@container">
<div class="@md:flex @md:space-x-4">
Content that responds to container size
</div>
</div>Custom media query variants for advanced responsive design.
Print Variants:
print: - @media printMotion Preferences:
motion-safe: - @media (prefers-reduced-motion: no-preference)motion-reduce: - @media (prefers-reduced-motion: reduce)Custom Media Queries:
media configurationFeature query variants for progressive enhancement.
Supports Variants:
supports-[property:value]: - @supports (property: value)supports configurationUsage Example:
<div class="grid supports-[display:subgrid]:subgrid">
Falls back to grid, uses subgrid if supported
</div>Powerful arbitrary variant syntax for custom selectors when arbitraryVariants is enabled.
Arbitrary Syntax:
[selector]: - Custom CSS selector[&>*]: - Target direct children[&[attr]]: - Target elements with attributes[.parent_&]: - Custom parent selectorUsage Examples:
<!-- Target all children -->
<div class="[&>*]:margin-4">
All direct children get margin
</div>
<!-- Complex selectors -->
<details class="[&[open]>summary]:text-blue-600">
<summary>Click to expand</summary>
<p>Content</p>
</details>
<!-- Parent-based styling -->
<div class="[.sidebar_&]:hidden">
Hidden when inside .sidebar
</div>Force important on any utility with the ! prefix.
Important Variants:
! - Adds !important to CSS declarationsUsage Example:
<div class="!text-red-500">
This text color cannot be overridden
</div>Automatic negative value support for applicable utilities.
Negative Variants:
- prefix for negative valuesUsage Example:
<div class="-mt-4 -translate-x-2">
Negative margin and transform
</div>Variants can be combined and stacked for complex conditional styling:
<!-- Multiple variants -->
<button class="md:hover:focus:bg-blue-600 dark:md:hover:bg-gray-700">
Complex conditional styling
</button>
<!-- Arbitrary with standard variants -->
<div class="hover:[&>*]:scale-110 focus-within:[&>*]:opacity-75">
Combined arbitrary and standard variants
</div>Variants respect preset configuration options:
dark option affects dark mode variant behaviorattributifyPseudo changes group/peer selector generationarbitraryVariants enables/disables arbitrary variant syntaxInstall with Tessl CLI
npx tessl i tessl/npm-unocss--preset-mini