Utilities

Opacity

The Opacity utility allows you to control the transparency of an element and its children. This utility provides a range of classes to adjust the opacity from fully transparent to fully opaque.

Utility Class
USS Properties
opacity-0
opacity: 0;
opacity-5
opacity: 0.05;
opacity-10
opacity: 0.1;
opacity-20
opacity: 0.2;
opacity-25
opacity: 0.25;
opacity-30
opacity: 0.3;
opacity-40
opacity: 0.4;
opacity-50
opacity: 0.5;
opacity-60
opacity: 0.6;
opacity-70
opacity: 0.7;
opacity-75
opacity: 0.75;
opacity-80
opacity: 0.8;
opacity-90
opacity: 0.9;
opacity-95
opacity: 0.95;
opacity-100
opacity: 1;

Basic Usage in UXML

Here is how you might use these classes in your project:

<!-- Fully transparent element -->
<ui:VisualElement class="opacity-0" />

<!-- Semi-transparent element -->
<ui:VisualElement class="opacity-50" />

<!-- Fully opaque element -->
<ui:VisualElement class="opacity-100" />

Customize

Modifier Variations

Modifier Variations

You can customize which modifier variations of the Opacity utility are generated, such as pseudo-classes (e.g., hover, focus) and custom modifiers.

These modifier variations are enabled for the Opacity utility by default:
  • hover
  • focus

By fine-tuning the utility variations, you maintain control over your stylesheet's size and complexity, ensuring that only necessary styles are included. To update these values:

  1. Open the Theme Config Asset: Find the asset within your Unity project.
  2. Navigate to the 'Utilities' Section: Locate the Opacity utility.
  3. Adjust Modifier Variations: Select which modifiers you want to be generated for the utility. Keep in mind that the order of the modifiers will affect the order and specificity of the generated USS classes.

Class Tags and Properties

Class Tags and Properties

The Opacity utility generates classes based on predefined tags and their associated USS properties. While we recommend keeping these defaults for consistency and ease of reference in our documentation, you have the option to customize them to suit your project's specific needs.

These values are prepended to the defined values in this format tag-{value}. If a tag is empty, the generated class will simply be the value by itself.

Here are the default tags and the USS properties they set for the Opacity utility:

  • opacity : opacity

To customize these tags and properties, you can edit the Tag Property Map field for the Opacity utility in the Theme Config asset. This allows you to define new tags or modify existing ones, thus tailoring the generated classes to your preferences.

Extending Core Fields

The Opacity utility does not extend any fields from the Core section of the Theme Config asset. Before you try to extend any fields, we recommend checking Unity's documentation to verify which types of values are expected by the relevant USS properties.

To customize or define these extended fields:

  1. Open the Theme Config Asset: Locate the asset within your Unity project.
  2. Navigate to the 'Utilities' Section: Find the Opacity utility.
  3. Customize Extend Fields: Modify or add fields in the Extend Fields array to change the core configuration values that are extended. You'll only be able to extend fields of the same type.

Disable Utility

The Opacity utility is enabled by default. You can disable it by unchecking the Enabled option in the Theme Config asset. This will prevent the generation of the utility's styles.

Previous
Min-Width