Table of Contents Show
Unity Style Sheets (USS) provide a built-in animation system that allows you to define transitions for many USS properties. Combined with pseudo-classes such as :hover and :selected, it offers you a wide range of options for interactive effects based on user input.
In this tutorial, I show you three examples of USS hover effects in UI Toolkit. They are based solely on USS and do not require any C# script.
Created with Unity 6.3 | Source code on Github
Animate background shapes
This example consists of four cards. Each card contains a text label and a round, colored blob in the background. When the user hovers over a card, the blob grows until it covers the entire card. At the same time, the text changes its color.

UXML structure
First, create the UXML file for the sample. Each card has three visual layers:
- the card itself, which provides the dark background
- the rounded blob, which sits behind the text and expands on hover.
- the label, which sits on top of the blob
<ui:VisualElement name="Card" class="card">
<ui:VisualElement name="Shape" class="card-blob"/>
<ui:Label text="PLAY"/>
</ui:VisualElement> The style classes card and card-blob are important because the USS file will use them. The names are not important. They only provide a better overview in the UI builder.
Create four cards in the same way. Add them into a parent container and set its flex-direction to row.
The complete UXML code looks like this:
<ui:VisualElement style="flex-direction: row; justify-content: center;">
<ui:VisualElement name="Card" class="card">
<ui:VisualElement name="Shape" class="card-blob"/>
<ui:Label text="PLAY"/>
</ui:VisualElement>
<ui:VisualElement name="Card" class="card">
<ui:VisualElement name="Shape" class="card-blob"/>
<ui:Label text="OPTIONS"/>
</ui:VisualElement>
<ui:VisualElement name="Card" class="card">
<ui:VisualElement name="Shape" class="card-blob"/>
<ui:Label text="EXTRAS"/>
</ui:VisualElement>
<ui:VisualElement name="Card" class="card">
<ui:VisualElement name="Shape" class="card-blob"/>
<ui:Label text="QUIT"/>
</ui:VisualElement>
</ui:VisualElement> Note: If you create the elements in the UI builder, the flex-grow property is automatically set to 1. Reset it to 0 for all elements.
Basic style
At the moment, nothing is visible in our UI document. The cards have no size, so there is nothing to display.
First, give the cards a fixed size and background color. Center the content using justify-content, which determines the position of the label. Set overflow to hidden because the blob will extend beyond the card.
.card {
background-color: rgb(15, 15, 15);
width: 200px;
height: 200px;
margin: 20px;
justify-content: center;
overflow: hidden;
} The blob uses absolute positioning. It is purely a background element, so it shouldn’t affect the layout of the card or label.
Set its border radius to 50% to turn it into a circle and assign the same size (200px) as the card. Only a quarter of the circle should be visible. Therefore, position the blob at -100px on the right and bottom sides. Finally, assign a background image to create the gradient effect.
.card .card-blob {
position: absolute;
width: 200px;
height: 200px;
right: -100px;
bottom: -100px;
border-radius: 50%;
background-image: url("../Content/Textures/green-gradient.png");
background-repeat: repeat;
} Finally, adjust the label’s color and font properties.
.card .unity-label {
color: rgb(54, 173, 189);
font-size: 14px;
-unity-text-align: middle-center;
-unity-font-style: bold;
} 
Place the blobs in different corners
The card on the left already looks close to what we want. However, the colored blob is currently positioned in the same corner on every card.
Assign different style classes to the cards depending on where the blob should be located: card-left-top, card-left-bottom, card-right-top, and card-right-bottom.
Assign different positions based on the new style classes. Also rotate the background image. Then the blobs show the same cutout of the image.
.card-left-bottom .card-blob {
left: -100px;
bottom: -100px;
}
.card-right-bottom .card-blob {
right: -100px;
bottom: -100px;
rotate: 90deg;
}
.card-left-top .card-blob {
left: -100px;
top: -100px;
rotate: 180deg;
}
.card-right-top .card-blob {
right: -100px;
top: -100px;
rotate: 270deg;
}
Hover effect
The :hover pseudo-class allows you to define a different style while the user hovers over an element. In this example, the colored blob should grow until it covers the entire card.
.card:hover .card-blob {
width: 360px;
height: 360px;
}
Transitions are necessary to get a smooth animation between the two states. It’s important to define the transition in the basic selector, not the one with the hover pseudo-class. Then it will be active in both states: when the mouse enters the card and when it leaves.
The transition affects the properties width and height and has a duration of 0.5 seconds. The ease-in-out-back timing function adds a slight overshoot to the animation, giving the blob a more playful movement.
.card .card-blob {
// ... existing code
transition-property: width, height;
transition-duration: 0.5s;
transition-timing-function: ease-in-out-back;
} The label text should change its color to white when the blob covers the whole background.
.card:hover .unity-label {
color: rgb(255, 255, 255);
}
Finally, add a slight delay to the label transition. This makes the color change start after the blob has already begun expanding, so the text changes when the animation is roughly halfway through.
.card .unity-label {
// ... existing code
transition-property: color;
transition-delay: 0.2s;
transition-duration: 0.3s;
}
This creates a simple but effective hover animation: the colored shape expands from the corner, while the label smoothly changes from its original color to white.
Absolute sizes or percentages?
The blob size and offsets are defined in pixels. This has the drawback that changing the card size also requires changing the blob size.
Alternatively, the size could also be defined with percentages. 100% for the size and 50% for the offsets. Unfortunately, this does not work well when the card width shrinks because there is not enough space.
The problem is that percentage-based width and height are calculated independently from the card’s width and height. If the card is not square, the blob’s width and height will differ, turning the circle into an ellipse. With the rotation value, it’s even stretched in the wrong direction.

Expand the button icon
In the second example, the background shape and icon change while the user hovers over a button.

UXML definition
The button consists of
- the button itself, which provides hover and click events
- a circle on the left side
- an arrow icon inside the circle
- a label for the text, which is on the right side of the button
<ui:Button text="" class="button">
<ui:VisualElement name="circle" class="button-circle">
<ui:VisualElement name="icon" class="button-icon"/>
</ui:VisualElement>
<ui:Label text="LEARN MORE" class="button-text"/>
</ui:Button> We use a separate label instead of the button’s text property because it offers more flexibility for positioning and styling.
Basic style with USS
First, we need to remove some default styles from the button. It should be transparent, without a border, and without padding. Define a fixed width, align the child items at the center, and set the flex-direction to row.
.button {
width: 120px;
background-color: transparent;
padding: 0;
border-width: 0;
flex-direction: row;
align-items: center;
}
Use absolute positioning for the circle. Later, it will change its size, and this should not affect the layout of other elements. Set the width and height values to a fixed size. Use half of the value for the border-radius to convert the shape to a circle.
.button-circle {
position: absolute;
width: 24px;
height: 24px;
background-color: black;
border-radius: 12px;
} Assign a background image to the icon element. You can download it from the Git repository. Change the size and margin values so that it shows up at the center of the circle.
.button-icon {
width: 18px;
height: 18px;
margin: 3px 0 0 -2px;
background-image: url("../Content/Textures/arrow-1.png");
} Finally, adjust the spacing of the label. It has a larger margin on the left side to leave space for the circle. This is necessary because the circle uses absolute positioning and therefore is not automatically arranged.
.button-text {
margin: 8px 8px 8px 32px;
font-size: 12px;
} Hover effect
While the user hovers over the button, the circle should convert into a rounded rectangle and cover the whole button. This is achieved by setting the width to 100% of the button.
Add the transition properties to achieve a smooth animation. Again, it’s important to add the transition to the basic USS selector without the pseudo-class. This ensures that it is active when the mouse enters the button and when it leaves.
.button:hover .button-circle {
width: 100%;
}
.button-circle {
// ... existing code
transition-property: width;
transition-duration: 0.2s;
transition-timing-function: ease-in-out-cubic;
}
The text color has to change because it would not be visible on the black background. Start the transition with a delay of 0.1 to approximately coordinate the color change with the background change.
.button:hover .button-text {
color: rgb(225, 225, 225);
}
.button-text {
// ... existing code
transition-property: color;
transition-delay: 0.1s;
transition-duration: 0.1s;
} Finally, switch the icon to an arrow with a line. Assign a new background image and adjust the margin to make the icon slide to the right.
.button:hover .button-icon {
background-image: url("../Content/Textures/arrow-2.png");
margin: 3px 0 0 5px;
}
.button-icon {
// ... existing code
transition-property: margin;
transition-duration: 0.2s;
}
The background image cannot be animated with transitions. The USS properties reference shows which properties are supported by transitions.
Blur background images
The last example blurs images while hovering over them. Additionally, text appears over the blurred image.

UXML definition
Each image block consists of
- an outer container with the style class
blur-image - the image itself
- a label for the text
<ui:VisualElement class="blur-image">
<ui:Image scale-mode="ScaleAndCrop" source="project://..." />
<ui:Label text="LIGHT BLUR"/>
</ui:VisualElement> Note: The image source is missing in the code. The easiest way is to select a texture in the UI builder.
The example contains three image blocks for light, medium, and strong blur. First, duplicate the existing image block. Then add a different style class to each of them to distinguish them: blur-image-light, blur-image-medium, blur-image-strong.
The overall UXML code looks like this:
<ui:VisualElement name="BlurImagesExample" style="flex-direction: row; align-items: center; justify-content: space-around;">
<ui:VisualElement name="" class="blur-image blur-image-light">
<ui:Image source="project://..." scale-mode="ScaleAndCrop"/>
<ui:Label text="LIGHT BLUR"/>
</ui:VisualElement>
<ui:VisualElement class="blur-image blur-image-medium">
<ui:Image source="project://..." scale-mode="ScaleAndCrop"/>
<ui:Label text="MEDIUM BLUR"/>
</ui:VisualElement>
<ui:VisualElement class="blur-image blur-image-light blur-image-strong">
<ui:Image source="..." scale-mode="ScaleAndCrop"/>
<ui:Label text="STRONG BLUR"/>
</ui:VisualElement>
</ui:VisualElement> Basic style
Assign a fixed size to the container and justify the content in the center.
.blur-image {
width: 300px;
height: 200px;
justify-content: center;
} The image itself should cover the whole container. Set the position to absolute and the sizes to 100%.
.blur-image .unity-image {
position: absolute;
width: 100%;
height: 100%;
} Finally, adjust the font style of the label.
.blur-image .unity-label {
font-size: 14px;
-unity-font-style: bold;
-unity-text-align: middle-center;
} Hover effect
First, add the blur filter to the image elements when the :hover pseudo-class is active. We defined three style classes and can assign different blur values to them.
.blur-image-light:hover .unity-image {
filter: blur(2px);
}
.blur-image-medium:hover .unity-image {
filter: blur(4px);
}
.blur-image-strong:hover .unity-image {
filter: blur(8px);
} Define a basic transition for the filter property.
.blur-image .unity-image {
// ... existing code
transition-property: filter;
transition-duration: 0.2s;
} Finally, hide the label when the user is not hovering over the image block. Use the opacity property because you can animate it with a transition. Additionally, increase the font size for the hover state to achieve a zooming effect.
.blur-image .unity-label {
// ... existing code
opacity: 0;
transition-property: opacity, font-size;
transition-duration: 0.2s;
}
.blur-image:hover .unity-label {
opacity: 1;
font-size: 18px;
} These examples show how much can be achieved with USS alone – without writing a single line of C# code. By combining USS properties, pseudo-classes, and transitions, you can create creative UI effects.
Of course, this approach has its limits: You are restricted to the properties and transitions supported by USS. Custom animations and more complex interactions still require code.
