INTRODUCTION
IntroductionCore ConceptsGETTING STARTED
InstallationQuick startWhirl Compiler SettingsCORE CONCEPTS
Using Utility ClassesStyle FunctionsPseudo-Classes and statesResponsive DesignResponsive Base ElementThemeArbitrary ValuesLAYOUT
aspect-ratiodisplayoverflowpositionvisibilityobject-fittop / right / bottom / leftFLEXBOX
flex-basisflex-directionflex-wrapflexflex-growflex-shrinkgapjustify-contentalign-contentalign-itemsalign-selfSPACING
paddingmarginSIZING
widthmin-widthmax-widthheightmin-heightmax-heightTYPOGRAPHY
font-sizefont-styleauto-sizetext-outlineletter-spacingtext-aligncolorword-spacingparagraph-spacingtext-overflowoverflow-positionwhite-spaceBACKGROUND
background-colorbackground-imagebackground-positionbackground-repeatbackground-sizeBORDER
border-radiusborder-widthborder-colorEFFECTS
text-shadowopacityFILTER
Filterblurbrightnesscontrastgrayscalehue-rotateinvertsaturatesepiaTRANSITION
transition-propertytransition-durationtransition-timing-functiondelayTRANSFORM
rotatescaletransform-origintranslateUsing Utility Classes
Instead of writing long custom USS files, you use short utility classes directly inside your UXML. Whirl scans your UXML, C# scripts, and scriptable utility files and generates only the utilities you actually use.
Adding Utilities in UXML
Just place utility classes inside the class attribute:
<Label class="text-16 font-bold padding-4 bg-gray-200" />Whirl automatically detects these classes during compilation and injects the correct USS rules into your generated USS file.
However, there's an important detail to keep in mind, because Unity doesn’t support some CSS characters, Whirl uses a safe naming system:
| Symbol | Alternative |
|---|---|
| : | --- |
| [ | _b_ |
| ] | _B_ |
| / | _s_ |
| ( | _p_ |
| ) | _P_ |
| , | _c_ |
| * | _st_ |
| > | _gt_ |
| & | _and_ |
Example in UXML:
<Button class="p-4 hover---bg-blue-500 lg---bg-violet-500"/>This is only necessary when writing utility classes directly in UXML/through the UI Builder. When using utilities inside C# scripts or ScriptableObjects, you can use the normal naming convention with special characters.
You should add a class to a VisualElement through C# script by calling the .AddClass(...) extension method, it would handle the conversion for you automatically.
Example in C#
using UnityEngine.UIElements;
using Kostom.styles;
...
element.AddClass("text-16", "hover:text-20", "lg:hover:text-[40px]")As long as your WCS has its script search paths set, these utilities will be included in the final stylesheet.
Style Functions
To use the functions, you need to add them to the WhirlCompilerSettings.
StyleUtility (replaces @utility)
Inside the Style Utility, you can define the utility class name and add USS properties to it.
For example:
selector: card
properties:
- padding: 12px
- background-color: #f3f4f6
- border-radius: 8pxThis would create a utility class named card that you can use in your UXML or C# scripts like any other utility class:
<VisualElement class="card"/>
<VisualElement class="hover---card"/>
// or in C#
element.AddClass("card");
element.AddClass("hover:card");Utility Combos (Like @apply)
Inside the Utility Combo, you can add multiple utility classes that will be grouped together. For example, you could create a "btn-primary" combo that includes padding, background color, text color, ..., without state. This can then be used on UXML as a single class or even with states like hover:btn-primary.
Once created, you can use the combo class directly in your UXML or C# scripts like any other utility class.
For example:
selector: btn
apply:
- px-4
- py-2
- bg-blue-200
- text-white
- rounded-mdUse it like this:
<Button class="btn"/>
<Button class="hover---btn"/>
// or in C#
element.AddClass("btn");
element.AddClass("hover:btn");Component (Like @component)
I said somewhat because the Style Component look just like the Utility Combo, but what makes it different is that you can define states in it.
Inside the Style Component, you can define styles for specific UI elements, including default styles and state-based styles (like hover, active, etc.).
For example, you could create a "card" component that defines styles for a VisualElement with padding, background color, border radius, and hover effects.
Once created, you can use the component class directly in your UXML or C# scripts like any other utility class.
Create a Style Component ScriptableObject via Right-click → Create → Kostom → Styles → Style Component.
For example:
selector: card
Components:
- hover:p-4
- bg-blue-100
- lg:hover:bg-violet-100