×

CSS Justify Content

Justify Content: These properties are applied for the alignment of items of a flexible box container if any item does not cover every available space over the main-axis, i.e., horizontally. Justify content property specifies how a browser classifies the area everywhere and between any content item.

It is not used to define items or containers inside any vertical axis. We can apply the property, i.e., align-items, for the alignment of the items vertically.

Syntax:

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

The flex-start value is used as a default value. Take a look at the following description:

ValuesDescription
centerAs the name suggests, it set-up an item’s position in the starting of a container.
flex-startIt is used as a default value and places an item at the starting of a container.
flex-endThis value is applied to set an item’s position at a container’s end.
space-aroundThese are applied to position any item along with parallel spacing to each other. The space-around value evenly classifies several items inside the line with the same space about them.
space-betweenBy using this value, an item is spaced evenly. Here, any first item (element) is at a starting, and any last item (element) is at an end.
space-evenlyIt places the items along with a parallel space. Although, the spacing about all the corners varies.

Take a look on the following illustration of these property values:

Example:

<!DOCTYPE html>  
<html>          
<head>  
<title>Justify Content in CSS </title>  
<style>    
#flexstart
{ 
 display: flex; 
 justify-content: flex-start; 
} 
#flexend
{ 
 display: flex; 
 justify-content: flex-end; 
}   
#cent
{ 
 display: flex; 
 justify-content: center; 
} 
#evenly
{ 
 display: flex; 
 justify-content: space-evenly; 
} 
#around
{ 
 display: flex; 
 justify-content: space-around; 
} 
#between
{ 
 display: flex; 
 justify-content: space-between; 
} 
.flex-item
{ 
 width: 50px; 
 height: 50px; 
 margin: 5px; 
 padding: 5px; 
 color: black; 
 font-size: 2em; 
 font-weight: bold; 
 text-align: center; 
 border: 1px solid black; 
 background-color: lightblue; 
} 
</style>  
</head>  
<body>
<div id="flexstart"> 
<h1>flex-start</h1> 
  <div class="flex-item">1</div> 
  <div class="flex-item">2</div> 
  <div class="flex-item">3</div> 
  <div class="flex-item">4</div> 
  <div class="flex-item">5</div> 
</div> 
<div id="flexend"> 
<h1>flex-end</h1> 
  <div class="flex-item">1</div> 
  <div class="flex-item">2</div> 
  <div class="flex-item">3</div> 
  <div class="flex-item">4</div> 
  <div class="flex-item">5</div> 
</div> 
<div id="cent"> 
<h1>center</h1> 
  <div class="flex-item">1</div> 
  <div class="flex-item">2</div> 
  <div class="flex-item">3</div> 
  <div class="flex-item">4</div> 
  <div class="flex-item">5</div>  
</div> 
<h1>space-evenly</h1> 
<div id="evenly"> 
  <div class="flex-item">1</div> 
  <div class="flex-item">2</div> 
  <div class="flex-item">3</div> 
  <div class="flex-item">4</div> 
  <div class="flex-item">5</div> 
</div> 
<h1>space-around</h1> 
<div id="around"> 
  <div class="flex-item">1</div> 
  <div class="flex-item">2</div> 
  <div class="flex-item">3</div> 
  <div class="flex-item">4</div> 
  <div class="flex-item">5</div> 
</div> 
<h1>space-between</h1> 
<div id="between"> 
  <div class="flex-item">1</div> 
  <div class="flex-item">2</div> 
  <div class="flex-item">3</div> 
  <div class="flex-item">4</div> 
  <div class="flex-item">5</div> 
</div> 
</body>  
</html> 

Output:

Justify Content

Related Topics

CSS Font

CSS Font: CSS has font property, which makes the text more attractive. We can alter the entire look by changing font color, font size, font style, and much more. In...

5 minutes read.

How to change the font in CSS

How to change the font in CSS? Professionals can't deny typefaces — how users organize and style text — if we want to completely customize the website's design. One may wish...

4 minutes read.

CSS Page-break-before Attribute

Page-break-before Attribute As its name implies, the page-break-before property is applied to include page break before any element, at the time of printing any document. It adds the page break before...

5 minutes read.

CSS Align

CSS Center Align Elements CSS center align is used to create align by using block element. You should specify margin: auto;properties. The element will take up the specified width and the remaining space....

2 minutes read.

CSS Transition

CSS Transition The transitions in CSS are influenced, included to modify the component from one design to another, without the use of the JavaScript or Flash. We should describe two of the...

2 minutes read.

CSS Sticky

CSS Sticky The position property in CSS is applied to set an element’s position. This property is also applied to position an element behind the other element. It is useful for...

1 minute read.

CSS Color Keywords

Here, we will discuss the following keywords: transparent currentcolor Inherit Transparent keyword A color can generally be made transparent by using the transparent keyword. Often it is used to for all intents...

4 minutes read.

CSS Table

CSS table provides better look and feel. There are various properties of CSS table that are given below. border border-collapse padding width height text-align color background-color CSS Table Border You can set...

4 minutes read.

CSS Overflow

CSS Overflow: The Overflow property in CSS is used to manage the content if it overflows from its container of the block level. We have seen that all the elements...

3 minutes read.

How to use google fonts in CSS

Fonts: - Fonts are used to make our website look more beautiful. Choosing appropriate font according to the web design or layout is also important. Many typefaces are accessible in...

4 minutes read.

Css Text Orientation

Introduction: The text-orientation property of CSS is used to specify the orientation of the text characters in the line of content. This property applies only with the vertical writing-mode and not...

4 minutes read.

CSS Margin

CSS Margin: The CSS margin property is employed to describe the space throughout the elements. It clears the range throughout the element. These properties do not have a background color...

2 minutes read.

CSS Display

CSS Display: The CSS Display property is one of an essential property among all other properties of CSS. The display property specifies how the HTML elements should be displayed on...

4 minutes read.

How to center a table in CSS

The table is used to store and arrange the data in tabular format. The data here can be of any form like text, image, links, etc. The table is made...

3 minutes read.

CSS Descendant Selector

Descendant Selector The Descendant selector in CSS is used to match the descendant components of a particular component. The term descendant depicts nested in whatever place, inside a DOM tree. This...

2 minutes read.

CSS Ellipsis

The CSS ellipsis kind of is the value that mostly is used by the property: text-overflow. Here, we will discuss the following: What is CSS Ellipsis? Syntax for CSS ellipsis How to...

3 minutes read.

CSS Word-spacing

Word-spacing The work-spacing property of CSS is applied to manage the space among the words. We can decrease or increase the space among the words by the use of this property. It...

3 minutes read.

CSS Padding

CSS Padding: The padding property in CSS is addressed to describe the space among the element border and the element content.This property is quite different from the margin property of...

2 minutes read.

CSS Word Wrap

Word Wrap in CSS: The word-wrap property in CSS is referred to break any lengthy word and wrap towards the next or following line. It is employed for preventing overflow...

1 minute read.

CSS Animation

CSS Animation: The animation property of CSS is applied to make animation over any webpage. It is used as the animation replacement made by JavaScript and Flash. Rules of CSS3 @keyframes The...

3 minutes read.