# Space

> Fixed gaps and flexible spacers. A native Pyzed component for Python desktop GUIs, with a live preview, code examples and its API.

Source: https://albakore.github.io/pyzed/library/spacing/

:::tip[In plain words]
Empty space: a fixed gap, or a spring that pushes things apart.
:::

`pz.space(width, height)` is an empty box of a given size. `pz.hspace()` and `pz.vspace()` are flexible gaps that take the free space, pushing their siblings to the edges of a row or column.

`pz.space` · Category: [Layout](https://albakore.github.io/pyzed/library/#layout) · [Full reference →](https://albakore.github.io/pyzed/reference/widgets/#space)

**Code:**

```python
box = lambda text, w=90, h=44: pz.container(ui.label(text), center=True, width=w, height=h, bg=pz.theme.current().element, radius=6)
pz.column([
    pz.row([box("left"), pz.hspace(), box("right")], width=440),
    pz.row([box("a"), pz.space(width=60), box("60 px later", w=140)]),
], spacing=16)
```

## When to use

- To push actions to the right of a toolbar, or a footer to the bottom of a panel.

## Usage

```python
import pyzed as pz
from pyzed import ui

box = lambda text, w=90, h=44: pz.container(ui.label(text), center=True, width=w, height=h, bg=pz.theme.current().element, radius=6)
pz.column([
    pz.row([box("left"), pz.hspace(), box("right")], width=440),
    pz.row([box("a"), pz.space(width=60), box("60 px later", w=140)]),
], spacing=16)
```

## Variants

:::note[About these captures]
Each capture is recorded by pyzed itself, off-screen at 2x, in One Dark or One Light to match this site's theme, and cropped to the component so it shows at its real size. The pointer hovers, presses or types into it; a component that does not react to the pointer cycles through a few themes. With reduced motion you see the first frame. Open **Code** under a capture to see the snippet that draws it; free names such as `on_save` stand for your own callbacks.
:::

### Options

```python
box = lambda text, w=90, h=44: pz.container(ui.label(text), center=True, width=w, height=h, bg=pz.theme.current().element, radius=6)
pz.row([box("left"), pz.hspace(), box("right")], width=320)
```

```python
box = lambda text, w=90, h=44: pz.container(ui.label(text), center=True, width=w, height=h, bg=pz.theme.current().element, radius=6)
pz.row([box("a"), pz.space(width=60), box("b")])
```

```python
box = lambda text, w=90, h=44: pz.container(ui.label(text), center=True, width=w, height=h, bg=pz.theme.current().element, radius=6)
pz.column([box("top"), pz.vspace(), box("bottom")], height=150)
```

## Events

Space has no events of its own: it shows what you give it. Like every widget it also has the **18 common events** (`click`, `double_click`, `right_click`, `mouse_enter`, `drag`, `key_down`, `resize`…), attached with `.on(...)`: see [Events](https://albakore.github.io/pyzed/guides/events/) and [Events of every component](https://albakore.github.io/pyzed/library/events/).

## Properties and API

### `pz.space`

```python
space(width=None, height=None)
```

Empty space of a given size.

| Property | Default | Description |
| --- | --- | --- |
| `width` | `None` | Width: pixels, `"fill"`, `"shrink"` or `"fill:N"` (proportion). |
| `height` | `None` | Height: pixels, `"fill"`, `"shrink"` or `"fill:N"` (proportion). |

[Full reference →](https://albakore.github.io/pyzed/reference/widgets/#space)

### `pz.hspace`

```python
hspace(width='fill')
```

Flexible horizontal gap: pushes the siblings in a row towards the edges.

| Property | Default | Description |
| --- | --- | --- |
| `width` | `"fill"` | Width: pixels, `"fill"`, `"shrink"` or `"fill:N"` (proportion). |

[Full reference →](https://albakore.github.io/pyzed/reference/widgets/#hspace)

### `pz.vspace`

```python
vspace(height='fill')
```

Flexible vertical gap: pushes the siblings in a column towards the edges.

| Property | Default | Description |
| --- | --- | --- |
| `height` | `"fill"` | Height: pixels, `"fill"`, `"shrink"` or `"fill:N"` (proportion). |

[Full reference →](https://albakore.github.io/pyzed/reference/widgets/#vspace)

## Related

- [Row](https://albakore.github.io/pyzed/library/row/): Lays out children horizontally.
- [Column](https://albakore.github.io/pyzed/library/column/): Stacks children vertically.
- [Divider](https://albakore.github.io/pyzed/library/divider/): A thin line in the theme's border color.
