Open In App

CSS justify-self Property

The justify-self property is used to specify the alignment of a content’s position along with the appropriate axis in a CSS Grid.

Syntax:



justify-self: stretch | normal | auto | baseline | start | end | center | flex-start | flex-end | self-start | self-end | left | right | safe | unsafe

Property Values:



Example 1: In this example, justify-self is not used for the alignment.




<!DOCTYPE html>
<html>
<head>
    <style>
        article {
            font-family: sans-serif;
            background-color: green;
            display: grid;
            grid-template-columns: 1fr 1fr;
            grid-auto-rows: 70px;
            grid-gap: 30px;
            width: 700px;
            justify-items: stretch;
            border: solid;
            margin: 20%;
        }
 
        article span {
            background-color: white;
            color: green;
            margin: 2px;
            text-align: center;
            border: solid;
        }
 
        article,
        span {
            padding: 5px;
            border-radius: 3px;
            border: solid;
        }
    </style>
</head>
<body>
    <article class="container">
        <span>GEEKS</span>
        <span>FOR</span>
        <span>GEEKS</span>
        <span>ONLINE</span>
        <span>PORTAL</span>
    </article>
</body>
</html>

Output:

Example 2: In this example, a few of the justify-self values are used for the alignment.




<!DOCTYPE html>
<html>
<head>
    <style>
        article {
            font-family: sans-serif;
            background-color: green;
            display: grid;
            grid-template-columns: 1fr 1fr;
            grid-auto-rows: 70px;
            grid-gap: 30px;
            width: 700px;
            justify-items: stretch;
            border: solid;
            margin: 20%;
        }
 
        span:nth-child(2) {
            justify-self: start;
        }
 
        span:nth-child(3) {
            justify-self: center;
        }
 
        span:nth-child(4) {
            justify-self: end;
        }
 
        article span {
            background-color: white;
            color: green;
            margin: 2px;
            text-align: center;
            border: solid;
        }
 
        article,
        span {
            padding: 5px;
            border-radius: 3px;
            border: solid;
        }
    </style>
</head>
<body>
    <article class="container">
        <span>GEEKS</span>
        <span>FOR</span>
        <span>GEEKS</span>
        <span>ONLINE</span>
        <span>PORTAL</span>
    </article>
</body>
</html>

Output:

Supported Browsers:


Article Tags :