|
| 1 | +--- |
| 2 | +title: Gradients |
| 3 | +summary: Use gradient utilities to build directional color backgrounds with from, via, and to color stops. |
| 4 | +description: Create directional gradients with utility classes. |
| 5 | +--- |
| 6 | + |
| 7 | +{% assign colors = '' | split: '' %} |
| 8 | +{% for color in site.colors %} |
| 9 | +{% assign colors = colors | push: color[0] %} |
| 10 | +{% endfor %} |
| 11 | +{% assign colors = colors | push: 'white' %} |
| 12 | +{% assign colors = colors | push: 'transparent' %} |
| 13 | + |
| 14 | +## Default gradient |
| 15 | + |
| 16 | +Use `.bg-gradient` to enable gradient background rendering on an element. |
| 17 | +Then combine it with color stop utilities to define the final look. |
| 18 | + |
| 19 | +```html |
| 20 | +<div class="bg-gradient bg-gradient-from-primary bg-gradient-to-transparent"></div> |
| 21 | +``` |
| 22 | + |
| 23 | +{% capture html -%} |
| 24 | +<div class="border rounded bg-gradient bg-gradient-from-primary bg-gradient-to-transparent p-5"></div> |
| 25 | +{%- endcapture %} |
| 26 | +{% include "docs/example.html" html=html bg="pattern-rectangles" column %} |
| 27 | + |
| 28 | +## Gradient directions |
| 29 | + |
| 30 | +Use direction utilities to control gradient flow: |
| 31 | + |
| 32 | +- `.bg-gradient-to-t` |
| 33 | +- `.bg-gradient-to-te` |
| 34 | +- `.bg-gradient-to-e` |
| 35 | +- `.bg-gradient-to-be` |
| 36 | +- `.bg-gradient-to-b` |
| 37 | +- `.bg-gradient-to-bs` |
| 38 | +- `.bg-gradient-to-s` |
| 39 | +- `.bg-gradient-to-ts` |
| 40 | + |
| 41 | +{% capture html -%} |
| 42 | +<div class="row row-cols-1 row-cols-sm-2 row-cols-lg-4 g-3"> |
| 43 | + <div class="col"><div class="border rounded bg-gradient bg-gradient-from-blue bg-gradient-to-transparent bg-gradient-to-t p-4"></div><code>.bg-gradient-to-t</code></div> |
| 44 | + <div class="col"><div class="border rounded bg-gradient bg-gradient-from-blue bg-gradient-to-transparent bg-gradient-to-te p-4"></div><code>.bg-gradient-to-te</code></div> |
| 45 | + <div class="col"><div class="border rounded bg-gradient bg-gradient-from-blue bg-gradient-to-transparent bg-gradient-to-e p-4"></div><code>.bg-gradient-to-e</code></div> |
| 46 | + <div class="col"><div class="border rounded bg-gradient bg-gradient-from-blue bg-gradient-to-transparent bg-gradient-to-be p-4"></div><code>.bg-gradient-to-be</code></div> |
| 47 | + <div class="col"><div class="border rounded bg-gradient bg-gradient-from-blue bg-gradient-to-transparent bg-gradient-to-b p-4"></div><code>.bg-gradient-to-b</code></div> |
| 48 | + <div class="col"><div class="border rounded bg-gradient bg-gradient-from-blue bg-gradient-to-transparent bg-gradient-to-bs p-4"></div><code>.bg-gradient-to-bs</code></div> |
| 49 | + <div class="col"><div class="border rounded bg-gradient bg-gradient-from-blue bg-gradient-to-transparent bg-gradient-to-s p-4"></div><code>.bg-gradient-to-s</code></div> |
| 50 | + <div class="col"><div class="border rounded bg-gradient bg-gradient-from-blue bg-gradient-to-transparent bg-gradient-to-ts p-4"></div><code>.bg-gradient-to-ts</code></div> |
| 51 | +</div> |
| 52 | +{%- endcapture %} |
| 53 | +{% include "docs/example.html" html=html bg="surface-primary" hide-code %} |
| 54 | + |
| 55 | +```html |
| 56 | +<div class="bg-gradient bg-gradient-from-blue bg-gradient-to-transparent bg-gradient-to-t"> |
| 57 | + ... |
| 58 | +</div> |
| 59 | +<div class="bg-gradient bg-gradient-from-blue bg-gradient-to-transparent bg-gradient-to-te"> |
| 60 | + ... |
| 61 | +</div> |
| 62 | +<div class="bg-gradient bg-gradient-from-blue bg-gradient-to-transparent bg-gradient-to-e"> |
| 63 | + ... |
| 64 | +</div> |
| 65 | +<div class="bg-gradient bg-gradient-from-blue bg-gradient-to-transparent bg-gradient-to-be"> |
| 66 | + ... |
| 67 | +</div> |
| 68 | +<div class="bg-gradient bg-gradient-from-blue bg-gradient-to-transparent bg-gradient-to-b"> |
| 69 | + ... |
| 70 | +</div> |
| 71 | +<div class="bg-gradient bg-gradient-from-blue bg-gradient-to-transparent bg-gradient-to-bs"> |
| 72 | + ... |
| 73 | +</div> |
| 74 | +<div class="bg-gradient bg-gradient-from-blue bg-gradient-to-transparent bg-gradient-to-s"> |
| 75 | + ... |
| 76 | +</div> |
| 77 | +<div class="bg-gradient bg-gradient-from-blue bg-gradient-to-transparent bg-gradient-to-ts"> |
| 78 | + ... |
| 79 | +</div> |
| 80 | +``` |
| 81 | + |
| 82 | + |
| 83 | +## Gradient color stops |
| 84 | + |
| 85 | +Use color stop utilities to control where a gradient starts, transitions, and ends. You can choose any color from [full list of available colors](/ui/base/colors). |
| 86 | + |
| 87 | +Here is a list of classes: |
| 88 | +- `.bg-gradient-from-{color}` |
| 89 | +- `.bg-gradient-via-{color}` (optional middle stop for smoother blending) |
| 90 | +- `.bg-gradient-to-{color}` |
| 91 | + |
| 92 | +{% capture html -%} |
| 93 | +<div class="row row-cols-1 row-cols-lg-2 g-3"> |
| 94 | + <div class="col"> |
| 95 | + <div class="border rounded bg-gradient bg-gradient-from-purple bg-gradient-to-transparent p-5"></div> |
| 96 | + <code>.bg-gradient-from-purple .bg-gradient-to-transparent</code> |
| 97 | + </div> |
| 98 | + <div class="col"> |
| 99 | + <div class="border rounded bg-gradient bg-gradient-from-pink bg-gradient-via-orange bg-gradient-to-yellow p-5"></div> |
| 100 | + <code>.bg-gradient-from-pink .bg-gradient-via-orange .bg-gradient-to-yellow</code> |
| 101 | + </div> |
| 102 | +</div> |
| 103 | +{%- endcapture %} |
| 104 | +{% include "docs/example.html" html=html bg="pattern-rectangles" hide-code %} |
| 105 | + |
| 106 | +```html |
| 107 | +<div class="bg-gradient bg-gradient-from-purple bg-gradient-to-transparent"> |
| 108 | + ... |
| 109 | +</div> |
| 110 | + |
| 111 | +<div class="bg-gradient bg-gradient-from-pink bg-gradient-via-orange bg-gradient-to-yellow"> |
| 112 | + ... |
| 113 | +</div> |
| 114 | +``` |
| 115 | + |
| 116 | +## Available colors |
| 117 | + |
| 118 | +You can use any project color token with `from`, `via`, and `to` utilities. |
| 119 | +See the [full list of available colors](/ui/base/colors) for all color names. |
| 120 | + |
| 121 | +{% capture html -%} |
| 122 | +<div class="row row-cols-1 row-cols-sm-2 row-cols-lg-3 row-cols-xl-6 g-3"> |
| 123 | + {% for color in colors %} |
| 124 | + <div class="col"> |
| 125 | + <div class="border rounded bg-gradient bg-gradient-from-{{ color }} bg-gradient-to-transparent mb-2 p-4"></div> |
| 126 | + <code>.bg-gradient-from-{{ color }}</code> |
| 127 | + </div> |
| 128 | + {% endfor %} |
| 129 | +</div> |
| 130 | +{%- endcapture %} |
| 131 | +{% include "docs/example.html" html=html bg="surface-primary" hide-code %} |
| 132 | + |
| 133 | +```html |
| 134 | +{% for color in colors %} |
| 135 | +<div class="bg-gradient bg-gradient-from-{{ color }} bg-gradient-to-transparent"> |
| 136 | + ... |
| 137 | +</div> |
| 138 | +{% endfor %} |
| 139 | +``` |
| 140 | + |
| 141 | +## Examples |
| 142 | + |
| 143 | +### Card header gradient |
| 144 | + |
| 145 | +Use gradient utilities on card sections to highlight key content areas. |
| 146 | + |
| 147 | +{% capture html -%} |
| 148 | +<div class="card"> |
| 149 | + <div class="card-body bg-gradient bg-gradient-from-indigo bg-gradient-to-transparent rounded-top"> |
| 150 | + <h3 class="card-title mb-1">Performance</h3> |
| 151 | + <p class="text-secondary mb-0">Weekly trend overview</p> |
| 152 | + </div> |
| 153 | + |
| 154 | + <div class="card-body"> |
| 155 | + <p class="mb-0">Card content</p> |
| 156 | + </div> |
| 157 | +</div> |
| 158 | +{%- endcapture %} |
| 159 | +{% include "docs/example.html" html=html bg="surface-secondary" column %} |
| 160 | + |
| 161 | +### Badge-like highlight |
| 162 | + |
| 163 | +Use short gradients on compact UI elements for subtle emphasis. |
| 164 | + |
| 165 | +{% capture html -%} |
| 166 | +<div class="d-flex gap-2 flex-wrap"> |
| 167 | + <span class="badge bg-gradient bg-gradient-from-green bg-gradient-to-teal">Success trend</span> |
| 168 | + <span class="badge bg-gradient bg-gradient-from-orange bg-gradient-to-red">Warning trend</span> |
| 169 | + <span class="badge bg-gradient bg-gradient-from-blue bg-gradient-to-purple">New feature</span> |
| 170 | +</div> |
| 171 | +{%- endcapture %} |
| 172 | +{% include "docs/example.html" html=html bg="surface-secondary" centered %} |
0 commit comments