---
title: Layout
path: utilities/layout
status: Stable
source: 'https://github.com/primer/css/blob/main/src/utilities/layout.scss'
bundle: utilities
---
Change the document layout with display, float, alignment, and other utilities.
## Display
Adjust the display of an element with `.d-block`, `.d-none`, `.d-inline`, `.d-inline-block`, `.d-table`, `.d-table-cell` utilities.
```html live
.d-inline
.d-inline-block
.d-block
.d-table-cell
.d-none
```
### The HTML `hidden` attribute
As of [Primer v10.10.0](https://github.com/primer/css/releases/v10.10.0), `primer-base` includes a rule that sets `display: none !important` for any element with the [`hidden` attribute][hidden]. You can safely use the `hidden` attribute with display utilities, but we suggest:
1. Use the `hidden` attribute (and corresponding JavaScript property) if you're going to programmatically show and hide content.
1. Use `d-none` and/or its responsive variants (`d-sm-block`, `d-lg-none`) to conditionally show content at different screen sizes.
Rather than toggling the `d-none` class in JavaScript, you should toggle the `hidden` property on an element. This means that you won't have to restore any more specific display utility (`d-inline` or `d-flex`, for instance) just to work around the order in which they're listed in the stylesheet.
```js
// Good:
element.hidden = !visible
// Bad:
element.classList.toggle('d-none', !visible)
element.classList.toggle('d-inline', visible)
```
### `display:table` wrapping issues
There are known issues with using `display:table` and wrapping long strings, particularly in Firefox. You may need to use `table-fixed` on elements with `d-table` and apply column widths to table cells, which you can do with our [column width styles](/objects/grid#column-widths).
```html live
.d-table-cell
d-table-cell .col-10
```
### Responsive display
A selection of display utilities are able to be applied or changed per [breakpoint](/objects/grid#breakpoints). `.d-block`, `.d-none`, `.d-inline`, and `.d-inline-block` are available as responsive utilities using the following formula: `d-[breakpoint]-[property]`. For example: `d-md-inline-block`. Each responsive display utility is applied to the specified breakpoint and up.
In the following example, the `ul` element switches from `display: block` on mobile to `display: inline-block` at the `md` breakpoint, while the list items remain inline.
```html live
.d-md-inline-block
```
### Responsive hide
Hide utilities are able to be applied or changed per breakpoint using the following formula:
`hide-[breakpoint]`, for example: `hide-sm`. Hide utilities act differently from other responsive styles and are applied to each **breakpoint-range only**.
| Shorthand | Range |
| --- | --- |
| -sm | 0—543px |
| -md | 544px—767px |
| -lg | 768px—1011px |
| -xl | 1012px and above |
```html live
Potato update
Opened by broccolini
Updated 3 hours ago
```
### Text direction
`.direction-ltr` or `.direction-rtl` can be used to change the text direction. This is especially helpful when paired with `.d-table`, `.d-table-cell`, and `.v-align-middle` to create equal height, vertically centered, alternating content.
## Visibility
Adjust the visibility of an element with `.v-hidden` and `.v-visible`.
## Overflow
Adjust element overflow with `.overflow-hidden`, `.overflow-scroll`, and `.overflow-auto`, or use `.overflow-visible` to undo the effects of CSS with overflow issues. `.overflow-hidden` can also be used to create a new [block formatting context](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context) or clear floats.
Overflow utilities can also target x- and y-axes independently via:
* `.overflow-x-auto`
* `.overflow-x-hidden`
* `.overflow-x-scroll`
* `.overflow-x-visible`
* `.overflow-y-auto`
* `.overflow-y-hidden`
* `.overflow-y-scroll`
* `.overflow-y-visible`
Overflow utilities can be applied or changed per [breakpoint](/objects/grid#breakpoints). Each **responsive** overflow utility is applied to the specified breakpoint and up, using the following formula: `overflow-[breakpoint]-[axis]-[property]`. For example: `overflow-x-scroll` or `overflow-md-x-visible`.
## Floats
Use `.float-left` and `.float-right` to set floats, and `.clearfix` to clear.
```html live
```
### Responsive floats
Float utilities can be applied or changed per [breakpoint](/objects/grid#breakpoints). This can be useful for responsive layouts when you want an element to be full width on mobile but floated at a larger breakpoint.
Each responsive float utility is applied to the specified breakpoint and up, using the following formula: `float-[breakpoint]-[property]`. For example: `float-md-left`. Remember to use `.clearfix` to clear.
```html live
.float-md-left
.float-md-right
```
## Alignment
Adjust the alignment of an element with `.v-align-baseline`, `.v-align-top`, `.v-align-middle` or `.v-align-bottom`. The vertical-align property only applies to inline or table-cell boxes.
```html live
Potatoes
.v-align-baseline
.v-align-top
.v-align-middle
.v-align-bottom
```
Use `v-align-text-top` or `v-align-text-bottom` to adjust the alignment of an element with the top or bottom of the parent element's font.
```html live
Potatoes
.v-align-text-top
.v-align-text-bottom
```
## Width and height
Use `.width-fit` to set max-width 100%.
```html live
```
Use `.width-full` to set width to 100%.
```html live
```
Use `.width-auto` to reset width to `auto` (initial value). Typically used with **responsive variants**. Resize the window to see the effect in the example below.
```html live
```
Use `.height-fit` to set max-height 100%.
```html live
Bacon ipsum dolor amet meatball flank beef tail pig boudin ham hock chicken capicola. Shoulder ham spare ribs turducken pork tongue. Bresaola corned beef sausage jowl ribeye kielbasa tenderloin andouille leberkas tongue. Ribeye tri-tip tenderloin pig, chuck ground round chicken tongue corned beef biltong.
```
Use `.height-full` to set height to 100%.
```html live
Bacon ipsum dolor amet meatball flank beef tail pig boudin ham hock chicken capicola. Shoulder ham spare ribs turducken pork tongue. Bresaola corned beef sausage jowl ribeye kielbasa tenderloin andouille leberkas tongue. Ribeye tri-tip tenderloin pig, chuck ground round chicken tongue corned beef biltong.
```
## Position
Position utilities can be used to alter the default document flow. **Be careful when using positioning, it's often unnecessary and commonly misused.**
The position of an element depends on the content. Use `top-0`, `right-0`, `bottom-0`, and `left-0` to further specify an elements final position.
```html live
.top-0 .left-0
.top-0 .right-0
.bottom-0 .right-0
.bottom-0 .left-0
```
Using the **responsive variants** (e.g. `.right-md-0`) can be helpful for positioning select menus, dropdowns, popovers etc. when the content gets shuffled around for certain responsive breakpoints. You can also use `auto` to "reset" a final position for wider breakpoints (e.g. `right-0 right-md-auto`).
### Relative
Use `.position-relative` to create a new stacking context.
_Note how the other elements are displayed as if "Two" were in its normal position and taking up space._
```html live
One
Two
Three
Four
```
### Absolute
Use `.position-absolute` to take elements out of the normal document flow.
```html live
```
### Fixed
Use `.position-fixed` to position an element relative to the viewport. **Be careful when using fixed positioning. It is tricky to use and can lead to unwanted side effects.**
_Note: This example is shown in an `