> For the complete documentation index, see [llms.txt](https://docs.appfarm.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.appfarm.io/library/ui-components/container.md).

# Container

The most important UI component is the container. For those of you with any HTML experience, a container is similar to a `<div>` tag. The container allows for grouping the view into sections, and the container may have its contents (the components inside the container, known as the *children*) aligned vertically (which is by default) or horizontally.

The container is probably the most important UI component. Some typical use cases for a container are:

* Split a screen into sections
* Group a set of other UI components, in order to apply the same visibility or enable a condition
* Group a set of other UI components, in order to apply motions (such as collapse)
* Styling different parts of your UI with regards to backgrounds, borders, elevation or alignment
* Create custom UI components, such as custom buttons or lists / tiles
* Create a file-drop or hover sections
* Create scrollable sections of your view or dialog

The Styling Pane properties are documented in Appfarm Create in the [Blue Dots](https://docs.appfarm.io/reference/appfarm-create/blue-dots.md) corresponding to each property. However, we will summarize a few key settings for various purposes.

### Split layout or adjust alignment

By default, all UI components inside a Container are left-aligned and vertically oriented.

To enable other behaviour, set the **Display** to **Flex**. You may also want to set this on the top-level View or Dialog as well, since the setting of the parent affects the possible settings of the children. You may read more on the Flex setting [here](https://docs.appfarm.io/how-to/user-interface/flexbox.md).

When the display is set to Flex, you may set **Layout direction** to e.g. Horizontal, and add two more containers inside, and allow them to stretch out by setting **Sizing** to **Stretch**. You have now created two equally sized *columns*. Each column may be adjusted further.

### Margin and padding

*Margin* is the outer space of the container, in other words, outside the container border. *Padding* is the inner space. In general, when scrolling is enabled, Padding is the best option.

A short rule of thumb when creating a UI is to use a multiplier of 8px as padding/margin. This will help you have your UI more aligned.

### Scroll settings

The setting for the scroll is found in the **Overflow** menu.

By default, no scrolling is enabled. The simplest type of scroll is the vertical scroll on the top level. You may enable Overflow **Vertical** by setting **Auto** on the top-level view or container.

Sometimes you want a fixed section at the top and a scrollable section at the bottom. To enable this, an easy rule of thumb may be applied: The container to be scrollable should have Overflow Vertical Auto. All parents of this container should have a **Display** set to **Flex**.

The scrollbar is positioned at the edge of the scrollable container. In other words, the scrollable container should have padding instead of margin - in order to have the scrollbar to the right side without any space to the right.

### Backgrounds and borders

Having different background colours for different sections of your UI will improve your UI a lot. For example, try combining background colours *Default* and *Paper* on a parent and child container, both with some padding, it will give the impression of different sections in your UI.

Borders may contribute to your UI, and you may also set Border Radius for a less "corporate" look and feel.

More tips are found in our [UI/UX crash course](https://showroom.appfarm.app/ui-ux-design).

### Create custom lists using Iterate Data Source

You may create custom lists or tiles using a container.

A container may be bound to a Data Source in the general setting **Repeat for each**. When bound to a Data Source containing e.g. 6 objects, the children of the container will repeat 6 times. In other words, you need only focus on the appearance of 1 row (or tile). Add a container inside, and configure the looks of the single row or tile.

When iterating a Data Source, use **Filter** and **Conditional filters** to pick which objects are iterated, **Sorting** to set their order, and **Skip** and **Limit** to control how many are shown.

When you select a data source in **Repeat for each**, the **Iteration variant** setting appears. There are four variants:

* **Repeat Content**: This is the default. The child of this Container will be repeated as rows (if vertical alignment is selected) or as columns/tiles (if horizontal alignment is selected). The number of rows/columns/tiles equals the number of objects in the Data Source for iteration. *Note*: You may repeat content inside a repeating container, meaning you may use this setting for creating two-dimensional data grids (a matrix), or calendars.
* **Swipeable Horizontal**: Only 1 child is displayed, but you may swipe between them horizontally (the number of possible swipes equals the number of objects in the Data Source for iteration). Use **Reveal next** (in px) to show part of the next item. You may find an example in our Showroom [here](https://showroom.appfarm.app/ui-components/container).
* **Swipeable Vertical**: Like **Swipeable Horizontal**, but you swipe up and down. **Reveal next** is only available for **Swipeable Horizontal**.
* **Tree / Recursive**: Build a recursive UI. Relevant when the data model has parent-child relationships within the same Object Class, such as `Department` having a property `Parent Department`. You will have to define that parent-child relationship in the setting **Parent ID**, the reference property that holds each object's parent. The iteration order of the objects in the Data Source will be done *depth-first*. Inside this iterating container, you have access to the Context Parameter **Recursion Level,** meaning you may e.g. set an offset to the left (of e.g. a Container representing one Department) as a function of `16 * Recursion Level` pixels, creating a visual tree structure. This variant is not available when iterating a property.

The swipeable variants are not available when iterating an App Variable of data type Schema.

{% hint style="info" %}
You may find many examples of Custom lists in our Showroom, such as [Tiles](https://showroom.appfarm.app/ui-components/container), [Data Grids](https://showroom.appfarm.app/use-cases/data-grid), [Recursive Trees](https://showroom.appfarm.app/use-cases/recursive-tree), [Calendars](https://showroom.appfarm.app/use-cases/calendar), [Kanban boards](https://showroom.appfarm.app/use-cases/kanban-board) or custom [vertical lists](https://showroom.appfarm.app/use-cases/comment-log). You may view demos, as well as access the setup in Appfarm Create. If you do not have access, you may register [here](https://showroom.appfarm.app/sign-up).
{% endhint %}

### Performance: Virtualize

When iterating a Data Source, the **Virtualize** section lets you optimize performance by only rendering the visible items. Check **Virtualization**, then set the **Orientation**, the **Item size** (height in px for vertical lists, width for horizontal lists) and **Overscan** (the number of items rendered outside the visible area). A Container with virtualization enabled must have a height or width, for example 100% or flex 1 inside a flex enabled parent Container.

### Custom HTML attributes

The Container is translated to a `<div>` tag in HTML. The Container has a few settings for those who need to set the HTML attributes/elements on the `<div>` tag: `Element ID`, `Element Type`, or add `Custom Attributes` to the `<div>` tag. Custom Attributes may be used e.g. for specific requirements regarding WCAG. You may read more about these three in the Blue Dots on the respective settings on the Container in Appfarm Create.

### Property conditions

Given certain conditions in your data or App Variables, you may apply different layouts and styling, such as changing the background colour.

### Show Loader

When a user initiates a long-running action, it is a good practice to give some feedback to the user that something is being processed. The Container has a setting **Show loader.** When set to true (or if the bound variable or condition is true), a loader is displayed as a placeholder for the whole container. Set the **Loader variant** to Circular (default), Linear Top Aligned or Linear Bottom Aligned, and the **Loader color**. For the Circular variant, you can also add a **Loader message**.

A typical pattern is the add an App Variable `Show loader`. This variable is set to `true` at the beginning of the long-running action, and is set to `false` as the final step of the action.

{% hint style="info" %}
Showroom: [Show Loader example](https://showroom.appfarm.app/ui-components/loader), with its setup in Appfarm Create ([register](https://showroom.appfarm.app/sign-up) for access).
{% endhint %}

### Hover and file drop zones

You may enable file drop on a container using the general setting **Enable file drop**. This will allow for setting an action **On file drop** and **On file paste**. You may also add actions for manipulating variables **On file over** and **On file out**. Property conditions may be used in combination with this to e.g. enable a light blue background colour when a file hovers over the container.

File drop allows you to paste (drag and drop) images or files into an Appfarm App from your desktop or clipboard.

{% hint style="info" %}
Showroom: [drag & drop of files example](https://showroom.appfarm.app/action-nodes/create-file-object), with its setup in Appfarm Create ([register](https://showroom.appfarm.app/sign-up) for access).
{% endhint %}

The settings **On hover start** and **On hover end** may be used to run an action when the mouse hovers over the container. Please note that to ensure the fast mouseovers are not "stuck", the actions executed on hover start / end should be allowed to run simultaneously (a setting on the Action). Use this in combination with Property Conditions on the Container, or Visibility Conditions on the children of the Container.

### Drag and drop

See our [guide](https://docs.appfarm.io/how-to/user-interface/drag-and-drop.md) on this. The **Drag & drop** section has these settings. It is not shown when **Iteration variant** is **Tree / Recursive**.

* **Drop area**: Makes the Container a drop area for draggable Containers. Adds the **On drop** event, where *Object in context* gives access to the dragged element's data and to the drop area's data.
* **Orientation**: Shown for a drop area. The direction items are dropped in, Vertical (default) or Horizontal.
* **Highlight on drag over**: Shown for a drop area. Highlights the Container background while a draggable Container is dragged over it. On by default when you enable the drop area.
* **Drop disabled**: Shown for a drop area. Turns dropping off, for example based on a condition.
* **Draggable**: Makes the Container draggable. It must be inside a drop area, and the whole Container acts as the drag handle. Adds the **On drag start** and **On drag end** events.
* **Drag disabled**: Shown when **Draggable** is checked. Turns dragging off, for example based on a condition.

Under **Other**, **No ripple** turns off the ripple effect when a Container with **On click** is clicked or focused.

### Event Handlers and Viewport Listener

Besides **On click**, a Container has **On double click** and **On right click**. When **Listener** is checked under **Viewport listener**, you can also use **On viewport enter** and **On viewport leave**. **Listener threshold** sets how much of the Container must be visible before these events run: `0` (default) runs them as soon as one pixel is visible, `1` waits until the whole Container is visible. You may read more on the various Event Handlers and the Listener setting in the [Event Handlers](https://docs.appfarm.io/appcademy/appfarm-fundamentals/actions-and-logic-fundamentals/event-handlers.md) section.

### Create custom buttons using On Click and styling

Containers may be used to create a button. Just set a background colour, add some text, images or icons - and add an **On click** Event Handler. The container will then be clickable.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.appfarm.io/library/ui-components/container.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
