Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS justify-content property

CSS justify-content property

CSS Reference Manual CSS Reference Manual

Example

Within a flexbox object, leave space around the

items in the element:

div

{

display:

flex

;

justify-content:

space-around

;

}

Try it »


Browser support

The numbers in the table indicate the version number of the first browser that supports this property.

The number immediately following -webkit-, -ms-, or -moz- is the first version that supports the prefixed property.

property
justify-content 29.0
21.0 -webkit- 11.0 28.0
18.0 -moz- 9.0
6.1 -webkit- 17.0

Definition and Usage

justify-content is used to set or retrieve the alignment of flexbox items along the main axis (horizontal axis).

**Tip:** Use the align-content property to align items on the cross axis (vertical).

Default value: flex-start
Inherited: No
Animatable: No. See Animatable.
Version: CSS3
JavaScript syntax: object.style.justifyContent="space-between" Try it

/* Alignment */

justify-content

:

center

;

   

/* Center alignment */

justify-content

:

start

;

     

/* Align from the start of the line */

justify-content

:

end

;

       

/* Align from the end of the line */

justify-content

:

flex-start

;

/* Align from the starting position at the beginning of the line */

justify-content

:

flex-end

;

 

/* Align from the position at the end of the line */

justify-content

:

left

;

     

/* One next to another at the left edge of the alignment container */

justify-content

:

right

;

     

/* Elements aligned one next to another based on the right edge of the container, */

/* Baseline alignment */

justify-content

:

baseline

;

justify-content

:

first

baseline

;

justify-content

:

last

baseline

;

/* Distribute flex items */

justify-content

:

space-between

;

 

/* Distribute each element evenly,
                                   with the first element placed at the start and the last element at the end */

justify-content

:

space-around

;

 

/* Distribute each element evenly,
                                   with the same space distributed around each element */

justify-content

:

space-evenly

;

 

/* Distribute each element evenly,
                                   with equal spacing between each element */

justify-content

:

stretch

;

     

/* Distribute each element evenly,
                                   'auto'-sized elements are stretched to fit the size of the container */

/* Overflow alignment */

justify-content

:

safe

center

;

justify-content

:

unsafe

center

;

/* global values */

justify-content

:

inherit

;

justify-content

:

initial

;

justify-content

:

unset

;


CSS Syntax

justify-content: flex-start|flex-end|center|space-between|space-around|initial|inherit;

Attribute values

Value Description Testing
flex-start Default value. Items are aligned from the starting position at the beginning of the line. Test »
flex-end Aligned from the position at the end of the line. Test »
center Center aligned. Test »
space-between Distribute each element evenly, with the first element placed at the start and the last element at the end. Test »
space-evenly Distribute each element evenly, with equal spacing between each element. Test »
space-around Distribute each element evenly, with the same space distributed around each element. Test »
initial Sets this property to its default value. See initial. Test »
inherit Inherits this property from its parent element. See inherit.

Related Articles

CSS Reference Manual:align-content Property

CSS Reference Manual:align-items Property

CSS Reference Manual:align-self Property

CSS Reference Manual CSS Reference Manual