The flex value of space-evenly doesn't affect the width of flex content, it only relate to white space. So by default all elements start in a flexbox with a width of auto (ie. their default width assuming nothing is declared) then flex shrinks them to fit if they would overflow. Space-evenly simly means once everything is there, any unused space is shared evenly between each item. In your case you have a div to house the image, divs are block elements (meaning they default to 100% of their parent width). The other elements have their width defined by content, so everything else takes up a width it needs as determined by length of content. Then the div tries to be 100% but flex shrinks it to fit, therefore it takes all remaining space... a close to 100% as will fit. This leaves no white space for space evenly to affect. So in short, even though you are using flexbox you still need a width on the image div, or a flex value on it. Answer from be_my_plaything on reddit.com
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Reference › Properties › justify-content
justify-content - CSS | MDN
The CSS justify-content property defines how the browser distributes space between and around content items along the main axis of a flex container and the inline axis of grid and multicol containers.
🌐
Bootstrap
getbootstrap.com › docs › 4.0 › utilities › flex
Flex · Bootstrap
Use justify-content utilities on flexbox containers to change the alignment of flex items on the main axis (the x-axis to start, y-axis if flex-direction: column). Choose from start (browser default), end, center, between, or around.
Discussions

why is my justify-content: space-between not working on flex items?
The flex value of space-evenly doesn't affect the width of flex content, it only relate to white space. So by default all elements start in a flexbox with a width of auto (ie. their default width assuming nothing is declared) then flex shrinks them to fit if they would overflow. Space-evenly simly means once everything is there, any unused space is shared evenly between each item. In your case you have a div to house the image, divs are block elements (meaning they default to 100% of their parent width). The other elements have their width defined by content, so everything else takes up a width it needs as determined by length of content. Then the div tries to be 100% but flex shrinks it to fit, therefore it takes all remaining space... a close to 100% as will fit. This leaves no white space for space evenly to affect. So in short, even though you are using flexbox you still need a width on the image div, or a flex value on it. More on reddit.com
🌐 r/csshelp
3
1
January 20, 2024
css - Flexbox: justify-content: space-between? - Stack Overflow
How do i make use of justify-content: space-between;? I need space between 2 articles in a section. And space between an img and a div in each article. How it currently looks like and... It sh... More on stackoverflow.com
🌐 stackoverflow.com
html - How to justify content with space-between AND have everything centered? - Stack Overflow
I'm running into a problem with flexbox. I have a div that has a max-width of 920px. I want the boxes of content to fill up the div from left to right to the max possible width, with everything ha... More on stackoverflow.com
🌐 stackoverflow.com
Justify content: space-between; is not working. please explain
I am trying to build a portfolio but when I write justify content: space-between; inside nav tag and it’s not working , so to check I am not making errors I used another property justify content: flex-end ; and that is working perfectly! so please explain how can I use justify content: ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
0
November 16, 2020
🌐
W3Schools
w3schools.com › cssref › css3_pr_justify-content.php
CSS justify-content property
justify-content: flex-start|flex-end|center|space-between|space-around|space-evenly|initial|inherit;
🌐
Tailwind CSS
tailwindcss.com › docs › justify-content
justify-content - Flexbox & Grid - Tailwind CSS
Use the justify-between utility to justify items along the container's main axis such that there is an equal amount of space between each item:
🌐
Bootstrap Shuffle
bootstrapshuffle.com › classes › flexbox › justify-content-*-between
justify-content-*-between - Bootstrap CSS class
<div class="d-flex justify-content-between"> <div class="p-2">Flex item 1</div> <div class="p-2">Flex item 2</div> <div class="p-2">Flex item 3</div> </div> <!-- responsive variations --> <div class="d-flex justify-content-sm-between">...</div> <div class="d-flex justify-content-md-between">...</div> <div class="d-flex justify-content-lg-between">...</div> <div class="d-flex justify-content-xl-between">...</div>Copy code
🌐
Bootstrap
getbootstrap.com › docs › 5.0 › utilities › flex
Flex · Bootstrap v5.0
Use justify-content utilities on flexbox containers to change the alignment of flex items on the main axis (the x-axis to start, y-axis if flex-direction: column). Choose from start (browser default), end, center, between, around, or evenly.
Find elsewhere
🌐
Reddit
reddit.com › r/csshelp › why is my justify-content: space-between not working on flex items?
r/csshelp on Reddit: why is my justify-content: space-between not working on flex items?
January 20, 2024 -

>> https://codepen.io/coderr11/pen/rNRwVmy

My code pen is above.

header is the parent, where i have placed: display: flex, align-items: center, and justify-content: space-evenly on it.

The child elements of it are .logo-image, .navbar, .btn and .fas - However, .logo-image takes up most of the width as seen by the red background and other flex items are squished to the left and are spaced-evenly. I can define a width on the .logo-image, but why is the default nature of it takes so much space compared to the other flex items?

Thank you

Top answer
1 of 2
2

justify-content: space-between will automatically fill the space between the elements on the flex-axis. This means that 1. you have no control over the amount of space between the elements, the browser will calculate and fill as it sees fit; 2. only the space on the flex-axis (default: row; x-axis) is filled so the space below your first row is not filled automatically.

The solution is to go back to good ol' margins. Do note that margin behaves slightly different on flex items, i.e. margin: auto will fill the available space with a margin.

/* === RESERVATION === */
.reservation {
  flex-direction: row-reverse;
}


/* === FLEXCONTAINER === */

.flexcontainer {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-wrap: wrap;
}


.flexcontainer p {
  width: 500px;
}

.flexcontainer article {
  display: flex;
}

.flexcontainer article img {
  width: 500px;
  margin: 24px;
  margin-left: 0;
}

.flexcontainer article:nth-child(even) img {
  margin: 24px;      
  margin-right: 0;
}
<section class="flexcontainer">
  <article class="beliefs">
    <img src="https://via.placeholder.com/500" alt="Our beliefs image" title="Our beliefs">
    <div>
      <h3>Our beliefs</h3>
      <p>When eating...</p>
      <p>We know...</p>
    </div>
  </article>
  <article class="reservation">
    <img src="https://via.placeholder.com/500" alt="reservation image" title="Reservation">
    <div>
      <h3>Reservation</h3>
      <p>To fully...</p>
      <p>This way...</p>
    </div>
  </article>
</section>

2 of 2
1

I would just add some padding.

/* === BELIEFS === */
.beliefs {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
}

/* === RESERVATION === */
.reservation {
    display: flex;
    flex-direction: row-reverse;
    justify-content: space-between;
}

/* ==== SLOGAN === */
.slogan {
    font-size: 1.4rem;
    margin-bottom: 55px;
}

/* === FLEXCONTAINER === */
.flexcontainer {
    display: flex;
    flex-direction: row;
    justify-content: center;
    flex-wrap: wrap;
}
section.flexcontainer p {
    width: 500px;
}
section.flexcontainer img {
    width: 500px;
    height:375px;
}
section.flexcontainer article:nth-child(even) img {
    padding-left:25px;
    padding-bottom:25px;
}
section.flexcontainer article:nth-child(odd) img {
    padding-right:25px;
    padding-bottom:25px;
}
<section class="flexcontainer">
    <article class="beliefs">
        <img src="https://media.wired.com/photos/5926db217034dc5f91becd6b/master/w_1904,c_limit/so-logo-s.jpg" alt="Our beliefs image" title="Our beliefs">
        <div>
            <h3>Our beliefs</h3>
            <p>When eating is motivated by pleasure, rather than hunger. A bit of italian tradition in the middle of
                the
                modern
                world. A combination of traditional craftsmanship and the quality of “made in italy”.
            </p>
            <p>
                We know your time is money. The spaces are reduced in this modern world. To meet your desires, in
                every
                time and
                place, there we are that bring you a little moment of pleasure through spaces of your life.
            </p>
        </div>
    </article>
    <article class="reservation">
        <img src="https://media.wired.com/photos/5926db217034dc5f91becd6b/master/w_1904,c_limit/so-logo-s.jpg" alt="reservation image" title="Reservation">
        <div>
            <h3>Reservation</h3>
            <p>
                To fully enjoy this experience you can call us on 646-755-8939 to book you table between 5.00
                pm-11.30
                pm
                (between
                11.30 am-11.30 pm on weekend).
            </p>
            <p>
                This way we can reserve you a special spot in our warm italian atmosphere. We advise to call upfront
                for
                any large
                group
            </p>
        </div>
    </article>
</section>

Edit: I changed the css so it's more dynamic if another article is added.

🌐
CSS-Tricks
css-tricks.com › almanac › properties › j › justify-content
justify-content | CSS-Tricks
September 22, 2022 - The justify-content property accepts five different values: flex-start (default): items are packed toward the start line ... space-between: items are evenly distributed in the line; first item is on the start line, last item on the end line
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Guides › Flexible_box_layout › Aligning_items
Aligning items in a flex container - CSS | MDN
In the example below, the value of justify-content is space-between. The available space after displaying the items is distributed between the items.
🌐
Webpixels
docs.webpixels.io › css › justify-content
Justify Content - Bootstrap 5
Align Content · Justify Content · Order · Sizing · Width · Height · Spacing · Margin · Padding · Gap · Effects · Opacity · Shadow · Transform · Transform · Origin · Scale · Rotate · Translate · Skew · Transition · Transition Property · Timing Function ·
🌐
freeCodeCamp
forum.freecodecamp.org › html-css
Justify content: space-between; is not working. please explain - HTML-CSS - The freeCodeCamp Forum
November 16, 2020 - I am trying to build a portfolio but when I write justify content: space-between; inside nav tag and it’s not working , so to check I am not making errors I used another property justify content: flex-end ; and that is working perfectly! so please explain how can I use justify content: ...
🌐
PureCode AI
blogs.purecode.ai › home › justify content css: empowering you to make beautiful layouts
Justify Content CSS: Empowering You to Make Beautiful Layouts - Blogs
September 15, 2025 - It adds consistent space between each adjacent pair of items, effectively pushing the items to the outer edges of the container while maintaining equal spacing between them. In essence, justify-content is a Flexbox property that governs the ...
🌐
freeCodeCamp
forum.freecodecamp.org › html-css
CSS Flexbox: Justify-content property not working - HTML-CSS - The freeCodeCamp Forum
Hello guys. I have been working on my Survey Form project since yesterday, trying to learn how to use CSS Flexbox. It’s been hard but rewarding up until a few hours ago when I ran into this problem: **<HTML>** <div id…
Published   January 12, 2019
🌐
W3Schools
w3schools.com › css › css3_flexbox_container.asp
CSS Flexbox Container
justify-content - Aligns the flex items when they do not use all available space on the main-axis (horizontally)
🌐
Ant Design
ant.design › components › flex
Flex - Ant Design
Set the gap between elements, which has three preset sizes: small, medium, and large. You can also customize the gap size. Wrap · Auto wrap line. combination · Nesting can achieve more complex layouts. horizontalvertical · Select justify : flex-start · center · flex-end ·
🌐
CSS-Tricks
css-tricks.com › a-quick-way-to-remember-difference-between-justify-content-align-items
A Quick Way to Remember the Difference Between `justify-content` and `align-items` | CSS-Tricks
April 5, 2018 - She said that justify-content positions elements across the horizontal axis because the word itself is longer than align-items. At first I thought this was a really silly idea but now this is how I remember it.