BY Ajay Singh8 Jul 2021 Edit
CSS: place-items
What is a place-items


The CSS place-items shorthand property allows you to align items along both the block and inline directions at once.

Are you working with Grid in CSS and confused about the content to place center? Let's understand how can we do this using align-items and with justify-items.

Example


<div class="box-1">
  <div>place-items</div>
</div>

.box-1 {
  display: grid;
  justify-items: center;
  align-items: center;
  border: 1px solid red;
  width: 200px;
  height: 200px;
}

Let's first understand what these two CSS properties does.

align-items

Aligns content along the vertical (column) axis.

justify-items

Aligns along the horizontal (row) axis.

Do you find it difficult to remember the align-items justify-items. Here, We have another great CSS property called place-items.

The place-items property in CSS is shorthand for the align-items and justify-items properties, combining them into a single declaration. A common usage is doing horizontal and vertical centering with Grid

Let's rewrite the above example using the single property place-items.

<div class="box-1">
  <div>place-items</div>
</div>


.box-1 {
  display: grid;
  place-items:center;
  border: 1px solid red;
  width: 200px;
  height: 200px;
}

No need to remember align-items justify-items. The place-items property accepts dual values, the first for align-items and the second for justify-items.

Another example

if you are working with justify items and align-items to place the item at the start like this:-

.box-1 {
   display:grid;
   justify-items:start;
   align-items:start.
}

This is equivalent to:

.box-1 {
  display:grid;
  place-items:start;
}

If only one value is provided, then it sets both properties.

What makes this property interesting is that it behaves differently based on the context it is used. For example, some values only apply to Flexbox and will not work in a Grid setting. Additionally, some values apply to the align-items property where others apply to the justify-items side.

Browser Support

  • Edge 79+ (post-Chromium)
  • Firefox 45+
  • Chrome 59+
  • Safari 11+

References

CSS Box Alignment Model Level 3

The official specification where the place-items property is initially defined.

Mozilla Developer Network

The Mozilla team’s documentation.

Box Alignment Cheat Sheet

Rachel Andrew’s outline is a super helpful resource for grasping alignment terms and their definitions.

Thank You.

BY Ajay Singh
LikeCommentSave
LikeCommentSaveShare
0
Categories
General
YantraJS
Developer Guides
Tutorials
Web Atoms Updates

POPULAR POSTS
17 Mar 2021
LATEST ACTIVITY
Simmi Kava
commented this post.
Simmi Kava
liked this post.
Show more
ARCHIVES
2024
2023
2022
2021
TAGS
javascript (56)
developer (25)
javascriptdeveloper (16)
Xamarin.Forms (16)
Html (14)
typescript (12)
webatoms (12)
xamarin (11)
coding (10)
web-atoms (10)
arrays (9)
android (8)
javascript-developer (8)
csharp (7)
dotnet (7)
css (6)
update (6)
dotnet-standard (5)
function (5)
iOS (5)
methods (4)




Web Atoms: JSX (TSX + TypeScript) for Xamarin.Forms, Hot Reload Your App in Production Environment

PlaygroundSamples Repository