xiaohongshu
xiaohongshu
creating-custom-utilities
Create custom utilities with @utility directive supporting static utilities, functional utilities with values, theme-based utilities, and multi-value utilities. Use when extending Tailwind with custom CSS properties or patterns.
Full skill instructions
The @utility directive creates custom utility classes with full variant support (hover, focus, responsive, etc.). This is the proper way to extend Tailwind v4 with custom utilities.
Define utilities with fixed values:
@utility content-auto {
content-visibility: auto;
}
@utility content-hidden {
content-visibility: hidden;
}
@utility text-balance {
text-wrap: balance;
}
@utility text-pretty {
text-wrap: pretty;
}
@utility bg-glass {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
}
Usage:
<div class="content-auto hover:content-hidden"></div>
<p class="text-balance lg:text-pretty"></p>
<div class="bg-glass"></div>
Static utilities work with all variants automatically.
Create utilities that accept numeric values:
@utility mt-* {
margin-top: calc(0.25rem * --value(integer));
}
@utility truncate-* {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: --value(integer);
overflow: hidden;
}
@utility text-stroke-* {
-webkit-text-stroke-width: --value(integer) px;
}
Usage:
<div class="mt-5"></div>
<p class="truncate-3"></p>
<h1 class="text-stroke-2"></h1>
The --value(integer) function extracts the numeric value from the class name.
Reference theme variables using --value(--namespace- *):
@theme {
--tab-size-2: 2;
--tab-size-4: 4;
--tab-size-8: 8;
--tab-size-github: 8;
}
@utility tab-* {
tab-size: --value(--tab-size- *);
}
Usage:
<pre class="tab-2"><code>...</code></pre>
<pre class="tab-github"><code>...</code></pre>
Another example:
@theme {
--aspect-square: 1 / 1;
--aspect-video: 16 / 9;
--aspect-portrait: 3 / 4;
}
@utility aspect-* {
aspect-ratio: --value(--aspect- *);
}
Usage:
<img class="aspect-square" />
<video class="aspect-video" />
<div class="aspect-portrait"></div>
Create utilities that accept multiple value types:
@utility text-stroke-* {
-webkit-text-stroke-width: --value(integer) px;
-webkit-text-stroke-color: --value(--color- *);
}
Usage:
<h1 class="text-stroke-2-blue-500">Stroked text</h1>
<h1 class="text-stroke-1-primary">Stroked with theme color</h1>
Another example:
@theme {
--blur-sm: 4px;
--blur-md: 8px;
--blur-lg: 16px;
}
@utility backdrop-blur-* {
backdrop-filter: blur(--value(--blur- *));
backdrop-filter: blur(--value(integer) px);
}
Usage:
<div class="backdrop-blur-sm"></div>
<div class="backdrop-blur-12"></div>
Support both theme values and arbitrary values:
@utility tab-* {
tab-size: --value(integer);
tab-size: --value([integer]);
}
Usage:
<pre class="tab-4">Theme value</pre>
<pre class="tab-[12]">Arbitrary value</pre>
The --value([integer]) function enables arbitrary value syntax with square brackets.
@utility text-gradient-* {
background: linear-gradient(to right, --value(--color- *), --value(--color- *, 2));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
Usage:
<h1 class="text-gradient-blue-500-purple-600">Gradient text</h1>
@utility grid-cols-* {
grid-template-columns: repeat(--value(integer), minmax(0, 1fr));
}
Usage:
<div class="grid grid-cols-3"></div>
<div class="grid grid-cols-5"></div>
@utility line-clamp-* {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: --value(integer);
overflow: hidden;
}
@utility line-clamp-none {
display: block;
-webkit-box-orient: horizontal;
-webkit-line-clamp: none;
overflow: visible;
}
Usage:
<p class="line-clamp-2 lg:line-clamp-3 xl:line-clamp-none"></p>
@theme {
--spacing-base: 0.25rem;
}
@utility gap-* {
gap: calc(var(--spacing-base) * --value(integer));
}
@utility space-x-* > * + * {
margin-left: calc(var(--spacing-base) * --value(integer));
}
Usage:
<div class="flex gap-6"></div>
<div class="flex space-x-4"></div>
@utility glass-* {
background: rgba(255, 255, 255, --value(integer) / 100);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
}
@utility glass-dark-* {
background: rgba(0, 0, 0, --value(integer) / 100);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.1);
}
Usage:
<div class="glass-10"></div>
<div class="glass-dark-20"></div>
@utility before-content-* {
&::before {
content: --value([string]);
display: block;
}
}
@utility after-content-* {
&::after {
content: --value([string]);
display: block;
}
}
Usage:
<div class="before:content-['★']">Star before</div>
<div class="after:content-['→']">Arrow after</div>
@import 'tailwindcss';
@utility content-auto {
content-visibility: auto;
}
@utility content-hidden {
content-visibility: hidden;
}
@utility text-balance {
text-wrap: balance;
}
@utility text-pretty {
text-wrap: pretty;
}
@utility truncate-* {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: --value(integer);
overflow: hidden;
}
@utility bg-glass {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
}
@utility text-stroke-* {
-webkit-text-stroke-width: --value(integer) px;
-webkit-text-stroke-color: --value(--color- *);
}
@theme {
--aspect-square: 1 / 1;
--aspect-video: 16 / 9;
--aspect-portrait: 3 / 4;
--aspect-ultrawide: 21 / 9;
}
@utility aspect-* {
aspect-ratio: --value(--aspect- *);
aspect-ratio: --value([number]);
}
@theme {
--tab-size-2: 2;
--tab-size-4: 4;
--tab-size-8: 8;
}
@utility tab-* {
tab-size: --value(--tab-size- *);
tab-size: --value(integer);
tab-size: --value([integer]);
}
Don't do this:
@layer utilities {
.my-button {
padding: 1rem;
}
}
Won't work with variants like hover:my-button.
Do this:
@utility my-button {
padding: 1rem;
}
Works with all variants: hover:my-button, focus:my-button, lg:my-button.
@utility instead of @layer utilities--value([type]) for flexibility--value(--namespace- *)xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience