For AI agents: the complete documentation index is at llms.txt. Markdown versions are available by appending .md or sending Accept: text/markdown.
Reflex Logo
Docs Logo
Library

/

Layout

/

Flex

Flex

The Flex component is used to make flexbox layouts. It makes it simple to arrange child components in horizontal or vertical directions, apply wrapping, justify and align content, and automatically size components based on available space, making it ideal for building responsive layouts.

By default, children are arranged horizontally (direction="row") without wrapping.

Basic Example

Card 1
Card 2
Card 3
Card 4
Card 5

Wrapping

With flex_wrap="wrap", the children will wrap to the next line instead of being resized.

Card 1
Card 2
Card 3
Card 4
Card 5
Card 6
Card 7
Card 8
Card 9
Card 10

Direction

With direction="column", the children will be arranged vertically.

Card 1
Card 2
Card 3
Card 4

Alignment

Two props control how children are aligned within the Flex component:

  • align controls how children are aligned along the cross axis (vertical for row and horizontal for column).
  • justify controls how children are aligned along the main axis (horizontal for row and vertical for column).

The following example visually demonstrates the effect of these props with different wrap and direction values.

Wrap

Direction

Align

Justify

Card 1
Card 2
Card 3
Card 4
Card 5
Card 6
Card 7
Card 8
Card 9
Card 10
Expand

Size Hinting

When a child component is included in a flex container, the flex_grow (default "0") and flex_shrink (default "1") props control how the box is sized relative to other components in the same container.

The resizing always applies to the main axis of the flex container. If the direction is row, then the sizing applies to the width. If the direction is column, then the sizing applies to the height. To set the optimal size along the main axis, the flex_basis prop is used and may be either a percentage or CSS size units. When unspecified, the corresponding width or height value is used if set, otherwise the content size is used.

When flex_grow="0", the box will not grow beyond the flex_basis.

When flex_shrink="0", the box will not shrink to less than the flex_basis.

These props are used when creating flexible responsive layouts.

Move the slider below and see how adjusting the width of the flex container affects the computed sizes of the flex items based on the props that are set.

flex_shrink=0
flex_shrink=1
flex_grow=0
flex_grow=1
Expand

API Reference

rx.flex

Component for creating flex layouts.

Card 1
Card 2
Card 3
rx.flex(
rx.card("Card 1", size="2", width="5rem"),
rx.card("Card 2", size="2", width="5rem"),
rx.card("Card 3", size="2", width="5rem"),
gap="0.75rem",
width="100%",
min_height="10rem",
border="1px dashed var(--gray-7)",
border_radius="0.5rem",
padding="0.75rem",
direction="row",
align="start",
justify="start",
)
direction
align
justify

Props

PropTypeDescription
access_key
str

Provides a hint for generating a keyboard shortcut for the current element.

auto_capitalize
"off""none""on""sentences""words""characters"

Controls whether and how text input is automatically capitalized as it is entered/edited by the user.

content_editable
"inherit""plaintext-only"

Indicates whether the element's content is editable.

context_menu
str

Defines the ID of a <menu> element which will serve as the element's context menu.

dir
str

Defines the text direction. Allowed values are ltr (Left-To-Right) or rtl (Right-To-Left).

draggable
bool

Defines whether the element can be dragged.

enter_key_hint
"enter""done""go""next""previous""search""send"

Hints what media types the media element is able to play.

hidden
bool

Defines whether the element is hidden.

input_mode
"none""text""tel""url""email""numeric""decimal""search"

Defines the type of the element.

item_prop
str

Defines the name of the element for metadata purposes.

lang
str

Defines the language used in the element.

role
"alert""alertdialog""application""article""banner""button""cell""checkbox""columnheader""combobox""complementary""contentinfo""definition""dialog""directory""document""feed""figure""form""grid""gridcell""group""heading""img""link""list""listbox""listitem""log""main""marquee""math""menu""menubar""menuitem""menuitemcheckbox""menuitemradio""navigation""none""note""option""presentation""progressbar""radio""radiogroup""region""row""rowgroup""rowheader""scrollbar""search""searchbox""separator""slider""spinbutton""status""switch""tab""table""tablist""tabpanel""term""textbox""timer""toolbar""tooltip""tree""treegrid""treeitem"

Defines the role of the element.

slot
str

Assigns a slot in a shadow DOM shadow tree to an element.

spell_check
bool

Defines whether the element may be checked for spelling errors.

tab_index
int

Defines the position of the current element in the tabbing order.

title
str

Defines a tooltip for the element.

as_child
bool

Change the default rendered element for the one passed as a child, merging their props and behavior.

direction
"row""column""row-reverse""column-reverse"

How child items are laid out: "row" | "column" | "row-reverse" | "column-reverse".

align
"start""center""end""baseline""stretch"

Alignment of children along the main axis: "start" | "center" | "end" | "baseline" | "stretch".

justify
"start""center""end""between"

Alignment of children along the cross axis: "start" | "center" | "end" | "between".

wrap
"nowrap""wrap""wrap-reverse"

Whether children should wrap when they reach the end of their container: "nowrap" | "wrap" | "wrap-reverse".

spacing
"0""1""2""3""4""5""6""7""8""9"

Gap between children: "0" - "9".

Built with Reflex