Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

flex-basis

The starting size of a flex item along the main axis, before free space is shared.

Syntax

flex-basis: value;

Values

ParameterTypeDescription
lengthlengthA size: `200px`, `10rem`.
%percentageA percentage of the container.
autokeywordUses `width` (or `height` in a column), otherwise the content size (the default).

Examples

Different starting sizes:

<style>
  .row { display: flex; gap: 6px; }
  .row div { padding: 6px; background: peachpuff; }
</style>
 
<div class="row">
  <div style="flex-basis: 100px;">100px</div>
  <div style="flex-basis: 50%;">50%</div>
</div>

Notes

In a row flex-basis works like width, in a column like height. It is usually set through the flex shorthand.

See also

  • flex — A shorthand for how a flex item grows, shrinks and what size it starts from.
  • flex-grow — How much of the free space a flex item takes.
  • width — The width of an element.

Related recipes

In the tutorial

  • Flex items — How to control individual items in flexbox — flex-grow, flex-shrink, flex-basis, the flex shorthand, align-self, order and margin auto.

Thanks for reading!

Donate to the site — we work hard for you.