We're sorry, but this feature is not yet available. We are working hard to make it happen as soon as possible. Thank you for your patience and understanding. Please check back later for updates.
The element you clicked is for demonstration purposes only and does not lead to actual content. Everything you see here is a simulation intended to demonstrate how the UI elements might look and behave in a real application.
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.
Note If you are not using Tailwind
CSS, you can skip this step. On your tailwind.config.js
file, add the Width component
within the ui()
plugin.
import ui from "franken-ui";
ui({
components: {
width: {
hooks: {},
media: true
}
}
}),
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.
Class | Description |
---|---|
.uk-width-1-1 | Fills 100% of the available width. |
.uk-width-1-2 | The element takes up halves of its parent container. |
.uk-width-1-3 , .uk-width-2-3 | The element takes up thirds of its parent container. |
.uk-width-1-4 , .uk-width-3-4 | The 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-6 | The 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>
<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>
The Width component provides additional modifiers to give you more flexibility in the distribution of items.
Class | Description |
---|---|
.uk-width-auto | The item expands only to the width of its own content. |
.uk-width-expand | The 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>
<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>
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.
Class | Description |
---|---|
.uk-child-width-1-2 | All elements take up half of their parent container. |
.uk-child-width-1-3 | All elements take up a third of their parent container. |
.uk-child-width-1-4 | All elements take up a fourth of their parent container. |
.uk-child-width-1-5 | All elements take up a fifth of their parent container. |
.uk-child-width-1-6 | All elements take up a sixth of their parent container. |
.uk-child-width-auto | Divides the grid into equal units depending on the content size. |
.uk-child-width-expand | Divides the grid into equal units depending on the available space. |
<div class="uk-child-width-1-4" uk-grid>
<div></div>
<div></div>
…
</div>
<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>
<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>
In addition to the calculated width classes, you can also add one of the following classes, which apply fixed widths.
Class | Description |
---|---|
.uk-width-small | Applies a fixed width of 150px. |
.uk-width-medium | Applies a fixed width of 300px. |
.uk-width-large | Applies a fixed width of 450px. |
.uk-width-xlarge | Applies a fixed width of 600px. |
.uk-width-2xlarge | Applies a fixed width of 750px. |
<div class="uk-width-medium"></div>
<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>
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>
<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>
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.
Class | Description |
---|---|
.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. |
<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>