What does justify-content CSS property do and what values can it have?
Experience Level: Junior
Tags: CSSFlexbox
Answer
The CSS property justify-content
defines how the flex items within a flex container will be justified.
The justification is always done on the main axis. So for the horizontal orientation of a flex container the flex-start will justify items to left, flex-end will justify items to right.
flex-start
- justifies the content to left for horizontal orientation or to top for vertical orientationflex-end
- justifies the content to right for horizontal orientation or to bottom for vertical orientationcenter
- justifies the content to centerspace-between
- when there are multiple flex items in a flex container, they will be justified evenly, however, the first and last item won't have space on their outer edgesspace-around
- when there are multiple flex items in a flex container, they will be justified evenly.
CSS
div {
display: flex;
justify-content: flex-start;
}
Related Flexbox job interview questions
What CSS property does the value flex-end belong to and when would you use it?
CSSFlexbox JuniorUsing Flexbox, how can you align elements to right?
CSSFlexbox JuniorHow do you turn a html element into a flex container?
CSSFlexbox JuniorWhat is a relation between flex container and flex item?
CSSFlexbox JuniorWhat is a flex item and what is its job?
CSSFlexbox Junior