|
1 | 1 | ---
|
2 | 2 | title: Buttons
|
3 | 3 | ---
|
| 4 | +Use buttons for major actions. |
4 | 5 |
|
5 |
| -## Link buttons |
| 6 | +Buttons draw more attention than a simple text link. Because of their larger surface and color, they are visually more findable and easier to click or tap. |
6 | 7 |
|
7 |
| -This is some text about link buttons. We should explain why we want links to |
8 |
| -look like buttons. |
| 8 | +## When to use |
| 9 | + |
| 10 | +Use a button when an action has more weight or significance. Examples: |
| 11 | + |
| 12 | +* There is a clear primary action people should take |
| 13 | +* Highlighting a suggested action in a page section |
| 14 | +* A significant or destructive action will be applied and users need to be aware |
| 15 | + |
| 16 | +If the action should not be prompted, a text link may be a better option. |
| 17 | + |
| 18 | +## Types of buttons |
| 19 | + |
| 20 | +### Primary button |
| 21 | + |
| 22 | +This is the most common type of button. Use these to direct people to a clear primary action. To call out that these buttons are actionable, they are action blue (`{{ tokens.colors.action }}`). |
| 23 | + |
| 24 | +```html |
| 25 | +<button class="btn"> |
| 26 | + Do something |
| 27 | +</button> |
| 28 | +``` |
| 29 | + |
| 30 | +Try not to have more than 1 primary button on a page. Multiple primary buttons puts more cognitive load on people. It takes them more time and effort to figure out what to do. |
| 31 | + |
| 32 | +### Inverse button |
| 33 | + |
| 34 | +On some backgrounds, the primary button color will not have sufficient contrast. In this case, use inverse buttons, which have a white fill. |
| 35 | + |
| 36 | +```html wrapper_class="bg-blue-dark p-20" |
| 37 | +<div class="bg-blue-dark"> |
| 38 | + <button class="btn btn-inverse"> |
| 39 | + Do something |
| 40 | + </button> |
| 41 | +</div> |
| 42 | +``` |
| 43 | + |
| 44 | +### Secondary button |
| 45 | + |
| 46 | +```html |
| 47 | +<button class="btn btn-secondary"> |
| 48 | + Do something |
| 49 | +</button> |
| 50 | +``` |
| 51 | + |
| 52 | +Secondary buttons don’t have as much visual weight because they are outlined instead of solid. Use these if your button is not an important action on the page. |
| 53 | + |
| 54 | +Pair it side-by-side with a primary button to prompt toward the primary button’s action. |
| 55 | + |
| 56 | +```html id="buttons-side-by-side" |
| 57 | +<div class="flex gap-20"> |
| 58 | + <button class="btn btn-secondary"> |
| 59 | + Cancel |
| 60 | + </button> |
| 61 | + <button class="btn"> |
| 62 | + Continue |
| 63 | + </button> |
| 64 | +</div> |
| 65 | +``` |
| 66 | + |
| 67 | +## Variations |
| 68 | + |
| 69 | +### Block buttons |
| 70 | + |
| 71 | +Block buttons stretch to fill the width of the screen or area instead of having a set width. They are often used on mobile layouts. |
| 72 | + |
| 73 | +```html |
| 74 | +<div class="bg-blue-1 p-20 text-slate text-body"> |
| 75 | + <div>COVID-19 vaccination appointments available only for San Francisco Health Network patients.</div> |
| 76 | + <button class="btn btn-block my-20"> |
| 77 | + Check for availability |
| 78 | + </button> |
| 79 | + <div class="text-center"> |
| 80 | + Or call <a href="tel:1234567890" class="text-action">123-456-7890</a> |
| 81 | + </div> |
| 82 | +</div> |
| 83 | +``` |
| 84 | + |
| 85 | +### Icons |
| 86 | + |
| 87 | +Icons can be on the left or right of the text in a button. Do not use more than one icon in a button. |
| 88 | + |
| 89 | +```html |
| 90 | +<div class="flex justify-around items-center gap-16 title-xs"> |
| 91 | + <a href="#" class="btn btn-secondary flex gap-8"> |
| 92 | + <sfgov-icon symbol="arrow-left"></sfgov-icon> |
| 93 | + <span>Previous</span> |
| 94 | + </a> |
| 95 | + <a href="#" class="text-action">1</a> |
| 96 | + <span>...</span> |
| 97 | + <a href="#" class="text-action">8</a> |
| 98 | + <a href="#" class="text-action">9</a> |
| 99 | + <span>10</span> |
| 100 | + <a href="#" class="text-action">11</a> |
| 101 | + <a href="#" class="btn btn-secondary flex gap-8"> |
| 102 | + <span>Next</span> |
| 103 | + <sfgov-icon symbol="arrow-right"></sfgov-icon> |
| 104 | + </a> |
| 105 | +</div> |
| 106 | +``` |
| 107 | + |
| 108 | +Icons should reinforce the meaning of the button’s text. In rare cases, an icon can be used without text. Only do this if the icon is extremely universally understood, such as an arrow or search magnifying glass. [Read more about icons](/foundations/icons/) |
| 109 | + |
| 110 | +## Appearance |
| 111 | + |
| 112 | +<img alt="" src="/static/images/button-specs.png" class="w-full"> |
| 113 | + |
| 114 | +Buttons have: |
| 115 | +* corner radius of 8px |
| 116 | +* 8px padding on the top and bottom |
| 117 | +* 20px padding left and right, but can be variable on block buttons |
| 118 | +* Body Bold text |
| 119 | + |
| 120 | +## Usage |
| 121 | + |
| 122 | +### Alignment |
| 123 | + |
| 124 | +Buttons are typically left aligned with other content, not centered. For exceptions, see <a href="#block-buttons">block buttons</a>. |
| 125 | + |
| 126 | +| <img class="w-1/1" alt="Left aligned button with left aligned text" src="/static/images/alignment-correct.png"> | <img class="w-1/1" alt="Center aligned button with left aligned text" src="/static/images/alignment-incorrect.png"> | |
| 127 | +| ----------- | ----------- | |
| 128 | +| Yes | No | |
| 129 | +| Button is left aligned with other content | Button is centered | |
| 130 | + |
| 131 | +### Arrangement of multiple buttons |
| 132 | + |
| 133 | +For 2 or more button options, place them side by side instead of on top of one another if possible. This reduces the chance of accidentally clicking the wrong one and avoids alignment issues. |
| 134 | + |
| 135 | +| <div class="flex gap-20"><button class="btn btn-secondary">Cancel</button><button class="btn">Continue</button></div> | <div><button class="btn btn-secondary mb-20">Cancel</button><br><button class="btn mb-20">Continue</button></div> | |
| 136 | +| ----------- | ----------- | |
| 137 | +| Yes | No | |
| 138 | +| Choices are side by side | Choices are stacked | |
| 139 | + |
| 140 | +### Writing button text |
| 141 | + |
| 142 | +Button text should ideally be less than 15 characters. A maximum of 25 characters is OK if necessary. |
| 143 | + |
| 144 | +Refer to the [button text library](https://sfgovdt.jira.com/wiki/spaces/SFGOV/pages/3221651460/Button+text+library) for common button uses. |
| 145 | + |
| 146 | +Long button text is less legible, less impactful, and sometimes can even cause wrapping. |
| 147 | + |
| 148 | +| <button class="btn mb-48">Apply now</button> | <button class="btn mb-48">Apply now for your Small Business Grant</button> | |
| 149 | +| ----------- | ----------- | |
| 150 | +| Yes | No | |
| 151 | +| Button text is short | Button text is very long | |
| 152 | + |
| 153 | +| <button class="btn mb-20">Apply now</button> | <button class="btn mb-20">Apply now for your<br>Small Business Grant</button> | |
| 154 | +| ----------- | ----------- | |
| 155 | +| Yes | No | |
| 156 | +| Button text fits on one line | Button text wraps to fit | |
| 157 | + |
| 158 | +## HTML implementation |
| 159 | + |
| 160 | +Buttons styles can be applied to both HTML links (`<a>` elements) and interactive buttons (`<button>`). |
| 161 | + |
| 162 | +### Link buttons |
9 | 163 |
|
10 |
| -### Inline link |
11 | 164 | ```html
|
12 | 165 | <a class="btn" href="#">
|
13 | 166 | This is a link
|
14 | 167 | </a>
|
15 | 168 | ```
|
16 | 169 |
|
17 | 170 | ### Block link
|
| 171 | + |
18 | 172 | ```html
|
19 | 173 | <a class="btn btn-block" href="#">
|
20 | 174 | This is a block link
|
21 | 175 | </a>
|
22 | 176 | ```
|
23 | 177 |
|
24 |
| -## HTML buttons |
25 |
| - |
26 |
| -This is some text about actual styling actual `<button>` elements. |
| 178 | +### HTML buttons |
27 | 179 |
|
28 |
| -### Inline button |
29 | 180 | ```html
|
30 | 181 | <button class="btn">
|
31 | 182 | This is a button
|
32 | 183 | </button>
|
33 | 184 | ```
|
34 | 185 |
|
35 | 186 | ### Block button
|
| 187 | + |
36 | 188 | ```html
|
37 | 189 | <button class="btn btn-block">
|
38 | 190 | This is a block button
|
|
0 commit comments