×

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 Images

Images in CSS: Images are a critical part of a web application. It includes various types of images in the web application that cannot be recommended. However, it is essential...

4 minutes read.

CSS Hover

CSS Hover: CSS :hover is used to select the various elements whenever we point the mouse on these elements. We can also use this selector on all the HTML elements,...

3 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 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.

CSS Outline

CSS Outline: This CSS property is quite similar to the border property of CSS. It eases us to design an additional border around the element to obtain visual attention. The...

4 minutes read.

What is CSS used for

What is CSS used for? CSS stands for Cascading Style Sheet. CSS is a stylesheet language for web pages. It specifies how a document created in a markup language looks and...

4 minutes read.

CSS Text-decoration

CSS Text-decoration: It is an essential property of CSS that is used to decorate the content of the text. It can add-on the lines above, under, and over the text....

3 minutes read.

CSS: nth-selector

CSS nth selector can be used to match an element according to its position regardless of its parent’s type. Here, n can be any number, formula, or a keyword. These selectors...

2 minutes read.

CSS Text-stroke

Text-stroke Text-stroke CSS property inserts the stroke to any text and gives a decoration option to them also. It describes the stroke’s width and color for various text characters. It is...

2 minutes read.

CSS Opacity

The CSS Opacity property is used to set the clarity of the image. It is defined as degree and specify the transparency of an element. Note: Opacity value will be less...

1 minute read.

CSS Form

You can create attractive HTML form by using CSS. Style input Fields The Input Field width properties are used to determine the width of the input field. Let us see an example of CSS style...

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.

What is a CSS File?

What is a CSS File and How to use it in Html? CSS: - CSS stands for Cascading Style Sheet. CSS is a file of style sheets that describe the presentation of...

4 minutes read.

CSS Inline

What is CSS? CSS is an acronym for Cascading Style Sheets. CSS is the language that we use to style an HTML document. It specifies how HTML components should appear. CSS...

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 @keyframes rule

CSS @keyframes rule It describes the rule of animation that depicts the properties of CSS for the components at every state along with the timeline. We may make the properties of complex...

4 minutes read.

How to change font size in CSS

How to change font size in CSS? Font Size: - Users may attract attention to content on a website page in various ways. One element in a sentence can be highlighted. You...

5 minutes read.

CSS Comments

CSS Comments: Generally, comments in CSS are used to describe our code. Further, it will provide support to many users who are concerned with the code. Somewhat, these are ignored...

2 minutes read.

CSS Border

CSS Border: The border property of CSS allows us to define the style, color, width, and radius of the element’s border. It is applied to various elements to set-up the...

4 minutes read.

CSS White Space Property

White Space in CSS The white-space CSS property describes how to show the content inside an element. This property is applied to manage a white space within an element. Values of White-space...

2 minutes read.