Utilities

Border Width

The Border Width utility provides control over the thickness of borders on UI elements.

Utility Class
USS Properties
border-0
border-width: 0px;
border-2
border-width: 2px;
border-4
border-width: 4px;
border-8
border-width: 8px;
border
border-width: 1px;
border-t-0
border-top-width: 0px;
border-t-2
border-top-width: 2px;
border-t-4
border-top-width: 4px;
border-t-8
border-top-width: 8px;
border-t
border-top-width: 1px;
border-r-0
border-right-width: 0px;
border-r-2
border-right-width: 2px;
border-r-4
border-right-width: 4px;
border-r-8
border-right-width: 8px;
border-r
border-right-width: 1px;
border-b-0
border-bottom-width: 0px;
border-b-2
border-bottom-width: 2px;
border-b-4
border-bottom-width: 4px;
border-b-8
border-bottom-width: 8px;
border-b
border-bottom-width: 1px;
border-l-0
border-left-width: 0px;
border-l-2
border-left-width: 2px;
border-l-4
border-left-width: 4px;
border-l-8
border-left-width: 8px;
border-l
border-left-width: 1px;

Using Border Width in UXML

Uniform Border Width

<ui:VisualElement class="border-4">
    <!-- Element with a uniform border width of 4px -->
</ui:VisualElement>

Specific Border Widths

You can also apply border width to specific sides of an element:

<ui:VisualElement class="border-t-0 border-r-2 border-b-4 border-l-8">
    <!-- Element with a border width of 0px on the top, 2px on the right, 4px on the bottom, and 8px on the left -->
</ui:VisualElement>

Customize

Modifier Variations

Modifier Variations

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

These modifier variations are enabled for the Border Width utility by default:
  • hover
  • focus
  • checked

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 Border Width 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 Border Width 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 Border Width utility:

  • border : border-width
  • border-t : border-top-width
  • border-r : border-right-width
  • border-b : border-bottom-width
  • border-l : border-left-width

To customize these tags and properties, you can edit the Tag Property Map field for the Border Width 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 Border Width 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 Border Width 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 Border Width 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
Border Radius
Next
Cursor