@@ -64,6 +64,13 @@ function requiredAt<T>(
6464 return item;
6565 }
6666
67+function getMainAxisGap(
68+ gap: number,
69+ justify: ContainerProps["justifyContent"] | undefined,
70+): number {
71+ return justify === "space-between" ? 0 : gap;
72+}
73+
6774 // --- Intrinsic size computation ---
6875
6976 /**
@@ -111,6 +118,7 @@ function intrinsicMainSize(
111118 // If it's the cross axis, take the max of children on that axis.
112119 const props = node.props;
113120 const gap = props.gap ?? 0;
121+ const mainAxisGap = getMainAxisGap(gap, props.justifyContent);
114122 const containerIsVertical = node.type === "vstack";
115123 const axisMatchesMain = isVertical === containerIsVertical;
116124
@@ -149,7 +157,7 @@ function intrinsicMainSize(
149157 childMain = clamp(childMain, minMain, maxMain);
150158 }
151159 total += childMain;
152- if (i < node.children.length - 1) total += gap;
160+ if (i < node.children.length - 1) total += mainAxisGap;
153161 }
154162 return total + padMain;
155163 }
@@ -185,7 +193,7 @@ function intrinsicMainSize(
185193 }
186194 wrapHeights.push(h);
187195 }
188- const wrapRows = assignWrapRows(wrapWidths, innerCross, gap);
196+ const wrapRows = assignWrapRows(wrapWidths, innerCross, mainAxisGap);
189197 let total = 0;
190198 for (let ri = 0; ri < wrapRows.length; ri++) {
191199 let maxH = 0;
@@ -359,6 +367,7 @@ function layoutWrapHStack(
359367 const gap = props.gap ?? 0;
360368 const align = props.alignItems ?? "stretch";
361369 const justify = props.justifyContent ?? "start";
370+ const itemGap = getMainAxisGap(gap, justify);
362371
363372 // Padding
364373 const padX = props.padding?.x ?? 0;
@@ -404,7 +413,7 @@ function layoutWrapHStack(
404413 }
405414
406415 // Phase 2: Assign children to rows
407- const rows = assignWrapRows(baseWidths, innerW, gap);
416+ const rows = assignWrapRows(baseWidths, innerW, itemGap);
408417
409418 // Phase 3: Layout each row independently
410419 const layoutChildren: LayoutNode[] = [];
@@ -412,7 +421,7 @@ function layoutWrapHStack(
412421
413422 for (let ri = 0; ri < rows.length; ri++) {
414423 const rowIdx = requiredAt(rows, ri, "wrap row");
415- const rowGapTotal = gap * (rowIdx.length - 1);
424+ const rowGapTotal = itemGap * (rowIdx.length - 1);
416425 const rowAvail = innerW - rowGapTotal;
417426
418427 // Compute fixed and flex totals for this row
@@ -537,7 +546,7 @@ function layoutWrapHStack(
537546
538547 xOffset += childW;
539548 if (ci < rowIdx.length - 1) {
540- xOffset += gap;
549+ xOffset += itemGap;
541550 if (betweenGaps) {
542551 xOffset += requiredAt(betweenGaps, ci, "justified gap");
543552 }
@@ -609,7 +618,9 @@ function layoutNode(
609618
610619 // Gap
611620 const gap = props.gap ?? 0;
612- const totalGap = gap * (children.length - 1);
621+ const justify = props.justifyContent ?? "start";
622+ const mainAxisGap = getMainAxisGap(gap, justify);
623+ const totalGap = mainAxisGap * (children.length - 1);
613624 const mainAvail = (isVertical ? innerH : innerW) - totalGap;
614625
615626 // --- Measure phase: compute each child's main-axis and cross-axis size ---
@@ -738,7 +749,6 @@ function layoutNode(
738749 const remainingMain = Math.max(0, mainInner - totalContent);
739750
740751 // justifyContent: compute main-axis starting offset and per-gap extra space
741- const justify = props.justifyContent ?? "start";
742752 let mainStart = 0;
743753 let betweenGaps: number[] | null = null;
744754
@@ -780,7 +790,7 @@ function layoutNode(
780790
781791 mainOffset += info.mainSize;
782792 if (i < infos.length - 1) {
783- mainOffset += gap;
793+ mainOffset += mainAxisGap;
784794 if (betweenGaps) {
785795 mainOffset += requiredAt(betweenGaps, i, "justified gap");
786796 }