Splitting a container down the middle
The goal is a container holding two sides of equal height, each taking exactly half the width, with a clear break between them. CSS offers several routes to that result, each with its own trade-offs for content, flow and browser support.
Purely visual approaches
Background gradient
A single element can be made to look like two halves by painting a gradient in which the color stops meet with zero space in the middle rather than fading from one color to the other. Half the background is one color, half is the other.
.container {
background: linear-gradient(
to right,
#ff9e2c 0%,
#ff9e2c 50%,
#b6701e 50%,
#b6701e 100%
);
}
This requires only one container, but filling both sides with content means falling back on floats or another layout method anyway.
Absolute positioning
Two child containers are placed inside a parent, positioned absolutely, and split 50/50 with percentages before backgrounds are applied. Unlike the gradient trick, each side is a real container that can hold its own content.
The drawback is that absolute positioning takes elements out of the document flow, so pushing content down below the pair becomes difficult. The parent also needs a fixed height, which is problematic once the content changes.
Flow-based layout methods
Fake tables
Applying display: table; to the semantic parent and display: table-cell; to the children produces the layout with no table markup at all. The display values can be swapped at breakpoints so the sides stack on smaller screens, and because display: table; and friends are supported back to IE 8 and old Android, the technique is safe in practice.
Floats
Floating the containers side by side avoids the messiness of absolute positioning. Even heights do not come for free, though: the example sets heights explicitly, while other options are the gradient trick so the sides merely look even, or negative-margin techniques. The floats also need clearing on the parent to keep the document flow correct.
Inline-block
display: inline-block removes the need to clear floats, at the cost of whitespace sensitivity: any break or space between the two elements in the HTML renders as a literal space, which pushes the second half down. The heights must again be set explicitly, since inline-block does nothing to equalize them. Other approaches exist for the spacing problem.
Modern layout modules
Flexbox
Making the parent a flex container gives the children equal shares of the space with no widths or heights to declare — the defaults, flex-direction: row; and align-items: stretch;, are already what the layout needs. Setting flex: 1; on the sides guarantees the even split. Support starts at IE 10 and up, and prefixes and values may be needed for the best coverage. The demo also makes each side a flex container to center its content vertically and horizontally.
Grid
CSS Grid Layout behaves like the table and flexbox methods merged: a container is defined and split into columns and cells that child elements fill flexibly.
CSS Anchor Positioning
Anchor Positioning began rolling out in 2024 and full browser support is still pending. It "attaches" one element to another — even when the two are unrelated in the markup — by registering one element as the anchor and another as its target, which is effectively pinned to the anchor at a position we control.
.anchor {
anchor-name: --anchor;
}
.target {
anchor-position: --anchor;
position: absolute; /* required */
}
With the .anchor element and its relationship to .target established, the target is told which side of the anchor to pin to.
.anchor {
anchor-name: --anchor;
}
.target {
anchor-position: --anchor;
position: absolute; /* required */
left: anchor(right);
}


