Written by Julian. Posted in UIKit
Create a fully responsive, fluid and nestable grid layout.
The grid system of UIkit follows the mobile-first approach and accomodates up to 10 grid columns. It uses units with predefined classes inside each grid, which define the column width. It is also possible to combine the grid with classes from the Flex component, although it works only in modern browsers.
Usage
To create the grid container, add the .uk-grid
class to a parent element. Add one of the .uk-width-*
classes to child elements to determine, how the units shall be sized. The grid supports 1, 2, 3, 4, 5, 6 and 10 unit divisions. This table gives you an overview of the uk-width-*
classes that can be applied to units.
Class |
Description |
.uk-width-1-1 |
Fills 100% of the available width. |
.uk-width-1-2 |
Divides the grid into halves. |
.uk-width-1-3 to .uk-width-2-3 |
Divides the grid into thirds. |
.uk-width-1-4 to .uk-width-3-4 |
Divides the grid into fourths. |
.uk-width-1-5 to .uk-width-4-5 |
Divides the grid into fifths. |
.uk-width-1-6 to .uk-width-5-6 |
Divides the grid into sixths. |
.uk-width-1-10 to .uk-width-9-10 |
Divides the grid into tenths. |
We built an intentional redundancy into each set of unit classes, so that for instance the .uk-width-5-10
class will work just as well as .uk-width-1-2
.
Example
Take a closer look at the following grid example, which gives you a great overwiew of all basic .uk-width-*
classes.
NOTE The grid has no style related CSS. In our example we used panels from the Panel component.
Markup
Here is a simple code example of how the default grid with 2 columns would look like:
<div class="uk-grid">
<div class="uk-width-1-2">...</div>
<div class="uk-width-1-2">...</div>
</div>
UIkit provides a number of very useful responsive widths classes. Basically they work just like the usual width classes, except they are prefixed, so that they only come to effect at certain breakpoints. These classes can be combined with the visibility classes from the Utility component. This is great to adjust your layout and content for different device sizes.
Class |
Description |
.uk-width-* |
Affects all device widths, grid columns stay side by side. |
.uk-width-small-* |
Affects device widths of 480px and higher. Grid columns will stack on smaller sizes. |
.uk-width-medium-* |
Affects device widths of 768px and higher. Grid columns will stack on smaller sizes. |
.uk-width-large-* |
Affects device widths of 960px and higher. Grid columns will stack on smaller sizes. |
IMPORTANT To create a margin between stacking grid columns, just add the data-uk-grid-margin
attribute.
Example
.uk-width-medium-1-2
.uk-width-large-1-3
.uk-hidden-medium
.uk-width-large-1-3
.uk-width-medium-1-2
.uk-width-large-1-3
.uk-width-1-2
.uk-width-medium-1-3
.uk-hidden-small
.uk-width-medium-1-3
.uk-width-1-2
.uk-width-medium-1-3
.uk-width-1-1 .uk-visible-small
.uk-width-medium-1-1 .uk-visible-medium
.uk-width-large-1-1 .uk-visible-large
Grids automatically create a horizontal gutter between columns and a vertical one between two succeeding grids. By default, the grid gutter is wider on large screens.
Example
Large gutter
To apply a large gutter between grid columns, just add the .uk-grid-large
class.
Example
Medium gutter
To apply a medium sized gutter between grid columns, just add the .uk-grid-medium
class.
Example
Small gutter
To apply a smaller gutter between grid columns, just add the .uk-grid-small
class.
Example
Collapse gutter
To remove the gutter entirely, just add the .uk-grid-collapse
class.
Example
You can easily extend your grid layout with nested grids.
Example
Markup
<div class="uk-grid">
<div class="uk-width-1-2">...</div>
<div class="uk-width-1-2">
<div class="uk-grid">
<div class="uk-width-1-2">...</div>
<div class="uk-width-1-2">...</div>
</div>
</div>
</div>
Add the .uk-container-center
class from the Utility component to center a grid column.
Example
.uk-container-center
Add the .uk-grid-divider
class to separate grid columns with lines. To separate grids with a horizontal line, just add the class to a <hr>
or <div>
element.
Example
Markup
<div class="uk-grid uk-grid-divider">...</div>
<hr class="uk-grid-divider">
<div class="uk-grid uk-grid-divider">...</div>
NOTE The horizontal divider can not be applied to grids with any of the uk-push-*
or uk-pull-*
classes.
You can change the display order of the columns to keep a specific column order in the source code. Add one of the .uk-push-*
classes to move the column to the right and add one of the .uk-pull-*
classes to move a column to the left. This allows you for example to flip the columns' display order for wider viewports. The classes can also be used to offset columns, creating additional space between them.
Source ordering is useful for SEO and responsive design, because in narrow viewports the grid will be displayed according to the source order of the markup.
NOTE This feature only works in combination with one of the .uk-width-medium-*
classes.
Example
.uk-width-medium-1-2 .uk-push-1-2
.uk-width-medium-1-2 .uk-pull-1-2
.uk-width-medium-2-5 .uk-push-3-5
.uk-width-medium-2-5 .uk-pull-2-5
Markup
<div class="uk-grid">
<div class="uk-width-medium-1-2 uk-push-1-2">...</div>
<div class="uk-width-medium-1-2 uk-pull-1-2">...</div>
</div>
The Grid component uses Flexbox, so the height of grid columns is matched automatically. To achieve the same effect in older browsers that don't support Flexbox, just add the data-uk-grid-match
attribute to your grid. If your grid wraps into multiple rows, only grid columns within the same row are matched. To match grid columns accross all rows just use data-uk-grid-match="{row: false}"
.
Example
Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.
Markup
<div class="uk-grid" data-uk-grid-match>...</div>
NOTE If grid columns extend to a width of 100%, their heights will no longer be matched. This makes sense, for example, if they stack vertically in narrower viewports.
Match height of panels
If you want to match the heights of panels in a grid, just add the .uk-grid-match
class. When using the data attribute, you need to add the {target:'.uk-panel'}
selector.
Example
Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.
Markup
<div class="uk-grid uk-grid-match" data-uk-grid-match="{target:'.uk-panel'}">
<div class="uk-width-medium-1-3">
<div class="uk-panel">...</div>
</div>
</div>
You can also create a grid with as many columns as you want, which automatically break into the next line. Just add the data-uk-grid-margin
attribute to create a margin between the grid rows. Typically this layout is built using a <ul>
element.
Example
NOTE You can also apply a custom width to your grid columns. Just add the .uk-width
class and use an inline style to define the width. This example uses fixed pixel values for the widths as you would do with images.
-
Box
-
Box
-
Box
-
Box
-
Box
-
Box
-
Box
-
Box
Markup
<ul class="uk-grid" data-uk-grid-margin>
<li class="uk-width-medium-1-5">...</li>
<li class="uk-width-medium-3-10">...</li>
<li class="uk-width" style="width: 100px;">...</li>
<li class="uk-width" style="width: 150px;">...</li>
</ul>
To create a grid whose child elements' widths are evenly split, you don't have to apply the same class to each list item within the grid. Just add one of the .uk-grid-width-*
classes to the grid itself.
Class |
Description |
.uk-grid-width-1-2 |
Divides the grid into halves. |
.uk-grid-width-1-3 |
Divides the grid into thirds. |
.uk-grid-width-1-4 |
Divides the grid into fourths. |
.uk-grid-width-1-5 |
Divides the grid into fifths. |
.uk-grid-width-1-6 |
Divides the grid into sixths. |
.uk-grid-width-1-10 |
Divides the grid into tenths. |
Example
Markup
<ul class="uk-grid uk-grid-width-1-5">
<li>...</li>
<li>...</li>
</ul>
Responsive width
UIkit also provides responsive grid width classes. You can apply these to maintain evenly sized grid columns, regardless of the device width.
Class |
Description |
.uk-grid-width-* |
Affects all device widths. |
.uk-grid-width-small-* |
Affects device widths of 480px and higher. |
.uk-grid-width-medium-* |
Affects device widths of 768px and higher. |
.uk-grid-width-large-* |
Affects device widths of 960px and higher. |
.uk-grid-width-xlarge-* |
Affects device widths of 1220px and higher. |
Example
Markup
<ul class="uk-grid uk-grid-width-1-2 uk-grid-width-medium-1-3 uk-grid-width-large-1-5">
<li>...</li>
<li>...</li>
</ul>
Print
Email
Written by Julian. Posted in UIKit
Create layout boxes with different styles.
UIkit uses panels to outline certain sections of your content, which can be styled differently. Typically, panels are arranged in grid columns from the Grid component.
The Panel component consists of the panel itself, the panel title and a panel badge. To prevent redundant white space, top and bottom margins are removed from the panel's content.
Class |
Description |
.uk-panel |
Add this class to a <div> element to define the Panel component. |
.uk-panel-title |
Add this class to a heading to create the panel title. |
.uk-panel-badge |
Add this class to a <div> element to create a panel badge. The easiest way to style your badge, is by adding the modifier classes from the Badge component. |
Example
Hot
Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
NOTE By default, a panel is blank and has no styling. That is why it is important to add a modifier class, which gives the panel some styling. In our examples we used the .uk-panel-box
class.
Markup
<div class="uk-panel">
<div class="uk-panel-badge uk-badge">...</div>
<h3 class="uk-panel-title">...</h3>
...
</div>
Panels in a grid
This is a short example of how to use panels with the Grid component. Both panels are using the .uk-width-medium-1-2
class.
Example
Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor.
Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor.
Markup
<div class="uk-grid">
<div class="uk-width-medium-1-2">
<div class="uk-panel">...</div>
</div>
<div class="uk-width-medium-1-2">
<div class="uk-panel">...</div>
</div>
</div>
Modifier classes are necessary to add a specific style to panels. UIkit includes a number of panel modifiers and you also have the possibility to create your own.
Panel box
Add the .uk-panel-box
class to create a visually styled box. This is the default panel modifier.
Example
Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit. .uk-panel-box
Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit. .uk-panel-box
Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit. .uk-panel-box
Markup
<div class="uk-panel uk-panel-box">...</div>
NOTE To create a hover effect on the panel, just add the .uk-panel-box-hover
class. This comes in handy when working with anchors.
Panel box primary
Add the .uk-panel-box-primary
class to modify the box panel and emphasize it with a different color.
Example
Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit. .uk-panel-box-primary
Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit. .uk-panel-box-primary
Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit. .uk-panel-box-primary
Markup
<div class="uk-panel uk-panel-box uk-panel-box-primary">...</div>
NOTE To create a hover effect on the panel, just add the .uk-panel-box-primary-hover
class. This comes in handy when working with anchors.
Panel box secondary
Add the .uk-panel-box-secondary
class to modify the box panel and give it a light background.
Example
Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit. .uk-panel-box-secondary
Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit. .uk-panel-box-secondary
Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit. .uk-panel-box-secondary
Markup
<div class="uk-panel uk-panel-box uk-panel-box-secondary">...</div>
NOTE To create a hover effect on the panel, just add the .uk-panel-box-secondary-hover
class. This comes in handy when working with anchors.
Panel hover
Add the .uk-panel-hover
class to add a hover effect to the panel. This comes in handy when using the panel as an anchor.
Example
Markup
<a class="uk-panel uk-panel-hover" href="">...</a>
Panel header
Add the .uk-panel-header
class to separate the panel title and content with a horizontal line.
Example
Markup
<div class="uk-panel uk-panel-header">...</div>
Panel space
Add the .uk-panel-space
class to increase the spacing around the panel content.
Example
Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit. .uk-panel-space
Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit. .uk-panel-space
Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit. .uk-panel-space
Markup
<div class="uk-panel uk-panel-space">...</div>
Panel divider
Add the .uk-panel-divider
class to separate vertically stacked panels with lines.
Example
Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit. .uk-panel-divider
Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit. .uk-panel-divider
Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit. .uk-panel-divider
Markup
<div class="uk-grid">
<div class="uk-width-medium-1-2">
<div class="uk-panel uk-panel-divider">...</div>
<div class="uk-panel uk-panel-divider">...</div>
<div class="uk-panel uk-panel-divider">...</div>
</div>
</div>
NOTE Use the .uk-grid-divider
class from the Grid component to separate grid columns.
To display an image inside a panel box that is attached to the border of the panel without any spacing, just add the .uk-panel-teaser
class to a <div>
element inside the panel.
Example
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Markup
<div class="uk-panel uk-panel-box">
<div class="uk-panel-teaser">
<img src="" alt="">
</div>
</div>
Easily apply an icon from our Icon component to your panel by adding one of the .uk-icon-*
classes to an <i>
or <span>
element inside the panel title.
Example
Panel
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Panel
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Panel
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Markup
<div class="uk-panel">
<h3 class="uk-panel-title"><i class="uk-icon-*"></i>...</h3>
</div>
Print
Email