# Group

## <mark style="color:green;">class</mark> **Group**

A `Group` is a UI element that can only exist as a child of a [Card](/ui-scripting/api-reference/card.md). It is used to organize multiple [UI Elements](/ui-scripting/api-reference/ui-elements.md) into a single unit for easier alignment and positioning.

{% hint style="warning" %}
Do not create **Group** instances directly. Instead, use the `create_group()` method of the [Card](/ui-scripting/api-reference/card.md) class to genereate them.
{% endhint %}

{% hint style="info" %}
Nesting multiple Groups is allowed.
{% endhint %}

#### Constructor

```python
# Basic example
group = card.create_group(type="columns")

# Setting extra attributes
group = card.create_group(
    type="columns",
    horizontal_align="center",
    vertical_align="center",
    gap=2,
    full_width=True
)

# Type of rows
group = card.create_group(type="rows")

# Nesting groups
group1 = card.create_group(type="columns")
group2 = group1.create_group(type="rows")
```

| Parameter         | Description                                                                              |                                                                                                                                                                                                                                                                           |                                                                                                                                                                  |
| ----------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| type              | <p>Allowed: <code>"columns"</code>                                                       | <code>"rows"</code><br>Default: <code>columns</code></p>                                                                                                                                                                                                                  |                                                                                                                                                                  |
| vertical\_align   | <p>Allowed: <code>"start"</code>                                                         | <code>"center"                                                                                                                                                                                                                                                            | "end"</code><br>Default: <code>"start"</code><br><br>Defines the alignment of the group's child elements (UI elements and Groups) along the vertical axis.</p>   |
| horizontal\_align | <p>Allowed: <code>"start"</code>                                                         | <code>"center"                                                                                                                                                                                                                                                            | "end"</code><br>Default: <code>"start"</code><br><br>Defines the alignment of the group's child elements (UI elements and Groups) along the horizontal axis.</p> |
| gap               | <p>See <a href="/pages/DTBGfFducdgJJ6exaVF7#gap">Gap</a>.<br>Default: <code>6</code></p> |                                                                                                                                                                                                                                                                           |                                                                                                                                                                  |
| full\_width       | <p>Allowed: <code>True                                                                   | False</code><br>Default: <code>False</code><br><br>Forces the group to occupy the entire available width. Use this if the group appears smaller than expected. Note: It may require setting the parent elements (such as containers and cards) to full width as well.</p> |                                                                                                                                                                  |

#### Methods

| Method                                   | Description                                                                          |
| ---------------------------------------- | ------------------------------------------------------------------------------------ |
| create\_group(type, \*\*kwargs)          | Creates a nested Group instance within the current Group.                            |
| create\_ui\_element(element, \*\*kwargs) | Creates a [UI Element](/ui-scripting/api-reference/ui-elements.md) within the Group. |

### Examples

Improved version of the last example from the previous section (Card). Here, Group is used to place the button next to the input.

<figure><img src="/files/obXvCfqePigrFVbgY2DL" alt=""><figcaption></figcaption></figure>

```python
tab = Tab(name='My Custom Tab')

container = tab.create_container(type="columns")

card = container.create_card(gap=2, vertical_align="center", horizontal_align="center")
card.create_ui_element(UI.Text, content="Input email", size="base")

group = card.create_group(type="columns", gap=2, vertical_align="center")

email_input = group.create_ui_element(UI.Input, label="Email")
submit_button = group.create_ui_element(UI.Button, label="Submit", variant="cta")

def on_submit():
    print(f"{email_input.value} submitted")

submit_button.onClick = on_submit

tab.render()
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.nighty.one/ui-scripting/api-reference/group.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
