# Grid (/examples/layouts/grid)



A 2D cell-based layout that places children into explicit rows and columns, analogous to CSS Grid. Use it when content must align across both axes, such as dashboards or forms.

Grid alignment of tracks [#grid-alignment-of-tracks]

<LvglExampleBrief>
  Place column and row tracks within free space.
</LvglExampleBrief>

Track sizes are smaller than the container, so leftover space is distributed by
style\_grid\_column\_align and style\_grid\_row\_align. Here columns use space\_between to
push them to the edges, while rows align to end and stick to the bottom.

<LvglExample name="lv_example_grid_align" path="layouts/grid/lv_example_grid_align" />

Grid cell span and alignment [#grid-cell-span-and-alignment]

<LvglExampleBrief>
  Position cells inside their track and span multiple tracks.
</LvglExampleBrief>

The first row uses different style\_grid\_cell\_x\_align / y\_align values to show start,
center, and end placement within a cell. Two further items use column\_span and row\_span
to occupy multiple tracks at once, demonstrating how a single child can cover several
cells of the grid.

<LvglExample name="lv_example_grid_cell_span" path="layouts/grid/lv_example_grid_cell_span" />

Grid descriptors [#grid-descriptors]

<LvglExampleBrief>
  Define fixed-size column and row tracks.
</LvglExampleBrief>

style\_grid\_column\_dsc\_array and style\_grid\_row\_dsc\_array list the size of each track in
pixels. The example uses three 70px columns and two 44px rows, and each child positions
itself with style\_grid\_cell\_column\_pos and style\_grid\_cell\_row\_pos.

<LvglExample name="lv_example_grid_descriptors" path="layouts/grid/lv_example_grid_descriptors" />

Grid FR units [#grid-fr-units]

<LvglExampleBrief>
  Share remaining space across tracks with fr() weights.
</LvglExampleBrief>

The first column has a fixed 60px size; the next two columns use fr(1) and fr(2) and
split the remaining width in a 1:2 ratio. The same idea applies to rows: the first row
is fixed at 44px and the second uses fr(1) to absorb the leftover height.

<LvglExample name="lv_example_grid_fr" path="layouts/grid/lv_example_grid_fr" />

Grid ignore layout [#grid-ignore-layout]

<LvglExampleBrief>
  Detach an item from grid placement.
</LvglExampleBrief>

Four normal grid items occupy their cells while a fifth item with ignore\_layout="true"
is skipped by the grid. The detached item keeps its manual x/y position and does not
displace any of the placed cells, useful for floating badges or overlays.

<LvglExample name="lv_example_grid_ignore_layout" path="layouts/grid/lv_example_grid_ignore_layout" />

Grid internal padding [#grid-internal-padding]

<LvglExampleBrief>
  Set horizontal and vertical gaps between grid cells.
</LvglExampleBrief>

style\_pad\_column inserts space between columns and style\_pad\_row inserts space between
rows. The two are independent, so column gaps and row gaps can differ — here columns
are flush together while rows have a large vertical gap.

<LvglExample name="lv_example_grid_internal_padding" path="layouts/grid/lv_example_grid_internal_padding" />

Grid RTL [#grid-rtl]

<LvglExampleBrief>
  Reverse column order with style_base_dir.
</LvglExampleBrief>

Both grids declare the same three columns and the same children. Setting style\_base\_dir
to rtl on the second grid flips the column order, so cell 0 appears on the right
without changing how children are referenced or ordered in XML.

<LvglExample name="lv_example_grid_rtl" path="layouts/grid/lv_example_grid_rtl" />

Grid sub-grid [#grid-sub-grid]

<LvglExampleBrief>
  Nest a grid inside a cell of a parent grid.
</LvglExampleBrief>

The outer grid defines 3x2 tracks, and an inner grid occupies a 2x2 area within it. The
inner grid intentionally omits its own column/row descriptors so it inherits the parent
tracks, keeping its cells aligned with the outer grid's columns and rows.

<LvglExample name="lv_example_grid_subgrid" path="layouts/grid/lv_example_grid_subgrid" />
