|
| 1 | +--- |
| 2 | +title: Spacing | Ignite UI for Angular |
| 3 | +_description: The Ignite UI for Angular provides a way of adjusting paddings and margins with ease on application or component level. |
| 4 | +_keywords: Ignite UI for Angular, UI controls, Angular widgets, web widgets, UI widgets, Angular, Native Angular Components Suite, Native Angular Components, Native Angular Controls, Native Angular Components Library, spacing, padding, margin |
| 5 | +--- |
| 6 | + |
| 7 | +# Spacing |
| 8 | + |
| 9 | +Spacing configuration can significantly improve the visual representation of large amounts of data. In Ignite UI for Angular, we provide a pre-defined set of options for adjusting paddings and margins. |
| 10 | + |
| 11 | +Instead of using fixed values, we use CSS custom properties to adjust the spacing on an application or a component level. |
| 12 | + |
| 13 | +## How Spacing Works |
| 14 | + |
| 15 | +Ignite UI for Angular provides a sophisticated spacing system that scales dynamically based on component sizes (small, medium, large). The spacing system is built around CSS custom properties that allow you to control spacing at a global or component level without writing custom CSS. |
| 16 | + |
| 17 | +## The Relationship Between Sizing and Spacing |
| 18 | + |
| 19 | +The spacing system in Ignite UI is closely tied to component sizing. Components can have three different sizes: |
| 20 | +- **Small** - Compact spacing for dense layouts |
| 21 | +- **Medium** - Default balanced spacing. |
| 22 | +- **Large** - Comfortable spacing for touch-friendly interfaces |
| 23 | + |
| 24 | +The spacing automatically adapts based on which size is active, ensuring consistent visual hierarchy throughout your application. |
| 25 | + |
| 26 | +## Core CSS Custom Properties |
| 27 | + |
| 28 | +The spacing system revolves around several key CSS custom properties: |
| 29 | + |
| 30 | +### Global Spacing Properties |
| 31 | + |
| 32 | +- `--ig-spacing` - The base spacing multiplier (default: 1) |
| 33 | +- `--ig-spacing-small` - Spacing for small-sized components |
| 34 | +- `--ig-spacing-medium` - Spacing for medium-sized components. |
| 35 | +- `--ig-spacing-large` - Spacing for large-sized components |
| 36 | + |
| 37 | +### Directional Spacing Properties |
| 38 | + |
| 39 | +- `--ig-spacing-inline` - Controls horizontal spacing |
| 40 | +- `--ig-spacing-block` - Controls vertical spacing |
| 41 | +- `--ig-spacing-inline-small` - Horizontal spacing for small components |
| 42 | +- `--ig-spacing-inline-medium` - Horizontal spacing for medium components |
| 43 | +- `--ig-spacing-inline-large` - Horizontal spacing for large components |
| 44 | +- `--ig-spacing-block-small` - Vertical spacing for small components |
| 45 | +- `--ig-spacing-block-medium` - Vertical spacing for medium components |
| 46 | +- `--ig-spacing-block-large` - Vertical spacing for large components |
| 47 | + |
| 48 | +## Size Detection Variables |
| 49 | + |
| 50 | +Components use CSS custom properties to automatically detect their current size: |
| 51 | + |
| 52 | +- `--is-small` - Set to 1 when component is small-sized, 0 otherwise. |
| 53 | +- `--is-medium` - Set to 1 when component is medium-sized, 0 otherwise |
| 54 | +- `--is-large` - Set to 1 when component is large-sized, 0 otherwise. |
| 55 | +- `--component-size` - Numeric value indicating current size (1=small, 2=medium, 3=large). |
| 56 | + |
| 57 | +These variables are automatically managed by the theming system and change based on the component's size setting, controlled by `--ig-size`. |
| 58 | + |
| 59 | +## Practical Usage Examples |
| 60 | + |
| 61 | +### Global Spacing Control |
| 62 | + |
| 63 | +To make all components more compact across your entire application: |
| 64 | + |
| 65 | +```css |
| 66 | +:root { |
| 67 | + --ig-spacing: 0.8; /* 20% less spacing */ |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +To increase spacing for better touch accessibility: |
| 72 | + |
| 73 | +```css |
| 74 | +:root { |
| 75 | + --ig-spacing: 1.2; /* 20% more spacing */ |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +### Component-Specific Spacing |
| 80 | + |
| 81 | +To adjust spacing for a specific component type: |
| 82 | + |
| 83 | +```css |
| 84 | +.my-grid { |
| 85 | + --ig-spacing: 0.5; /* More compact grid, 50% of the original spacing in all sizes */ |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +### Directional Spacing Control |
| 90 | + |
| 91 | +To reduce only horizontal spacing while keeping vertical spacing normal: |
| 92 | + |
| 93 | +```css |
| 94 | +:root { |
| 95 | + --ig-spacing-inline: 0.7; |
| 96 | + --ig-spacing-block: 1.0; |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +### Size-Specific Spacing |
| 101 | + |
| 102 | +To customize spacing for specific component sizes: |
| 103 | + |
| 104 | +```css |
| 105 | +:root { |
| 106 | + --ig-spacing-small: 0.5; /* Very tight for small components */ |
| 107 | + --ig-spacing-medium: 1.0; /* Normal for medium components */ |
| 108 | + --ig-spacing-large: 1.5; /* Extra spacious for large components */ |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +## How Spacing Multipliers Work |
| 113 | + |
| 114 | +The spacing system uses multipliers to scale base values: |
| 115 | + |
| 116 | +- Spacing values in components are multiplied by the active spacing variables |
| 117 | +- For example, if a component has `8px` base padding and you set `--ig-spacing: 1.5`, the actual padding becomes `12px` |
| 118 | +- Size-specific multipliers like `--ig-spacing-large` override the global `--ig-spacing` for large-sized components |
| 119 | +- Directional multipliers like `--ig-spacing-inline` allow you to scale horizontal and vertical spacing independently |
| 120 | + |
| 121 | +This cascading approach ensures consistent spacing relationships while giving you fine-grained control through CSS custom properties alone. |
| 122 | + |
| 123 | +## API References |
| 124 | +* [Utilities - Pad]({environment:sassApiUrl}/utilities#function-pad) |
| 125 | +* [Utilities - Pad Inline]({environment:sassApiUrl}/utilities#function-pad-inline) |
| 126 | +* [Utilities - Pad Block]({environment:sassApiUrl}/utilities#function-pad-block) |
| 127 | + |
| 128 | +### Sizing Functions and Mixins |
| 129 | +* [Themes - Sizable Mixin]({environment:sassApiUrl}/themes#mixin-sizable) |
| 130 | +* [Themes - Sizable Function]({environment:sassApiUrl}/themes#function-sizable) |
| 131 | + |
| 132 | +## Additional Resources |
| 133 | +<div class="divider--half"></div> |
| 134 | + |
| 135 | +Our community is active and always welcoming to new ideas. |
| 136 | + |
| 137 | +* [Ignite UI for Angular **Forums**](https://www.infragistics.com/community/forums/f/ignite-ui-for-angular) |
| 138 | +* [Ignite UI for Angular **GitHub**](https://github.com/IgniteUI/igniteui-angular) |
0 commit comments