# Sizing

> Sizing utilities set the width and height of an element relative to its parent or to the viewport.

Set width and height with utility classes - relative to the parent, to the viewport, or to the visible viewport on mobile.

Source: https://docs.tabler.io/ui/utilities/sizing

---

## Width and height

`.w-*` and `.h-*` set the width or height in percent of the parent (`25`, `33`, `50`, `66`, `75`, `100`), on the spacing scale, or to `auto`.

```html
<div class="w-25 p-2 mb-2 bg-primary-lt rounded">Width 25%</div>
<div class="w-50 p-2 mb-2 bg-primary-lt rounded">Width 50%</div>
<div class="w-100 p-2 bg-primary-lt rounded">Width 100%</div>
```

## Content-based sizes

`min-content`, `max-content`, and `fit-content` size the element by its content instead of its parent. Use them as `.w-fit-content`, `.h-max-content`, and so on.

- `min-content` is as narrow as the longest word.
- `max-content` fits the content on one line, even if it overflows the parent.
- `fit-content` fits the content but never grows wider than the parent.

```html
<div class="w-min-content p-2 mb-2 bg-primary-lt rounded">Min content width</div>
<div class="w-max-content p-2 mb-2 bg-primary-lt rounded">Max content width</div>
<div class="w-fit-content p-2 bg-primary-lt rounded">Fit content width</div>
```

## Minimum width and height

`.min-w-0`, `.min-w-100`, `.min-h-0`, and `.min-h-100` set `min-width` or `min-height` to `0` or `100%`.

A flex child does not shrink below the width of its content by default, so a long word, a table, or a code block pushes the layout wider than its parent. Add `.min-w-0` to the child to let it shrink, for example to make `.text-truncate` work inside a flex row.

```html
<div class="d-flex gap-2 p-2 border rounded" style="max-width: 20rem">
  <span class="avatar avatar-sm">AB</span>
  <div class="min-w-0">
    <div class="text-truncate">A very long name that has to be truncated inside a flex row</div>
  </div>
</div>
```

## Viewport

`.vw-100` and `.vh-100` set the width or height to the full viewport, and `.min-vw-100` and `.min-vh-100` set it as the minimum.

The dynamic versions `.dvw-100`, `.dvh-100`, `.min-dvw-100`, and `.min-dvh-100` use the `dvw` and `dvh` units. They follow the visible viewport, so a full-height section does not overflow on mobile while the browser shows its address bar.

```html
<section class="min-dvh-100">...</section>
<div class="dvh-100 overflow-auto">...</div>
```
