This example shows a flex container with five items. The flex-wrap: wrap; property lets items move to the next line if they don't fit in the container's width. Try resizing the browser window to see the wrapping effect.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Flex Wrap Example</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 1rem;
}
.container {
display: flex;
flex-wrap: wrap;
gap: 1rem;
background-color: #f0f0f0;
padding: 1rem;
border: 2px solid #ccc;
max-width: 20rem;
}
.item {
background-color: #4a90e2;
color: white;
padding: 1rem;
flex: 0 0 8rem;
text-align: center;
border-radius: 0.5rem;
user-select: none;
}
</style>
</head>
<body>
<h1>Flex Wrap Example</h1>
<p>Resize the browser window to see items wrap to the next line.</p>
<section class="container" aria-label="Flex wrap container">
<div class="item" tabindex="0">Item 1</div>
<div class="item" tabindex="0">Item 2</div>
<div class="item" tabindex="0">Item 3</div>
<div class="item" tabindex="0">Item 4</div>
<div class="item" tabindex="0">Item 5</div>
</section>
</body>
</html>