Skip to content
Justice Tech School

Flex Item Properties

flex-grow lets an item take extra space, flex-shrink lets it give space up when tight, and flex-basis sets its starting size. The shorthand flex: 1 means grow equally and share the space. order changes visual position without touching the HTML, and align-self overrides alignment for one item.

Use margin-left: auto on a flex item to push it (and the following items) to the far end.

Example
<style>
  .bar { display: flex; gap: 8px; align-items: center; background: #f1f5f9; padding: 8px; }
  .bar div { background: #a5b4fc; padding: 10px; border-radius: 6px; }
  .grow { flex: 1; }
  .last { order: -1; align-self: flex-start; }
  .push { margin-left: auto; }
</style>
<div class="bar">
  <div>Fixed</div>
  <div class="grow">Grows to fill</div>
  <div class="push">Pushed right</div>
  <div class="last">First by order</div>
</div>

Exercise

Make the item grow to fill the free space.

.main {
  flex: ;
}

Quiz Test

What does the order property change?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.