Width

Define the width of elements for different viewport sizes.

UIkit’s Width component is often used in combination with grids to split the content into responsive columns. You can apply fractions, automatic width or expand units to fill the remaining space and combine these modes.

Usage

Add one of the .uk-width-* classes to an element to determine its size. Typically, you would use a grid from the Grid component and its child elements to create the units.

ClassDescription
.uk-width-1-1Fills 100% of the available width.
.uk-width-1-2The element takes up halves of its parent container.
.uk-width-1-3, .uk-width-2-3The element takes up thirds of its parent container.
.uk-width-1-4, .uk-width-3-4The element takes up fourths of its parent container.
.uk-width-1-5, .uk-width-2-5,
.uk-width-3-5, .uk-width-4-5
The element takes up fifths of its parent container.
.uk-width-1-6, .uk-width-5-6The element takes up sixths of its parent container.

Note We remove redundancy into each set of unit classes, so that for instance instead of .uk-width-3-6 you should use .uk-width-1-2.

<div uk-grid>
  <div class="uk-width-1-2"></div>
  <div class="uk-width-1-2"></div>
</div>
Copy to clipboard
  • 1-3
    1-3
    1-3
    1-2
    1-2
    1-4
    3-4
  • <div class="uk-text-center" uk-grid>
      <div class="uk-width-1-3">
        <div class="uk-card uk-card-body uk-card-default">1-3</div>
      </div>
      <div class="uk-width-1-3">
        <div class="uk-card uk-card-body uk-card-default">1-3</div>
      </div>
      <div class="uk-width-1-3">
        <div class="uk-card uk-card-body uk-card-default">1-3</div>
      </div>
    </div>
    
    <div class="uk-text-center" uk-grid>
      <div class="uk-width-1-2">
        <div class="uk-card uk-card-body uk-card-default">1-2</div>
      </div>
      <div class="uk-width-1-2">
        <div class="uk-card uk-card-body uk-card-default">1-2</div>
      </div>
    </div>
    
    <div class="uk-text-center" uk-grid>
      <div class="uk-width-1-4">
        <div class="uk-card uk-card-body uk-card-default">1-4</div>
      </div>
      <div class="uk-width-3-4">
        <div class="uk-card uk-card-body uk-card-default">3-4</div>
      </div>
    </div>

Auto and expand

The Width component provides additional modifiers to give you more flexibility in the distribution of items.

ClassDescription
.uk-width-autoThe item expands only to the width of its own content.
.uk-width-expandThe item expands to fill up the remaining space of the grid container.
<div uk-grid>
  <div class="uk-width-auto"></div>
  <div class="uk-width-expand"></div>
</div>
Copy to clipboard
  • Auto
    Expand
  • <div class="uk-text-center" uk-grid>
      <div class="uk-width-auto">
        <div class="uk-card uk-card-body uk-card-default">Auto</div>
      </div>
      <div class="uk-width-expand">
        <div class="uk-card uk-card-body uk-card-default">Expand</div>
      </div>
    </div>

Equal child widths

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-child-width-* classes to the grid itself.

ClassDescription
.uk-child-width-1-2All elements take up half of their parent container.
.uk-child-width-1-3All elements take up a third of their parent container.
.uk-child-width-1-4All elements take up a fourth of their parent container.
.uk-child-width-1-5All elements take up a fifth of their parent container.
.uk-child-width-1-6All elements take up a sixth of their parent container.
.uk-child-width-autoDivides the grid into equal units depending on the content size.
.uk-child-width-expandDivides the grid into equal units depending on the available space.
<div class="uk-child-width-1-4" uk-grid>
  <div></div>
  <div></div>

</div>
Copy to clipboard
  • Item
    Item
    Item
    Item
    Item
  • <div class="uk-grid-small uk-text-center uk-child-width-1-4" uk-grid>
      <div>
        <div class="uk-card uk-card-body uk-card-default">Item</div>
      </div>
      <div>
        <div class="uk-card uk-card-body uk-card-default">Item</div>
      </div>
      <div>
        <div class="uk-card uk-card-body uk-card-default">Item</div>
      </div>
      <div>
        <div class="uk-card uk-card-body uk-card-default">Item</div>
      </div>
      <div>
        <div class="uk-card uk-card-body uk-card-default">Item</div>
      </div>
    </div>

Items that use width classes with fractions will break into a new row, if they no longer fit their container’s width. When using one of the expand classes, however, the space will be evenly distributed among items that always stay in the same row.

<div class="uk-child-width-expand" uk-grid>
  <div></div>
  <div></div>

</div>
Copy to clipboard
  • Item
    Item
    Item
    Item
    Item
  • <div class="uk-grid-small uk-text-center uk-child-width-expand" uk-grid>
      <div>
        <div class="uk-card uk-card-body uk-card-default">Item</div>
      </div>
      <div>
        <div class="uk-card uk-card-body uk-card-default">Item</div>
      </div>
      <div>
        <div class="uk-card uk-card-body uk-card-default">Item</div>
      </div>
      <div>
        <div class="uk-card uk-card-body uk-card-default">Item</div>
      </div>
      <div>
        <div class="uk-card uk-card-body uk-card-default">Item</div>
      </div>
    </div>

Fixed width

In addition to the calculated width classes, you can also add one of the following classes, which apply fixed widths.

ClassDescription
.uk-width-smallApplies a fixed width of 150px.
.uk-width-mediumApplies a fixed width of 300px.
.uk-width-largeApplies a fixed width of 450px.
.uk-width-xlargeApplies a fixed width of 600px.
.uk-width-2xlargeApplies a fixed width of 750px.
<div class="uk-width-medium"></div>
Copy to clipboard
  • Small
    Medium
    Large
    X-Large
    2X-Large
  • <div class="uk-margin uk-width-small">
      <div class="uk-card uk-card-body uk-card-default uk-card-small">Small</div>
    </div>
    <div class="uk-margin uk-width-medium">
      <div class="uk-card uk-card-body uk-card-default uk-card-small">Medium</div>
    </div>
    <div class="uk-margin uk-width-large">
      <div class="uk-card uk-card-body uk-card-default uk-card-small">Large</div>
    </div>
    <div class="uk-margin uk-width-xlarge">
      <div class="uk-card uk-card-body uk-card-default uk-card-small">X-Large</div>
    </div>
    <div class="uk-margin uk-width-2xlarge">
      <div class="uk-card uk-card-body uk-card-default uk-card-small">2X-Large</div>
    </div>

Mixing widths

You can also combine .uk-child-width-* classes with .uk-width-* classes for individual items. That way it is possible, for example, to create a grid with one item that has a specific width and all other items expanding to fill the remaining space.

<div class="uk-child-width-expand" uk-grid>
  <div></div>
  <div class="uk-width-1-3"></div>
  <div></div>

</div>
Copy to clipboard
  • Expand
    1-3
    Expand
    Expand
  • <div class="uk-grid-small uk-text-center uk-child-width-expand" uk-grid>
      <div>
        <div class="uk-card uk-card-body uk-card-default">Expand</div>
      </div>
      <div class="uk-width-1-3">
        <div class="uk-card uk-card-body uk-card-default">1-3</div>
      </div>
      <div>
        <div class="uk-card uk-card-body uk-card-default">Expand</div>
      </div>
      <div>
        <div class="uk-card uk-card-body uk-card-default">Expand</div>
      </div>
    </div>

Responsive width

UIkit provides a number of responsive width classes. Basically they work just like the usual width classes, except that they have suffixes that represent the breakpoint from which they come to effect. These classes can be combined with the Visibility component. This is great for adjusting your layout and content for different device sizes.

ClassDescription
.uk-width-*
.uk-child-width-*
Affects all device widths, grid columns stay side by side.
.uk-width-*@s
.uk-child-width-*@s
Affects device widths of 640px and larger. Grid columns will stack on smaller sizes.
.uk-width-*@m
.uk-child-width-*@m
Affects device widths of 768px and larger. Grid columns will stack on smaller sizes.
.uk-width-*@l
.uk-child-width-*@l
Affects device widths of 1024px and larger. Grid columns will stack on smaller sizes.
.uk-width-*@xl
.uk-child-width-*@xl
Affects device widths of 1280px and larger. Grid columns will stack on smaller sizes.
Copy to clipboard
  • 1-2@m
    1-4@m
    1-4@m
    1-5@m
    hidden@l
    1-5@m
    1-3@l
    3-5@m
    2-3@l
    auto@m
    visible@l
    1-3@m
    expand@m
  • <div class="uk-grid-small uk-grid-match uk-text-center" uk-grid>
      <div class="uk-width-1-2@m">
        <div class="uk-card uk-card-body uk-card-default">1-2@m</div>
      </div>
      <div class="uk-width-1-4@m">
        <div class="uk-card uk-card-body uk-card-default">1-4@m</div>
      </div>
      <div class="uk-width-1-4@m">
        <div class="uk-card uk-card-body uk-card-default">1-4@m</div>
      </div>
      <div class="uk-width-1-5@m uk-hidden@l">
        <div class="uk-card uk-card-body uk-card-secondary">
          1-5@m<br />hidden@l
        </div>
      </div>
      <div class="uk-width-1-5@m uk-width-1-3@l">
        <div class="uk-card uk-card-body uk-card-default">1-5@m<br />1-3@l</div>
      </div>
      <div class="uk-width-3-5@m uk-width-2-3@l">
        <div class="uk-card uk-card-body uk-card-default">3-5@m<br />2-3@l</div>
      </div>
    </div>
    
    <div class="uk-grid-small uk-grid-match uk-text-center" uk-grid>
      <div class="uk-width-auto@m uk-visible@l">
        <div class="uk-card uk-card-body uk-card-primary">
          auto@m<br />visible@l
        </div>
      </div>
      <div class="uk-width-1-3@m">
        <div class="uk-card uk-card-body uk-card-default">1-3@m</div>
      </div>
      <div class="uk-width-expand@m">
        <div class="uk-card uk-card-body uk-card-default">expand@m</div>
      </div>
    </div>
Customize