Role of CSS flex-wrap property no-wrap value

The CSS flex-wrap property with nowrap value prevents flex items from wrapping to new lines, keeping all items on a single row even if they overflow the container.

Syntax

selector {
    flex-wrap: nowrap;
}

Example

The following example demonstrates how nowrap forces all flex items to stay on one line −

<!DOCTYPE html>
<html>
<head>
<style>
    .mycontainer {
        display: flex;
        background-color: orange;
        flex-wrap: nowrap;
        width: 400px;
        border: 2px solid #333;
    }
    .mycontainer > div {
        background-color: white;
        text-align: center;
        line-height: 40px;
        font-size: 18px;
        width: 80px;
        margin: 5px;
        border: 1px solid #ddd;
    }
</style>
</head>
<body>
    <h3>Flex Items with nowrap</h3>
    <div class="mycontainer">
        <div>Item 1</div>
        <div>Item 2</div>
        <div>Item 3</div>
        <div>Item 4</div>
        <div>Item 5</div>
        <div>Item 6</div>
    </div>
</body>
</html>
An orange flex container with white bordered items arranged horizontally in a single row. The items may shrink or overflow the container width, but they remain on one line without wrapping to the next row.

Key Points

  • nowrap is the default value for flex-wrap
  • Items may shrink or overflow rather than wrap to new lines
  • Useful for creating horizontal scrolling layouts or single-row navigation

Conclusion

The flex-wrap: nowrap property ensures flex items stay on a single line, making it ideal for horizontal layouts where wrapping is not desired. This behavior helps maintain consistent row-based designs.

Updated on: 2026-03-15T12:55:26+05:30

289 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements