Visibility

Visibility classes let you show or hide elements based on screen size or device orientation. You can use visibility classes to control which elements users see depending on their browsing environment.

Show by Screen Size

In this example, we use the show visibility classes to show certain strings of text based on the device on which users view a page. If their browser meets the class's conditions, the element will be shown. If not, it will be hidden.

EXAMPLE

Show Code

<div class="row">
    <strong class="columns show-for-small-only">This text is shown only on a small screen.</strong>

    <strong class="columns show-for-medium-up">This text is shown on medium screens and up.</strong>

    <strong class="columns show-for-medium-only">This text is shown only on a medium screen.</strong>

    <strong class="columns show-for-large-up">This text is shown on large screens and up.</strong>

    <strong class="columns show-for-large-only">This text is shown only on a large screen.</strong>

    <strong class="columns show-for-xlarge-up">This text is shown on xlarge screens and up.</strong>

    <strong class="columns show-for-xlarge-only">This text is shown only on an xlarge screen.</strong>
</div>
This text is shown only on a small screen. This text is shown on medium screens and up. This text is shown only on a medium screen. This text is shown on large screens and up. This text is shown only on a large screen. This text is shown on xlarge screens and up. This text is shown only on an xlarge screen.

Hide by Screen Size

This example shows the opposite - using the hide visibility classes to state which elements should disappear based on your device's screen size or orientation. Users will see elements on every browser except those that meet these conditions.

EXAMPLE

Show Code

<div class="row">
    <strong class="columns hide-for-small-only">You are <em>not</em> on a small screen.</strong>

    <strong class="columns hide-for-medium-up">You are <em>not</em> on a medium, large, or xlarge screen.</strong>

    <strong class="columns hide-for-medium-only">You are <em>not</em> on a medium screen.</strong>

    <strong class="columns hide-for-large-up">You are <em>not</em> on a large, or xlarge screen.</strong>

    <strong class="columns hide-for-large-only">You are <em>not</em> on a large screen.</strong>

    <strong class="columns hide-for-xlarge-up">You are <em>not</em> on an xlarge screen and up.</strong>

    <strong class="columns hide-for-xlarge-only">You are <em>not</em> on an xlarge screen.</strong>
</div>
You are not on a small screen. You are not on a medium, large, or xlarge screen. You are not on a medium screen. You are not on a large, or xlarge screen. You are not on a large screen. You are not on an xlarge screen and up. You are not on an xlarge screen.

Orientation Detection

This straightforward example shows how two strings of text determine whether or not an element is visible in different orientations. This will change on mobile devices when you rotate the device. On desktop, the orientation is almost always reported as landscape.

EXAMPLE

Show Code

<div class="row">
    <strong class="columns show-for-landscape">You are in landscape orientation.</strong>

    <strong class="columns show-for-portrait">You are in portrait orientation.</strong>
</div>
You are in landscape orientation. You are in portrait orientation.

Touch Detection

There are also visibility classes to hide or show content based on whether a device supports touch (as determined by Modernizr).

EXAMPLE

Show Code

<div class="row">
    <strong class="columns show-for-touch">You are on a touch-enabled device.</strong>

    <strong class="columns hide-for-touch">You are not on a touch-enabled device.</strong>
</div>
You are on a touch-enabled device. You are not on a touch-enabled device.

Accessibility - Screen Readers

Adding display: none to an element will prevent screen readers from reading it. However, there are techniques to hide content while still making it readable by screen readers.

Show for Screen Readers Only

To visually hide content, while still allowing assistive technology to read it, add the class .show-for-sr.

EXAMPLE

Show Code

<strong class="show-for-sr">This text can only be read by a screen reader.</strong>
<strong>There is a line of text above this one, you just can&apos;t see it.</strong>
This text can only be read by a screen reader. There is a line of text above this one, you just can't see it.

Hide for Screen Readers Only

To hide text from assistive technology, while still keeping it visible, add the attribute aria-hidden="true". This doesn't affect how the element looks, but screen readers will skip over it.

EXAMPLE

Show Code

<strong aria-hidden="true">This text can be seen, but wont be read by a screen reader.</strong>

Responsive Visibility - Hiding

Finally, if you want to hide some content but still make it accessible for screen readers, use the hidden visibility classes. Do not confuse these classes with hide visibility classes. Use these classes in conjunction with the hide and show visibility classes to control complex layouts while offering accessibility for those using screen readers.

EXAMPLE

Show Code

<div class="row">
    <strong class="small-12 columns hidden-for-small-only">You are <em>not</em> on a small screen.</strong>

    <strong class="small-12 columns hidden-for-medium-up">You are <em>not</em> on a medium, large, or xlarge screen.</strong>

    <strong class="small-12 columns hidden-for-medium-only">You are <em>not</em> on a medium screen.</strong>

    <strong class="small-12 columns hidden-for-large-up">You are <em>not</em> on a large, or xlarge screen.</strong>

    <strong class="small-12 columns hidden-for-large-only">You are <em>not</em> on a large screen.</strong>

    <strong class="small-12 columns hidden-for-xlarge-up">You are <em>not</em> on an xlarge screen and up.</strong>

    <strong class="small-12 columns hidden-for-xlarge-only">You are <em>not</em> on an xlarge screen.</strong>
</div>
You are not on a small screen. You are not on a medium, large, or xlarge screen. You are not on a medium screen. You are not on a large, or xlarge screen. You are not on a large screen. You are not on an xlarge screen and up. You are not on an xlarge screen.

Responsive Visibility - Showing

To reverse the rules defined by hidden, use the visible visibility classes.

EXAMPLE

Show Code

<div class="row">
    <strong class="small-12 columns visible-for-small-only">This text is shown only on a small screen.</strong>

    <strong class="small-12 columns visible-for-medium-up">This text is shown on medium screens and up.</strong>

    <strong class="small-12 columns visible-for-medium-only">This text is shown only on a medium screen.</strong>

    <strong class="small-12 columns visible-for-large-up">This text is shown on large screens and up.</strong>

    <strong class="small-12 columns visible-for-large-only">This text is shown only on a large screen.</strong>

    <strong class="small-12 columns visible-for-xlarge-up">This text is shown on xlarge screens and up.</strong>

    <strong class="small-12 columns visible-for-xlarge-only">This text is shown only on an xlarge screen.</strong>
</div>
This text is shown only on a small screen. This text is shown on medium screens and up. This text is shown only on a medium screen. This text is shown on large screens and up. This text is shown only on a large screen. This text is shown on xlarge screens and up. This text is shown only on an xlarge screen.

Print Visibility

The UITK includes a couple of simple classes you can use to control elements printing, or not printing. Simply attach .show-for-print to an element to show when printing, .print-only for showing the element only when printing, and .hide-for-print to hide something when printing.

Important: Grid classes can be used to style print media, just be sure to use the .small-# grid classes. This should already be mostly complete for you because of the MOBILE-FIRST implementation of the grid throughout your code.

Available classes:

  • .show-for-print and .print-only = (Visible for printing)
  • .hide-for-print and .hide-on-print = (Hidden while printing)
EXAMPLE

Show Code

<div class="row">
    <strong class="columns text-center show-for-print">This will only display in print media.</strong>

    <strong class="columns text-center hide-for-print">This will <i>NOT</i> display in print media.</strong>

    <strong class="columns text-center print-only">This will only display in print media.</strong>

    <strong class="columns text-center hide-on-print">This will <i>NOT</i> display in print media.</strong>
</div>
This will only display in print media. This will NOT display in print media. This will only display in print media. This will NOT display in print media.