justify-content

  • Revision slug: Web/CSS/justify-content
  • Revision title: justify-content
  • Revision id: 393753
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment +Tag(NeedsExample) ...etc.Moved From CSS/justify-content to Web/CSS/justify-content

Revision Content

{{CSSRef}}

Summary

The CSS justify-content property defines how a browser distributes available space between and around elements when aligning flex items in the main-axis of the current line. The alignment is done after the lengths and auto margins are applied, meaning that, if there is at least one flexible element, with {{cssxref("flex-grow")}} different than 0, it will have no effect as there won't be any available space.

Do not assume that this property will only apply on flex containers in the future and therefore do not simply hide it by setting another {{cssxref("display")}} value. The CSSWG is working into extending its usage to any block element. The draft specification is still in its very early stage and isn't implement yet.

{{cssbox("justify-content")}}

See Using CSS flexible boxes for more properties and information.

Syntax

Formal syntax: {{csssyntax("justify-content")}}
justify-content: flex-start
justify-content: flex-end
justify-content: center
justify-content: space-between
justify-content: space-around

justify-content: inherit

Values

flex-start
The flex items are packed starting from the main-start. Margins of the first flex item is flushed with the main-start edge of the line and each following flex item is flushed with the preceding.
flex-end
The flex items are packed starting from the main-end. The margin edge of the last flex item is flushed with the main-end edge of the line and each preceding flex item is flushed with the following.
center
The flex items are packed toward the center of the line. The flex items are flushed with each other and aligned in the center of the line. Space between the main-start edge of the line and first item and between main-end and the last item of the line is the same.
space-between
Flex items are evenly distributed along the line. The spacing is done such as the space between two adjacent items is the same. Main-start edge and main-end edge are flushed with respectively first and last flex item edges.
space-around
Flex items are evenly distributed so that the space between two adjacent items is the same. The empty space before the first and after the last items equals half of the space between two adjacent items.

Examples

 

Specifications

Specification Status Comment
{{SpecName('CSS3 Flexbox', '#justify-content', 'justify-content')}} {{Spec2('CSS3 Flexbox')}}  

Browser compatibility

{{CompatibilityTable}}
Feature Firefox (Gecko) Chrome Internet Explorer Opera Safari
Basic support {{CompatGeckoDesktop("18.0")}} (behind a pref) [1]
{{CompatGeckoDesktop("20.0")}}
21.0{{property_prefix("-webkit")}} {{CompatNo}} 12.10 {{CompatNo}}
Feature Firefox Mobile (Gecko) Android IE Phone Opera Mobile Safari Mobile
Basic support {{CompatUnknown}} {{CompatUnknown}} {{CompatNo}} 12.10 {{CompatNo}}

[1] Firefox supports only single-line flexbox. To activate flexbox support, for Firefox 18 and 19, the user has to change the about:config preference "layout.css.flexbox.enabled" to true.

See also

Revision Source

<div>{{CSSRef}}</div>

<h2 id="Summary">Summary</h2>
<p>The <a href="/en-US/docs/CSS" title="CSS">CSS</a> <code>justify-content</code> property defines how a browser distributes available space between and around elements when aligning flex items in the main-axis of the current line. The alignment is done after the lengths and auto margins are applied, meaning that, if there is at least one flexible element, with {{cssxref("flex-grow")}} different than <code>0</code>, it will have no effect as there won't be any available space.</p>
<div class="note">
  <p>Do not assume that this property will only apply on flex containers in the future and therefore do not simply hide it by setting another {{cssxref("display")}} value. The CSSWG is working into <a href="http://dev.w3.org/csswg/css3-align/#justify-content" title="http://dev.w3.org/csswg/css3-align/#justify-content">extending its usage to any block element</a>. The draft specification is still in its very early stage and isn't implement yet.</p>
</div>
<div>{{cssbox("justify-content")}}</div>
<p>See <a href="/en-US/docs/CSS/Using_CSS_flexible_boxes" title="CSS/Using_CSS_flexible_boxes">Using CSS flexible boxes</a> for more properties and information.</p>


<h2 id="Syntax">Syntax</h2>
<pre class="twopartsyntaxbox">
<a href="/en-US/docs/CSS/Value_definition_syntax" title="CSS/Value_definition_syntax">Formal syntax</a>: {{csssyntax("justify-content")}}
</pre>
<pre>
justify-content: flex-start
justify-content: flex-end
justify-content: center
justify-content: space-between
justify-content: space-around

justify-content: inherit
</pre>

<h3 id="Values">Values</h3>
<dl>
  <dt><code>flex-start</code></dt>
  <dd>The flex items are packed starting from the <strong>main-start</strong>. Margins of the first flex item is flushed with the main-start edge of the line and each following flex item is flushed with the preceding.</dd>
  <dt><code>flex-end</code></dt>
  <dd>The flex items are packed starting from the <strong>main-end</strong>. The margin edge of the last flex item is flushed with the main-end edge of the line and each preceding flex item is flushed with the following.</dd>
  <dt><code>center</code></dt>
  <dd>The flex items are packed toward the center of the line. The flex items are flushed with each other and aligned in the center of the line. Space between the main-start edge of the line and first item and between main-end and the last item of the line is the same.</dd>
  <dt><code>space-between</code></dt>
  <dd>Flex items are evenly distributed along the line. The spacing is done such as the space between two adjacent items is the same. Main-start edge and main-end edge are flushed with respectively first and last flex item edges.</dd>
  <dt><code>space-around</code></dt>
  <dd>Flex items are evenly distributed so that the space between two adjacent items is the same. The empty space before the first and after the last items equals half of the space between two adjacent items.</dd>
</dl>


<h2 id="Examples">Examples</h2>
<pre>
&nbsp;</pre>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
  <thead>
    <tr>
      <th>Specification</th>
      <th>Status</th>
      <th>Comment</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>{{SpecName('CSS3 Flexbox', '#justify-content', 'justify-content')}}</td>
      <td>{{Spec2('CSS3 Flexbox')}}</td>
      <td>&nbsp;</td>
    </tr>
  </tbody>
</table>


<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>{{CompatibilityTable}}</div>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Firefox (Gecko)</th>
        <th>Chrome</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatGeckoDesktop("18.0")}} (behind a pref) [1]<br />
          {{CompatGeckoDesktop("20.0")}}</td>
        <td>21.0{{property_prefix("-webkit")}}</td>
        <td>{{CompatNo}}</td>
        <td>12.10</td>
        <td>{{CompatNo}}</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>Android</th>
        <th>IE Phone</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatNo}}</td>
        <td>12.10</td>
        <td>{{CompatNo}}</td>
      </tr>
    </tbody>
  </table>
</div>

<p>[1] Firefox supports only single-line flexbox. To activate flexbox support, for Firefox 18 and 19, the user has to change the about:config preference "layout.css.flexbox.enabled" to <code>true</code>.</p>


<h2 id="See_also">See also</h2>
<ul>
  <li><a href="/en-US/docs/CSS/Using_CSS_flexible_boxes" title="CSS/Using_CSS_flexible_boxes">Using CSS flexible boxes</a></li>
  <li>{{CSS_Reference:FlexBox}}</li>
</ul>
Revert to this revision