responsive-utilities.md 9.49 KB
Newer Older
Mark Otto's avatar
Mark Otto committed
1
---
Mark Otto's avatar
Mark Otto committed
2
layout: docs
Mark Otto's avatar
Mark Otto committed
3
title: Responsive utilities
Mark Otto's avatar
Mark Otto committed
4
description: Use responsive display utility classes for showing and hiding content by device, via media query.
5
group: layout
Mark Otto's avatar
Mark Otto committed
6
---
Mark Otto's avatar
Mark Otto committed
7

Mark Otto's avatar
Mark Otto committed
8
For faster mobile-friendly development, use these utility classes for showing and hiding content by device via media query. Also included are utility classes for toggling content when printed.
Mark Otto's avatar
Mark Otto committed
9

Mark Otto's avatar
Mark Otto committed
10
Try to use these on a limited basis and avoid creating entirely different versions of the same site. Instead, use them to complement each device's presentation.
Mark Otto's avatar
Mark Otto committed
11

12
13
14
15
16
## Contents

* Will be replaced with the ToC, excluding the "Contents" header
{:toc}

Mark Otto's avatar
Mark Otto committed
17
##  Available classes
Mark Otto's avatar
Mark Otto committed
18

19
* The `.hidden-*-up` classes hide the element when the viewport is at the given breakpoint or wider. For example, `.hidden-md-up` hides an element on medium, large, and extra-large viewports.
Quy's avatar
Quy committed
20
* The `.hidden-*-down` classes hide the element when the viewport is at the given breakpoint or smaller. For example, `.hidden-md-down` hides an element on extra-small, small, and medium viewports.
21
22
23
* There are no explicit "visible"/"show" responsive utility classes; you make an element visible by simply not hiding it at that breakpoint size.
* You can combine one `.hidden-*-up` class with one `.hidden-*-down` class to show an element only on a given interval of screen sizes. For example, `.hidden-sm-down.hidden-xl-up` shows the element only on medium and large viewports. Using multiple `.hidden-*-up` classes or multiple `.hidden-*-down` classes is redundant and pointless.
* These classes don't attempt to accommodate less common cases where an element's visibility can't be expressed as a single contiguous range of viewport breakpoint sizes; you will instead need to use custom CSS in such cases.
Mark Otto's avatar
Mark Otto committed
24

Mark Otto's avatar
Mark Otto committed
25
26
27
28
29
30
31
<div class="table-responsive">
  <table class="table table-bordered table-striped responsive-utilities">
    <thead>
      <tr>
        <th></th>
        <th>
          Extra small devices
Bass Jobsen's avatar
Bass Jobsen committed
32
          <small>Portrait phones (&lt;544px)</small>
Mark Otto's avatar
Mark Otto committed
33
34
35
        </th>
        <th>
          Small devices
Bass Jobsen's avatar
Bass Jobsen committed
36
          <small>Landscape phones (&ge;544px - &lt;768px)</small>
Mark Otto's avatar
Mark Otto committed
37
38
39
        </th>
        <th>
          Medium devices
Bass Jobsen's avatar
Bass Jobsen committed
40
          <small>Tablets (&ge;768px - &lt;992px)</small>
Mark Otto's avatar
Mark Otto committed
41
42
43
        </th>
        <th>
          Large devices
Bass Jobsen's avatar
Bass Jobsen committed
44
          <small>Desktops (&ge;992px - &lt;1200px)</small>
45
46
47
        </th>
        <th>
          Extra large devices
Bass Jobsen's avatar
Bass Jobsen committed
48
          <small>Desktops (&ge;1200px)</small>
Mark Otto's avatar
Mark Otto committed
49
50
51
52
53
        </th>
      </tr>
    </thead>
    <tbody>
      <tr>
54
        <th scope="row"><code>.hidden-xs-down</code></th>
Mark Otto's avatar
Mark Otto committed
55
        <td class="is-hidden">Hidden</td>
56
57
58
59
60
61
62
        <td class="is-visible">Visible</td>
        <td class="is-visible">Visible</td>
        <td class="is-visible">Visible</td>
        <td class="is-visible">Visible</td>
      </tr>
      <tr>
        <th scope="row"><code>.hidden-sm-down</code></th>
Mark Otto's avatar
Mark Otto committed
63
64
        <td class="is-hidden">Hidden</td>
        <td class="is-hidden">Hidden</td>
65
66
67
        <td class="is-visible">Visible</td>
        <td class="is-visible">Visible</td>
        <td class="is-visible">Visible</td>
Mark Otto's avatar
Mark Otto committed
68
69
      </tr>
      <tr>
70
        <th scope="row"><code>.hidden-md-down</code></th>
Mark Otto's avatar
Mark Otto committed
71
72
73
        <td class="is-hidden">Hidden</td>
        <td class="is-hidden">Hidden</td>
        <td class="is-hidden">Hidden</td>
74
75
        <td class="is-visible">Visible</td>
        <td class="is-visible">Visible</td>
Mark Otto's avatar
Mark Otto committed
76
77
      </tr>
      <tr>
78
79
        <th scope="row"><code>.hidden-lg-down</code></th>
        <td class="is-hidden">Hidden</td>
Mark Otto's avatar
Mark Otto committed
80
81
82
        <td class="is-hidden">Hidden</td>
        <td class="is-hidden">Hidden</td>
        <td class="is-hidden">Hidden</td>
83
        <td class="is-visible">Visible</td>
Mark Otto's avatar
Mark Otto committed
84
85
      </tr>
      <tr>
86
87
88
        <th scope="row"><code>.hidden-xl-down</code></th>
        <td class="is-hidden">Hidden</td>
        <td class="is-hidden">Hidden</td>
Mark Otto's avatar
Mark Otto committed
89
90
91
92
93
        <td class="is-hidden">Hidden</td>
        <td class="is-hidden">Hidden</td>
        <td class="is-hidden">Hidden</td>
      </tr>
      <tr>
94
95
96
97
98
        <th scope="row"><code>.hidden-xs-up</code></th>
        <td class="is-hidden">Hidden</td>
        <td class="is-hidden">Hidden</td>
        <td class="is-hidden">Hidden</td>
        <td class="is-hidden">Hidden</td>
Mark Otto's avatar
Mark Otto committed
99
100
101
        <td class="is-hidden">Hidden</td>
      </tr>
      <tr>
102
        <th scope="row"><code>.hidden-sm-up</code></th>
Mark Otto's avatar
Mark Otto committed
103
104
        <td class="is-visible">Visible</td>
        <td class="is-hidden">Hidden</td>
105
106
107
        <td class="is-hidden">Hidden</td>
        <td class="is-hidden">Hidden</td>
        <td class="is-hidden">Hidden</td>
Mark Otto's avatar
Mark Otto committed
108
109
      </tr>
      <tr>
110
        <th scope="row"><code>.hidden-md-up</code></th>
Mark Otto's avatar
Mark Otto committed
111
112
113
        <td class="is-visible">Visible</td>
        <td class="is-visible">Visible</td>
        <td class="is-hidden">Hidden</td>
114
115
        <td class="is-hidden">Hidden</td>
        <td class="is-hidden">Hidden</td>
Mark Otto's avatar
Mark Otto committed
116
117
      </tr>
      <tr>
118
        <th scope="row"><code>.hidden-lg-up</code></th>
Mark Otto's avatar
Mark Otto committed
119
120
121
122
        <td class="is-visible">Visible</td>
        <td class="is-visible">Visible</td>
        <td class="is-visible">Visible</td>
        <td class="is-hidden">Hidden</td>
123
        <td class="is-hidden">Hidden</td>
Mark Otto's avatar
Mark Otto committed
124
125
      </tr>
      <tr>
126
127
128
129
130
131
        <th scope="row"><code>.hidden-xl-up</code></th>
        <td class="is-visible">Visible</td>
        <td class="is-visible">Visible</td>
        <td class="is-visible">Visible</td>
        <td class="is-visible">Visible</td>
        <td class="is-hidden">Hidden</td>
Mark Otto's avatar
Mark Otto committed
132
133
134
135
136
137
138
139
140
141
142
      </tr>
    </tbody>
  </table>
</div>

<h2 id="responsive-utilities-print">Print classes</h2>
<p>Similar to the regular responsive classes, use these for toggling content for print.</p>
<div class="table-responsive">
  <table class="table table-bordered table-striped responsive-utilities">
    <thead>
      <tr>
143
        <th>Class</th>
Mark Otto's avatar
Mark Otto committed
144
145
146
147
148
149
        <th>Browser</th>
        <th>Print</th>
      </tr>
    </thead>
    <tbody>
      <tr>
150
        <th><code>.visible-print-block</code></th>
Mark Otto's avatar
Mark Otto committed
151
        <td class="is-hidden">Hidden</td>
152
153
154
155
156
157
158
159
160
161
162
        <td class="is-visible">Visible<br>(as <code>display: block</code>)</td>
      </tr>
      <tr>
        <th><code>.visible-print-inline</code></th>
        <td class="is-hidden">Hidden</td>
        <td class="is-visible">Visible<br>(as <code>display: inline</code>)</td>
      </tr>
      <tr>
        <th><code>.visible-print-inline-block</code></th>
        <td class="is-hidden">Hidden</td>
        <td class="is-visible">Visible<br>(as <code>display: inline-block</code>)</td>
Mark Otto's avatar
Mark Otto committed
163
164
165
166
167
168
169
170
171
172
173
      </tr>
      <tr>
        <th><code>.hidden-print</code></th>
        <td class="is-visible">Visible</td>
        <td class="is-hidden">Hidden</td>
      </tr>
    </tbody>
  </table>
</div>

## Test cases
Mark Otto's avatar
Mark Otto committed
174

Mark Otto's avatar
Mark Otto committed
175
Resize your browser or load on different devices to test the responsive utility classes.
Mark Otto's avatar
Mark Otto committed
176

Mark Otto's avatar
Mark Otto committed
177
178
179
Green checkmarks indicate the element **is visible** in your current viewport.

<div class="row responsive-utilities-test visible-on">
180
  <div class="col-6 col-sm-3">
181
182
    <span class="hidden-sm-up visible">&#10004; Visible on extra small</span>
    <span class="hidden-xs-down not-visible">Extra small</span>
Mark Otto's avatar
Mark Otto committed
183
  </div>
184
  <div class="col-6 col-sm-3">
185
186
    <span class="hidden-md-up visible">&#10004; Visible on small or narrower</span>
    <span class="hidden-sm-down not-visible">Small or narrower</span>
Mark Otto's avatar
Mark Otto committed
187
  </div>
188
  <div class="col-6 col-sm-3">
189
190
    <span class="hidden-lg-up visible">&#10004; Visible on medium or narrower</span>
    <span class="hidden-md-down not-visible">Medium or narrower</span>
Mark Otto's avatar
Mark Otto committed
191
  </div>
192
  <div class="col-6 col-sm-3">
193
194
    <span class="hidden-xl-up visible">&#10004; Visible on large or narrower</span>
    <span class="hidden-lg-down not-visible">Large or narrower</span>
Mark Otto's avatar
Mark Otto committed
195
196
  </div>
</div>
Mark Otto's avatar
Mark Otto committed
197
198
199

<hr>

Mark Otto's avatar
Mark Otto committed
200
<div class="row responsive-utilities-test visible-on">
201
  <div class="col-6 col-sm-3">
202
203
    <span class="hidden-xs-down visible">&#10004; Visible on small or wider</span>
    <span class="hidden-sm-up not-visible">Small or wider</span>
Mark Otto's avatar
Mark Otto committed
204
  </div>
205
  <div class="col-6 col-sm-3">
206
207
    <span class="hidden-sm-down visible">&#10004; Visible on medium or wider</span>
    <span class="hidden-md-up not-visible">Medium or wider</span>
Mark Otto's avatar
Mark Otto committed
208
  </div>
209
  <div class="col-6 col-sm-3">
210
211
    <span class="hidden-md-down visible">&#10004; Visible on large or wider</span>
    <span class="hidden-lg-up not-visible">Large or wider</span>
Mark Otto's avatar
Mark Otto committed
212
  </div>
213
  <div class="col-6 col-sm-3">
214
215
    <span class="hidden-lg-down visible">&#10004; Visible on extra large</span>
    <span class="hidden-xl-up not-visible">Extra large</span>
Mark Otto's avatar
Mark Otto committed
216
217
  </div>
</div>
Mark Otto's avatar
Mark Otto committed
218
219
220

<hr>

221
<div class="row responsive-utilities-test visible-on">
222
  <div class="col-6 col-sm-4">
223
224
    <span class="hidden-sm-up visible">&#10004; Your viewport is exactly extra small</span>
    <span class="hidden-xs-down not-visible">Your viewport is NOT exactly extra small</span>
Mark Otto's avatar
Mark Otto committed
225
  </div>
226
  <div class="col-6 col-sm-4">
227
228
    <span class="hidden-xs-down hidden-md-up visible">&#10004; Your viewport is exactly small</span>
    <span class="hidden-sm-only not-visible">Your viewport is NOT exactly small</span>
Mark Otto's avatar
Mark Otto committed
229
  </div>
230
  <div class="col-6 col-sm-4">
231
232
    <span class="hidden-sm-down hidden-lg-up visible">&#10004; Your viewport is exactly medium</span>
    <span class="hidden-md-only not-visible">Your viewport is NOT exactly medium</span>
Mark Otto's avatar
Mark Otto committed
233
  </div>
Mark Otto's avatar
Mark Otto committed
234
235
236
  </div>

<div class="row responsive-utilities-test visible-on">
237
  <div class="col-6 col-sm-4">
238
239
    <span class="hidden-md-down hidden-xl-up visible">&#10004; Your viewport is exactly large</span>
    <span class="hidden-lg-only not-visible">Your viewport is NOT exactly large</span>
Mark Otto's avatar
Mark Otto committed
240
  </div>
241
  <div class="col-6 col-sm-4">
242
243
    <span class="hidden-lg-down visible">&#10004; Your viewport is exactly extra large</span>
    <span class="hidden-xl-only not-visible">Your viewport is NOT exactly extra large</span>
Mark Otto's avatar
Mark Otto committed
244
245
  </div>
</div>