CSS Flex Basis Calculator
Enter a container width, item count, and gap to get the exact flex-basis value and copy-ready CSS for your flexbox layout.
Container
The total inner width of the flex container (excluding padding).
px
Padding subtracts from the available width automatically.
Items & Gap
Output Options
Calculated Flex Basis
flex-basis
—
Pixel equivalent
—
Container
—
Items/row
—
Total gap
—
Generated CSS
/* Fill in the fields to generate CSS */
Visual Preview (proportional)
Showing 1 row(s) of 3 items.
Formula
flex-basis =
(containerWidth - gap × (n - 1)) / n
Summary
Enter a container width, item count, and gap to get the exact flex-basis value and copy-ready CSS for your flexbox layout.
How it works
- Enter the total width of your flex container in pixels (or use a percentage/custom value).
- Set the number of items you want per row.
- Enter the gap size (column-gap) between items in pixels.
- The calculator outputs the exact flex-basis value using the formula: (containerWidth - gap * (itemsPerRow - 1)) / itemsPerRow.
- Copy the generated CSS and paste it directly into your stylesheet.
Use cases
- Build a responsive card grid where exactly 3 or 4 cards sit side-by-side per row.
- Prototype product listing pages with a fixed number of items per row without using CSS Grid.
- Create equal-width nav tabs or button groups using flexbox.
- Verify that your flex-basis and gap combination does not accidentally cause wrapping.
- Convert a design mock with specific item counts into production-ready CSS values.
- Teach junior developers how flex-basis interacts with gap and container width.
Frequently Asked Questions
Last updated: 2026-07-01 ·
Reviewed by Nham Vu