Utility

A collection of useful utility classes to style your content.

Container

Add the .uk-container class to a block element to give it a max-width and wrap the main content of your website. For large screens it applies a different max-width.


Centering

To center the container, use the .uk-container-center class. For any other block element, you additionally need to apply a width.

Example

Centered block element

Markup

<div class="uk-width-medium-1-2 uk-container-center">...</div>

Clearing and floating

Floating is fundamental for creating all kinds of layouts. But floats need to be cleared or in the worst case, you might end up with a scrambled site. The following classes will help you to setup basic layouts.

Class Description
.uk-float-left Float the element to the left.
.uk-float-right Float the element to the right.
.uk-clearfix Add this class to a parent container to clear floats.

Markup

<div class="uk-clearfix">
    <div class="uk-float-right">...</div>
    <div class="uk-float-left">...</div>
</div>

New block formatting context

Instead of using the .uk-clearfix class, you can create a new block formatting context to clear floats. Depending on your setup, you can evaluate which method is more suited.

Class Description
.uk-nbfc Sets overflow to hidden to create a new block formatting context.
.uk-nbfc-alt Sets display to table-cell to create a new block formatting context.

Alignment of images and objects

Align images or other elements with spacing between the text and the element.

Class Description
.uk-align-left Floats the element to the left and creates right and bottom margin.
.uk-align-right Floats the element to the right and creates left and bottom margin.
.uk-align-medium-left Only affects device widths of 768px and higher.
.uk-align-medium-right Only affects device widths of 768px and higher.
.uk-align-center Centers the element and creates bottom margin.

Example

Image aligned to the rightLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Markup

<p class="uk-clearfix">
    <img class="uk-align-medium-right" src="" alt="">
    ...
</p>

Vertical alignment

To align objects vertically, you need to create a parent container to which the object itself will be aligned.

Class Description
.uk-vertical-align Add this class to the parent container. This container needs a specific height.
.uk-vertical-align-middle Add this class to the child element to center your content.
.uk-vertical-align-bottom Add this class to the child element to align your content to the bottom.
.uk-height-1-1 This helper class applies a height of 100%.

Example

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

Markup

<div class="uk-vertical-align">
    <div class="uk-vertical-align-middle">
    ...
    </div>
</div>
<div class="uk-vertical-align">
    <div class="uk-vertical-align-bottom">
    ...
    </div>
</div>

NOTE The object you align needs to have a width or max-width that is smaller than its parent container.

Center the entire page

The .uk-height-1-1 class comes in handy, if you want to extend the <html> and <body> elements to the full height of the page. This can be very useful when creating error pages.

Markup

<html class="uk-height-1-1">
    ...
    <body class="uk-height-1-1">
        <div class="uk-vertical-align">
            <div class="uk-vertical-align-middle">...</div>
        </div>
    </body>
</html>

Center horizontally

To center your content horizontally as well, add the .uk-text-center class to the parent and the .uk-container-center class to the child element. This is necessary because of the responsive behavior.


Viewport height

To create a container that fills the height of the entire viewport, for example for fullscreen image or video teasers, just add the .uk-height-viewport class.


Position elements

UIkit provides a number of classes to position your content without having to add your own CSS.

Class Description
.uk-position-top Positions an element absolute at the top.
.uk-position-top-left Positions an element absolute at the top left.
.uk-position-top-right Positions an element absolute at the top right.
.uk-position-bottom Positions an element absolute at the bottom.
.uk-position-bottom-left Positions an element absolute at the bottom left.
.uk-position-bottom-right Positions an element absolute at the bottom right.
.uk-position-cover Adds absolute positioning to an element and stretches it to cover the entire parent.
.uk-position-relative Adds relative positioning to an element.
.uk-position-z-index Adds a z-index of 1 to an element.

Responsive objects

Images in UIkit adapt to the width of their parent container by default. If you want to apply the responsive behavior to media elements, like a video object, just add one of the following classes.

Class Description
.uk-responsive-width Adjusts the object's width according to its parent's width, keeping the original aspect ratio.
.uk-responsive-height Adjusts the object's height according to its parent's height, keeping the original aspect ratio.

NOTE The .uk-responsive-width class can also be applied to an Iframe, provided its width and height attributes are set.

Example width

Example height

Markup

<video controls class="uk-responsive-width"></video>

<img class="uk-responsive-height" src="" alt="">

Inline SVG

SVGs or Scaleable Vector Graphics are really handy, for example to display a logo that remains crisp when scaling or that is animated. To be able to control your SVG via CSS, just add the data-uk-svg attribute to the image tag. This will turn your image into an inline SVG including all attributes, like IDs, classes, width and height which you can now easily target using CSS.

Markup

<img src="my-image.svg" data-uk-svg>

Margin

Add one of the following classes to add spacing to block elements.

Class Description
.uk-margin Adds the same top and bottom margins as a paragraph usually has.
.uk-margin-top Adds top margin.
.uk-margin-bottom Adds bottom margin.
.uk-margin-left Adds left margin.
.uk-margin-right Adds right margin.

Larger margin

Add one of the following classes to add larger spacing to block elements.

Class Description
.uk-margin-large Adds large top and bottom margin.
.uk-margin-large-top Adds large top margin.
.uk-margin-large-bottom Adds large bottom margin.
.uk-margin-large-left Adds large left margin.
.uk-margin-large-right Adds large right margin.

Smaller margin

Add one of the following classes to add smaller spacing to block elements.

Class Description
.uk-margin-small Adds small top and bottom margin.
.uk-margin-small-top Adds small top margin.
.uk-margin-small-bottom Adds small bottom margin.
.uk-margin-small-left Adds small left margin.
.uk-margin-small-right Adds small right margin.

Remove margin

Add one of the following classes to remove margin from block elements.

Class Description
.uk-margin-remove Removes all margins.
.uk-margin-top-remove Removes top margin.
.uk-margin-bottom-remove Removes bottom margin.

Auto margin

To add spacing to stacking elements, for example inline elements that wrap on smaller vieports, just add the data-uk-margin attribute to their parent container. It will automatically add the .uk-margin-small-top to the lower element.

Example

Markup

<p data-uk-margin>
    <button class="uk-button">...</button>
    <button class="uk-button">...</button>
</p>

NOTE By default, the data attribute adds the .uk-margin-small-top class to stacking elements. To apply a bigger margin, just add the {cls:'uk-margin-top'} option.


Padding

To remove the padding from a block element, add one of the following classes.

Class Description
.uk-padding-remove Removes all padding.
.uk-padding-top-remove Removes top padding.
.uk-padding-bottom-remove Removes bottom padding.
.uk-padding-vertical-remove Removes top and bottom padding.

Border radius

To add rounded corners to an element, like an image, just add the .uk-border-rounded. To a apply a circled shape, add the .uk-border-circle class.

Example

Border rounded Border circle

<img class="uk-border-rounded" src="" alt="">
<img class="uk-border-circle" src="" alt="">

Heading large

To increase the font size of your headings on tablets and desktops, just add the .uk-heading-large class.

Example

Heading

Markup

<h1 class="uk-heading-large">...<h1>

If a link should not have the default link color, just add the .uk-link-muted class to the anchor element or the parent element.

Example

Markup

<a class="uk-link-muted">...<a>

<h1 class="uk-link-muted"><a>...<a><h1>

<ul class="uk-link-muted">
    <li><a>...<a></li>
    <li><a>...<a></li>
    <li><a>...<a></li>
</ul>

Scrollable preformatted text

Add the .uk-scrollable-text class to set a max-height and provide a vertical scrollbar. This is very useful for preformatted text, if you don't want your code blocks to take too much space.

Example

<!-- This is sample code to demonstrate preformatted text with a scrollbar. -->

<div class="uk-grid">
    <div class="uk-width-medium-1-2">
        <div class="uk-panel uk-panel-box uk-text-left">...</div>
    </div>
    <div class="uk-width-medium-1-2">
        <div class="uk-panel uk-panel-box uk-text-right">...</div>
    </div>
</div>
<div class="uk-grid">
    <div class="uk-width-medium-1-2">
        <div class="uk-panel uk-panel-box uk-text-center">...</div>
    </div>
    <div class="uk-width-medium-1-2">
        <div class="uk-panel uk-panel-box uk-text-justify">...</div>
    </div>
</div>

<div class="uk-grid">
    <div class="uk-width-medium-1-2">
        <div class="uk-panel uk-panel-box uk-text-break">...</div>
    </div>
    <div class="uk-width-medium-1-2">
        <div class="uk-panel uk-panel-box"><p class="uk-margin-remove uk-text-truncate">...</p></div>
    </div>
</div>

Scrollable box

Add the .uk-scrollable-box class to create a panel-like box which has a max-height and provides a vertical scrollbar. It can contain any kind of content.

Example

Markup

<div class="uk-scrollable-box">
    <ul class="uk-list">
        <li><label><input type="checkbox">...</label></li>
        <li><label><input type="checkbox">...</label></li>
    </ul>
</div>

Overflow container

To create a container that provides a horizontal scrollbar whenever the elements inside it are wider than the container itself, just add the .uk-overflow-container class to a <div> element. This comes in useful when having to handle tables on a responsive website, which at some point would just get too big.

Example

Table Heading Table Heading Table Heading Table Heading Table Heading Table Heading Table Heading Table Heading
Table Footer Table Footer Table Footer Table Footer Table Footer Table Footer Table Footer Table Footer
Table Data Table Data Table Data Table Data Table Data Table Data Table Data Table Data
Table Data Table Data Table Data Table Data Table Data Table Data Table Data Table Data
Table Data Table Data Table Data Table Data Table Data Table Data Table Data Table Data

Markup

<div class="uk-overflow-container">...</div>

Display utilities

Add one of these classes to change the display properties of an element.

Class Description
.uk-display-block Forces the element to behave like a block element.
.uk-display-inline Forces the element to behave like an inline element.
.uk-display-inline-block Forces the element to behave like an inline-block element.

Visibility utilities

Class Description
.uk-hidden Hides the element on any device.
.uk-hidden-touch Hides the element on touch devices.
.uk-hidden-notouch Hides the element on non-touch devices.
.uk-invisible Hides the element without removing it from the flow.
.uk-visible-hover Displays hidden content on hover using display: block. Add this class to the parent element.
.uk-visible-hover-inline Displays hidden content on hover using display: inline-block. Add this class to the parent element.

Example

Hover me...
Bazinga!

Markup

<div class="uk-visible-hover">
    <div class="uk-hidden">...</div>
</div>

Responsive visibility

You can show or hide content on specific viewport widths. Breakpoints are set through variables and can easily be modified. Since the line between different device sizes keeps blurring, class names are kept general and do not refer to particular devices.

Class Small
(Phones)
up to 767
Medium
(Tablets)
768 to 959
Large
(Desktops)
960 and larger
.uk-visible-small Visible Hidden Hidden
.uk-visible-medium Hidden Visible Hidden
.uk-visible-large Hidden Hidden Visible
.uk-hidden-small Hidden Visible Visible
.uk-hidden-medium Visible Hidden Visible
.uk-hidden-large Visible Visible Hidden