Open In App

Tailwind CSS Justify Items

Last Updated : 23 Mar, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

This class accepts two values in tailwind CSS. It is the alternative to the CSS justify-items property. This class is used for controlling how grid items are aligned along their inline axis.

Justify Items:

  • justify-items-auto 
  • justify-items-start 
  • justify-items-end 
  • justify-items-center 
  • justify-items-stretch 

justify-items-auto: This class is used to justify grid items automatically on their inline axis.

Syntax:

<element class="justify-items-auto">...</element>

Example:

HTML




<!DOCTYPE html> 
<head>     
    <link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" 
          rel="stylesheet"
</head
  
<body class="text-center"
    <h1 class="text-green-600 text-5xl font-bold">
        GeeksforGeeks
    </h1
    <b>Tailwind CSS Justify Items Class</b
    <div id="main" class="grid justify-items-auto grid-cols-2"
        <div class="bg-green-500 rounded-lg m-4 h-12">1</div
        <div class="bg-green-500 rounded-lg m-4 h-12">2</div
        <div class="bg-green-500 rounded-lg m-4 h-12">3</div
        <div class="bg-green-500 rounded-lg m-4 h-12">4</div>
        <div class="bg-green-500 rounded-lg m-4 h-12">5</div
        <div class="bg-green-500 rounded-lg m-4 h-12">6</div>
    </div
</body
  
</html>


Output:

justify-items-start: This class is used to justify grid items against the start of their inline axis.

Syntax:

<element class="justify-items-start">...</element>

Example:

HTML




<!DOCTYPE html> 
<head>    
    <link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" 
    rel="stylesheet"
</head
  
<body class="text-center"
    <h1 class="text-green-600 text-5xl font-bold">
        GeeksforGeeks
    </h1
    <b>Tailwind CSS Justify Items Class</b
    <div id="main" class="grid justify-items-start grid-cols-2"
        <div class="bg-green-500 rounded-lg m-4 w-20 h-12">1</div
        <div class="bg-green-500 rounded-lg m-4 w-20 h-12">2</div
        <div class="bg-green-500 rounded-lg m-4 w-20 h-12">3</div
        <div class="bg-green-500 rounded-lg m-4 w-20 h-12">4</div>
        <div class="bg-green-500 rounded-lg m-4 w-20 h-12">5</div
        <div class="bg-green-500 rounded-lg m-4 w-20 h-12">6</div>
    </div
</body
</html>


Output:

justify-items-end: This class is used to justify grid items against the end of their inline axis.

Syntax:

<element class="justify-items-end">...</element>

Example:

HTML




<!DOCTYPE html> 
<head>    
    <link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" 
          rel="stylesheet"
</head
  
<body class="text-center"
    <h1 class="text-green-600 text-5xl font-bold">
        GeeksforGeeks
    </h1
    <b>Tailwind CSS Justify Items Class</b
    <div id="main" class="grid justify-items-end grid-cols-2"
        <div class="bg-green-500 rounded-lg m-4 w-20 h-12">1</div
        <div class="bg-green-500 rounded-lg m-4 w-20 h-12">2</div
        <div class="bg-green-500 rounded-lg m-4 w-20 h-12">3</div
        <div class="bg-green-500 rounded-lg m-4 w-20 h-12">4</div>
        <div class="bg-green-500 rounded-lg m-4 w-20 h-12">5</div
        <div class="bg-green-500 rounded-lg m-4 w-20 h-12">6</div>
    </div
</body
  
</html>


Output:

justify-items-center: This class is used to justify grid items along their inline axis.

Syntax:

<element class="jjustify-items-center">...</element>

Example:

HTML




<!DOCTYPE html> 
<head>    
    <link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" 
     rel="stylesheet"
</head
  
<body class="text-center"
    <h1 class="text-green-600 text-5xl font-bold">
        GeeksforGeeks
    </h1
    <b>Tailwind CSS Justify Items Class</b
    <div id="main" class="grid justify-items-center grid-cols-2"
        <div class="bg-green-500 rounded-lg m-4 w-20 h-12">1</div
        <div class="bg-green-500 rounded-lg m-4 w-20 h-12">2</div
        <div class="bg-green-500 rounded-lg m-4 w-20 h-12">3</div
        <div class="bg-green-500 rounded-lg m-4 w-20 h-12">4</div>
        <div class="bg-green-500 rounded-lg m-4 w-20 h-12">5</div
        <div class="bg-green-500 rounded-lg m-4 w-20 h-12">6</div>
    </div
</body
  
</html>


Output:

justify-items-stretch: This class is used to stretch items along their inline axis.

Syntax:

<element class="justify-items-stretch">...</element>

Example:

HTML




<!DOCTYPE html> 
<head>    
    <link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" 
          rel="stylesheet"
</head
  
<body class="text-center"
    <h1 class="text-green-600 text-5xl font-bold">
        GeeksforGeeks
    </h1
    <b>Tailwind CSS Justify Items Class</b
    <div id="main" class="grid justify-items-stretch grid-cols-2"
        <div class="bg-green-500 rounded-lg m-4 h-12">1</div
        <div class="bg-green-500 rounded-lg m-4 h-12">2</div
        <div class="bg-green-500 rounded-lg m-4 h-12">3</div
        <div class="bg-green-500 rounded-lg m-4 h-12">4</div>
        <div class="bg-green-500 rounded-lg m-4 h-12">5</div
        <div class="bg-green-500 rounded-lg m-4 h-12">6</div>
    </div
</body
  
</html>


Output:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads