Utilities

Padding

The Padding utility let you to adjust the spacing inside an element. This utility provides classes for applying uniform padding across all sides, as well as for targeting specific sides or axes.

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

Basic Usage in UXML

Setting Uniform Padding

To apply equal padding to all sides of an element, use p- classes.

<ui:VisualElement class="p-2">
  <!-- Element with uniform padding of 8px -->
</ui:VisualElement>

Setting Horizontal and Vertical Paddings

For controlling the horizontal (left and right) padding, use px- classes, and for vertical (top and bottom) padding, use py- classes.

<ui:VisualElement class="px-3 py-1">
  <!-- Element with horizontal padding of 12px and vertical padding of 4px -->
</ui:VisualElement>

Setting Individual Side Paddings

You can also specify padding for individual sides using pt- (top), pr- (right), pb- (bottom), and pl- (left) classes.

<ui:VisualElement class="pt-1 pr-2 pb-3 pl-4">
  <!-- Element with different paddings for each side -->
</ui:VisualElement>

Customize

Modifier Variations

Modifier Variations

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

By default, no modifier variations are defined for the Padding 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 Padding 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 Padding 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 Padding utility:

  • p : padding
  • px : padding-left, padding-right
  • py : padding-top, padding-bottom
  • pt : padding-top
  • pr : padding-right
  • pb : padding-bottom
  • pl : padding-left

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

  • Spacing
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 Padding 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 Padding 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
Overflow Clip Box