Utilities

Space Evenly

The Space utility is used to control the spacing between child elements within a container. This is particularly useful for evenly spacing items horizontally or vertically, providing a consistent layout without the need to individually adjust the margins of each element.

Utility Class
USS Properties
space-x-0 > *
margin-left: 0px;
margin-right: 0px;
space-x-1 > *
margin-left: 4px;
margin-right: 4px;
space-x-2 > *
margin-left: 8px;
margin-right: 8px;
space-x-3 > *
margin-left: 12px;
margin-right: 12px;
space-x-4 > *
margin-left: 16px;
margin-right: 16px;
space-x-5 > *
margin-left: 20px;
margin-right: 20px;
space-x-6 > *
margin-left: 24px;
margin-right: 24px;
space-x-7 > *
margin-left: 28px;
margin-right: 28px;
space-x-8 > *
margin-left: 32px;
margin-right: 32px;
space-x-9 > *
margin-left: 36px;
margin-right: 36px;
space-x-10 > *
margin-left: 40px;
margin-right: 40px;
space-x-11 > *
margin-left: 44px;
margin-right: 44px;
space-x-12 > *
margin-left: 48px;
margin-right: 48px;
space-x-14 > *
margin-left: 56px;
margin-right: 56px;
space-x-16 > *
margin-left: 64px;
margin-right: 64px;
space-x-20 > *
margin-left: 80px;
margin-right: 80px;
space-x-24 > *
margin-left: 96px;
margin-right: 96px;
space-x-28 > *
margin-left: 112px;
margin-right: 112px;
space-x-32 > *
margin-left: 128px;
margin-right: 128px;
space-x-36 > *
margin-left: 144px;
margin-right: 144px;
space-x-40 > *
margin-left: 160px;
margin-right: 160px;
space-x-44 > *
margin-left: 176px;
margin-right: 176px;
space-x-48 > *
margin-left: 192px;
margin-right: 192px;
space-x-52 > *
margin-left: 208px;
margin-right: 208px;
space-x-56 > *
margin-left: 224px;
margin-right: 224px;
space-x-60 > *
margin-left: 240px;
margin-right: 240px;
space-x-64 > *
margin-left: 256px;
margin-right: 256px;
space-x-72 > *
margin-left: 288px;
margin-right: 288px;
space-x-80 > *
margin-left: 320px;
margin-right: 320px;
space-x-96 > *
margin-left: 384px;
margin-right: 384px;
space-x-px > *
margin-left: 1px;
margin-right: 1px;
space-x-0point5 > *
margin-left: 2px;
margin-right: 2px;
space-x-1point5 > *
margin-left: 6px;
margin-right: 6px;
space-x-2point5 > *
margin-left: 10px;
margin-right: 10px;
space-x-3point5 > *
margin-left: 14px;
margin-right: 14px;
space-x-minus-0 > *
margin-left: 0px;
margin-right: 0px;
space-x-minus-1 > *
margin-left: -4px;
margin-right: -4px;
space-x-minus-2 > *
margin-left: -8px;
margin-right: -8px;
space-x-minus-3 > *
margin-left: -12px;
margin-right: -12px;
space-x-minus-4 > *
margin-left: -16px;
margin-right: -16px;
space-x-minus-5 > *
margin-left: -20px;
margin-right: -20px;
space-x-minus-6 > *
margin-left: -24px;
margin-right: -24px;
space-x-minus-7 > *
margin-left: -28px;
margin-right: -28px;
space-x-minus-8 > *
margin-left: -32px;
margin-right: -32px;
space-x-minus-9 > *
margin-left: -36px;
margin-right: -36px;
space-x-minus-10 > *
margin-left: -40px;
margin-right: -40px;
space-x-minus-11 > *
margin-left: -44px;
margin-right: -44px;
space-x-minus-12 > *
margin-left: -48px;
margin-right: -48px;
space-x-minus-14 > *
margin-left: -56px;
margin-right: -56px;
space-x-minus-16 > *
margin-left: -64px;
margin-right: -64px;
space-x-minus-20 > *
margin-left: -80px;
margin-right: -80px;
space-x-minus-24 > *
margin-left: -96px;
margin-right: -96px;
space-x-minus-28 > *
margin-left: -112px;
margin-right: -112px;
space-x-minus-32 > *
margin-left: -128px;
margin-right: -128px;
space-x-minus-36 > *
margin-left: -144px;
margin-right: -144px;
space-x-minus-40 > *
margin-left: -160px;
margin-right: -160px;
space-x-minus-44 > *
margin-left: -176px;
margin-right: -176px;
space-x-minus-48 > *
margin-left: -192px;
margin-right: -192px;
space-x-minus-52 > *
margin-left: -208px;
margin-right: -208px;
space-x-minus-56 > *
margin-left: -224px;
margin-right: -224px;
space-x-minus-60 > *
margin-left: -240px;
margin-right: -240px;
space-x-minus-64 > *
margin-left: -256px;
margin-right: -256px;
space-x-minus-72 > *
margin-left: -288px;
margin-right: -288px;
space-x-minus-80 > *
margin-left: -320px;
margin-right: -320px;
space-x-minus-96 > *
margin-left: -384px;
margin-right: -384px;
space-x-minus-px > *
margin-left: -1px;
margin-right: -1px;
space-x-minus-0point5 > *
margin-left: -2px;
margin-right: -2px;
space-x-minus-1point5 > *
margin-left: -6px;
margin-right: -6px;
space-x-minus-2point5 > *
margin-left: -10px;
margin-right: -10px;
space-x-minus-3point5 > *
margin-left: -14px;
margin-right: -14px;
space-y-0 > *
margin-top: 0px;
margin-bottom: 0px;
space-y-1 > *
margin-top: 4px;
margin-bottom: 4px;
space-y-2 > *
margin-top: 8px;
margin-bottom: 8px;
space-y-3 > *
margin-top: 12px;
margin-bottom: 12px;
space-y-4 > *
margin-top: 16px;
margin-bottom: 16px;
space-y-5 > *
margin-top: 20px;
margin-bottom: 20px;
space-y-6 > *
margin-top: 24px;
margin-bottom: 24px;
space-y-7 > *
margin-top: 28px;
margin-bottom: 28px;
space-y-8 > *
margin-top: 32px;
margin-bottom: 32px;
space-y-9 > *
margin-top: 36px;
margin-bottom: 36px;
space-y-10 > *
margin-top: 40px;
margin-bottom: 40px;
space-y-11 > *
margin-top: 44px;
margin-bottom: 44px;
space-y-12 > *
margin-top: 48px;
margin-bottom: 48px;
space-y-14 > *
margin-top: 56px;
margin-bottom: 56px;
space-y-16 > *
margin-top: 64px;
margin-bottom: 64px;
space-y-20 > *
margin-top: 80px;
margin-bottom: 80px;
space-y-24 > *
margin-top: 96px;
margin-bottom: 96px;
space-y-28 > *
margin-top: 112px;
margin-bottom: 112px;
space-y-32 > *
margin-top: 128px;
margin-bottom: 128px;
space-y-36 > *
margin-top: 144px;
margin-bottom: 144px;
space-y-40 > *
margin-top: 160px;
margin-bottom: 160px;
space-y-44 > *
margin-top: 176px;
margin-bottom: 176px;
space-y-48 > *
margin-top: 192px;
margin-bottom: 192px;
space-y-52 > *
margin-top: 208px;
margin-bottom: 208px;
space-y-56 > *
margin-top: 224px;
margin-bottom: 224px;
space-y-60 > *
margin-top: 240px;
margin-bottom: 240px;
space-y-64 > *
margin-top: 256px;
margin-bottom: 256px;
space-y-72 > *
margin-top: 288px;
margin-bottom: 288px;
space-y-80 > *
margin-top: 320px;
margin-bottom: 320px;
space-y-96 > *
margin-top: 384px;
margin-bottom: 384px;
space-y-px > *
margin-top: 1px;
margin-bottom: 1px;
space-y-0point5 > *
margin-top: 2px;
margin-bottom: 2px;
space-y-1point5 > *
margin-top: 6px;
margin-bottom: 6px;
space-y-2point5 > *
margin-top: 10px;
margin-bottom: 10px;
space-y-3point5 > *
margin-top: 14px;
margin-bottom: 14px;
space-y-minus-0 > *
margin-top: 0px;
margin-bottom: 0px;
space-y-minus-1 > *
margin-top: -4px;
margin-bottom: -4px;
space-y-minus-2 > *
margin-top: -8px;
margin-bottom: -8px;
space-y-minus-3 > *
margin-top: -12px;
margin-bottom: -12px;
space-y-minus-4 > *
margin-top: -16px;
margin-bottom: -16px;
space-y-minus-5 > *
margin-top: -20px;
margin-bottom: -20px;
space-y-minus-6 > *
margin-top: -24px;
margin-bottom: -24px;
space-y-minus-7 > *
margin-top: -28px;
margin-bottom: -28px;
space-y-minus-8 > *
margin-top: -32px;
margin-bottom: -32px;
space-y-minus-9 > *
margin-top: -36px;
margin-bottom: -36px;
space-y-minus-10 > *
margin-top: -40px;
margin-bottom: -40px;
space-y-minus-11 > *
margin-top: -44px;
margin-bottom: -44px;
space-y-minus-12 > *
margin-top: -48px;
margin-bottom: -48px;
space-y-minus-14 > *
margin-top: -56px;
margin-bottom: -56px;
space-y-minus-16 > *
margin-top: -64px;
margin-bottom: -64px;
space-y-minus-20 > *
margin-top: -80px;
margin-bottom: -80px;
space-y-minus-24 > *
margin-top: -96px;
margin-bottom: -96px;
space-y-minus-28 > *
margin-top: -112px;
margin-bottom: -112px;
space-y-minus-32 > *
margin-top: -128px;
margin-bottom: -128px;
space-y-minus-36 > *
margin-top: -144px;
margin-bottom: -144px;
space-y-minus-40 > *
margin-top: -160px;
margin-bottom: -160px;
space-y-minus-44 > *
margin-top: -176px;
margin-bottom: -176px;
space-y-minus-48 > *
margin-top: -192px;
margin-bottom: -192px;
space-y-minus-52 > *
margin-top: -208px;
margin-bottom: -208px;
space-y-minus-56 > *
margin-top: -224px;
margin-bottom: -224px;
space-y-minus-60 > *
margin-top: -240px;
margin-bottom: -240px;
space-y-minus-64 > *
margin-top: -256px;
margin-bottom: -256px;
space-y-minus-72 > *
margin-top: -288px;
margin-bottom: -288px;
space-y-minus-80 > *
margin-top: -320px;
margin-bottom: -320px;
space-y-minus-96 > *
margin-top: -384px;
margin-bottom: -384px;
space-y-minus-px > *
margin-top: -1px;
margin-bottom: -1px;
space-y-minus-0point5 > *
margin-top: -2px;
margin-bottom: -2px;
space-y-minus-1point5 > *
margin-top: -6px;
margin-bottom: -6px;
space-y-minus-2point5 > *
margin-top: -10px;
margin-bottom: -10px;
space-y-minus-3point5 > *
margin-top: -14px;
margin-bottom: -14px;

Basic Usage

Horizontal Spacing

To apply horizontal spacing, use space-x-{value} classes. The value determines the space between each child element along the horizontal axis.

<ui:VisualElement class="flex flex-row space-x-2">
  <!-- Each child will have 8px margin to its right and left -->
</ui:VisualElement>

Vertical Spacing

For vertical spacing, use space-y-{value} classes. This adjusts the space between child elements along the vertical axis.

<ui:VisualElement class="flex-column space-y-3">
  <!-- Each child will have 12px margin to its top and bottom -->
</ui:VisualElement>

Removing Space from First or Last Elements

In some cases, you might want to remove the spacing from the first or last child element. This can be achieved by applying negative margins to the parent container.

<ui:VisualElement class="space-y-2 -my-2">
  <!-- Removes the top and bottom margin from the first and last child -->
</ui:VisualElement>

Why not :first-child or :last-child

You might be wondering why we don't use the :first-child and :last-child pseudo selectors to remove the margins from the first and last child elements. The reason is that these selectors are not currently supported in USS.


Customize

Modifier Variations

Modifier Variations

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

By default, no modifier variations are defined for the Space utility.

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 Space 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 Space 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 Space utility:

  • space-x : margin-left, margin-right
  • space-y : margin-top, margin-bottom

To customize these tags and properties, you can edit the Tag Property Map field for the Space 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 Space utility uses values from the following fields from the Core section of the Theme Config asset:

  • Spacing
  • NegativeSpacing
These fields are used in addition to any custom values defined for the utility. If the same key exists in both the utility and core configurations, the utility's values will override those from the core.

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 Space 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 Space 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
Scale