Basics

Auto Layout & Constraints

Designs rarely stay one size. Hana has two systems for handling that, and they solve different problems:

SystemWhat it doesReach for it when
Auto LayoutA frame arranges its children in a row, column, wrap or grid, spacing and resizing them for youButtons, lists, nav bars, cards, stacked sections — anything whose content can change
ConstraintsAn element holds a relationship to its parent frame's edges as that frame resizesBackgrounds, pinned headers, corner badges, anything placed freely

They work together: constraints handle elements positioned freely, auto layout handles the ones flowing inside a container.


Auto Layout

Select a frame and turn on the Layout panel in the properties sidebar. Its children stop being individually positioned and start flowing in order.

You don't need a frame first. Turn Layout on with a plain selection and Hana wraps it in a frame for you; turn it on with a group selected and the group becomes a frame.

Direction and wrapping

Direction sets the flow, with four modes: Row, Column, Wrap and Grid. In Wrap, items that don't fit continue onto a new line instead of overflowing — which is what you want for tag lists and card collections. Wrap mode also offers a masonry option, staggering items into a Pinterest-style arrangement rather than aligning them in strict rows. Grid places children in columns and rows; see Grid layout below.

Align

Align decides where children sit inside the container, as a nine-position grid — top-left through to bottom-right. In a horizontal layout the vertical half of that choice controls whether items ride the top, the middle or the bottom of the row; in a vertical layout the horizontal half does the same for columns.

To line up text of different sizes in a row, turn on Baseline in the Layout panel. Children then align on their text baseline instead of their boxes. It's available for rows only.

Gap and padding

Gap is the space between items, set separately for the main direction and for rows when wrapping. It accepts negative values — useful for deliberately overlapping avatars or stacked cards.

Padding is the space between the container's edges and its content, adjustable independently on each side.

Stacking and strokes

Two more options sit at the bottom of the Layout panel:

  • Stacking — when children overlap (with a negative gap, say), choose First on top or Last on top to decide which one is drawn above the others.
  • Strokes — choose whether the frame's stroke takes up space in the layout (Included) or not (Excluded).

Grid layout

Choose Grid as the direction to lay children out in columns and rows. Children fill the cells row by row, in layer order.

A frame with a 4 by 2 grid layout in Hana, with the Layout panel and the Dimensions picker

Setting the grid's size

The Grid field in the Layout panel shows a small picture of the grid with its size (for example 4 × 2). Click it to open Dimensions:

  • Type the number of Columns and Rows, or
  • point at a cell in the picker and click to set both at once.

The Gap fields set the space between columns and the space between rows separately.

Track sizes

Each column and row is a track. Click Track sizes in the Dimensions popover to edit them as text, using the same syntax as CSS:

TrackWhat it does
200A fixed size in pixels
1frA share of the free space; 1fr 2fr gives the second track twice as much
autoFits the track to its content

For example 1fr 1fr 200 auto, or repeat(3, 1fr) for three equal columns. Rows you don't list are added as needed and fit their content.

Spanning cells

Select a child of a grid and set Span to the number of columns (C) and rows (R) it should cover. A child set to Fill takes up its whole cell (or cells), and a grid frame set to Hug shrinks to fit its tracks.

When you export to HTML, a grid frame becomes a CSS grid with the same tracks, gaps and spans.


Sizing children: Fixed, Fill and Hug

This is the part that makes auto layout click. Every child of an auto-layout frame chooses how it sizes on each axis:

SizingBehaviorTypical use
FixedStays exactly the size you setAn icon, an avatar, a fixed-width sidebar
FillGrows to take the available space in the containerA text field next to a fixed button; the flexible middle of a nav bar
HugShrinks to fit its own contentA button that stays snug around its label

A button is usually Hug on both axes; the container it lives in is often Fill horizontally. Two elements that both Fill share the space between them.

The classic pattern: a row set to Fill the frame, with a Hug button on the right and a Fill text element on the left. Change the label, resize the frame — the row keeps working without you touching a coordinate.

Min and max sizes

Auto-layout frames and their children have Min and Max fields for width (W) and height (H). A Fill or Hug element then grows or shrinks only within those limits — a card that fills its row but never gets wider than 400 px, or a text box that hugs its content but never shrinks below 120 px. Leave a field empty for no limit.

Aspect ratio lock

Click the lock next to the width and height fields to keep a layer's proportions. The lock is saved with the layer: the size fields and the resize handles keep the ratio without holding Shift, and so does auto layout — if a child fills its parent in one direction, its other dimension follows the ratio.

Taking a child out of the flow

Sometimes one element inside an auto-layout frame shouldn't participate — a badge pinned to a corner, a decorative shape behind the content. Switch that child to absolute positioning from the Transform panel and it leaves the flow: you position it freely, and it follows its constraints instead.


Constraints

An element that isn't flowing in an auto layout needs to know what to do when its parent frame changes size. That's what the Constraints panel is for — a visual picker plus a dropdown per axis.

HorizontalVerticalWhat it does
LeftTopKeeps a fixed distance from that edge
RightBottomKeeps a fixed distance from the opposite edge
Left and RightTop and BottomHolds both edges, so the element stretches with the frame
CenterCenterStays centered as the frame grows
ScaleScaleKeeps its position and size proportional to the frame

Set each axis independently — a header is typically Left and Right plus Top, so it spans the width and stays at the top. A full-bleed background is Left and Right with Top and Bottom. A floating action button is Right and Bottom.


Things worth knowing

  • Layout properties don't animate. Padding, gap and direction can't change between states — a state that needs to visibly resize should change width, height or scale instead. See Interactivity in Hana.
  • Nest layouts freely. A vertical page frame holding horizontal row frames is the normal way to build a screen, and each level manages its own spacing.
  • Frames are also your export unit, so the frame you build a layout in is usually the frame you publish. See Exporting in Hana.

Designing in Hana, Sections in Hana, Pages in Hana

On this page