flex-wrap: wrap; do in a flex container?flex-wrap: wrap; on flex items inside a flex container.The flex-wrap: wrap; property allows flex items to wrap onto multiple lines when they can't fit in a single line. Without it, items stay on one line and may shrink.
div.container { display: flex; /* Which line below is correct? */ }
flex-wrap and the value to allow wrapping is wrap.The correct syntax to allow flex items to wrap is flex-wrap: wrap;. Other options are invalid CSS or disable wrapping.
div.container { display: flex; flex-wrap: wrap; width: 300px; border: 1px solid black; } div.item { flex: 0 0 140px; height: 50px; background-color: lightblue; margin: 5px; }
Each item is 140px wide plus margin, so only two fit per 300px container width. Because flex-wrap: wrap; is set, items wrap to the next line after two.
If two items fit per line, items from the third onward wrap to the next line. The selector :nth-child(n+3) selects items from the third child onward.
flex-wrap: wrap; affect keyboard navigation and accessibility?Keyboard navigation follows the DOM order. When using flex-wrap: wrap;, keeping the DOM order consistent with visual order ensures logical tabbing and better accessibility.