place-items
Quick Summary for place-items
The <a href="/en-US/docs/Web/CSS">CSS</a> <strong><code>place-items</code></strong> <a href="/en-US/docs/Web/CSS/Shorthandproperties">shorthand property</a> allows you to align items along both the block and inline directions at once (i.e. the <a href="/en-US/docs/Web/CSS/align-items"><code>align-items</code></a> and <a href="/en-US/docs/Web/CSS/justify-items"><code>justify-items</code></a> properties) in a relevant layout system such as <a href="/en-US/docs/Web/CSS/CSSGridLayout">Grid</a> or <a href="/en-US/docs/Web/CSS/CSSFlexibleBoxLayout">Flexbox</a>. If the second value is not set, the first value is also used for it.
Code Usage for place-items
<pre class="brush: css notranslate"><code><span class="token comment">/ Keyword values /</span> <span class="token property">place-items</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span> <span class="token property">place-items</span><span class="token punctuation">:</span> normal start<span class="token punctuation">;</span> <span class="token comment">/ Positional alignment /</span> <span class="token property">place-items</span><span class="token punctuation">:</span> center normal<span class="token punctuation">;</span> <span class="token property">place-items</span><span class="token punctuation">:</span> start legacy<span class="token punctuation">;</span> <span class="token property">place-items</span><span class="token punctuation">:</span> end normal<span class="token punctuation">;</span> <span class="token property">place-items</span><span class="token punctuation">:</span> self-start legacy<span class="token punctuation">;</span> <span class="token property">place-items</span><span class="token punctuation">:</span> self-end normal<span class="token punctuation">;</span> <span class="token property">place-items</span><span class="token punctuation">:</span> flex-start legacy<span class="token punctuation">;</span> <span class="token property">place-items</span><span class="token punctuation">:</span> flex-end normal<span class="token punctuation">;</span> <span class="token property">place-items</span><span class="token punctuation">:</span> left legacy<span class="token punctuation">;</span> <span class="token property">place-items</span><span class="token punctuation">:</span> right normal<span class="token punctuation">;</span> <span class="token comment">/ Baseline alignment /</span> <span class="token property">place-items</span><span class="token punctuation">:</span> baseline normal<span class="token punctuation">;</span> <span class="token property">place-items</span><span class="token punctuation">:</span> first baseline legacy<span class="token punctuation">;</span> <span class="token property">place-items</span><span class="token punctuation">:</span> last baseline normal<span class="token punctuation">;</span> <span class="token property">place-items</span><span class="token punctuation">:</span> stretch legacy<span class="token punctuation">;</span> <span class="token comment">/ Global values /</span> <span class="token property">place-items</span><span class="token punctuation">:</span> inherit<span class="token punctuation">;</span> <span class="token property">place-items</span><span class="token punctuation">:</span> initial<span class="token punctuation">;</span> <span class="token property">place-items</span><span class="token punctuation">:</span> revert<span class="token punctuation">;</span> <span class="token property">place-items</span><span class="token punctuation">:</span> unset<span class="token punctuation">;</span> </code></pre>
More Details for place-items
place-items
The CSS place-items shorthand property allows you to align items along both the block and inline directions at once (i.e. the align-items and justify-items properties) in a relevant layout system such as Grid or Flexbox. If the second value is not set, the first value is also used for it.
Constituent properties
This property is a shorthand for the following CSS properties:
align-items justify-items Syntax
/* Keyword values */ place-items: center; place-items: normal start; /* Positional alignment */ place-items: center normal; place-items: start legacy; place-items: end normal; place-items: self-start legacy; place-items: self-end normal; place-items: flex-start legacy; place-items: flex-end normal; place-items: left legacy; place-items: right normal; /* Baseline alignment */ place-items: baseline normal; place-items: first baseline legacy; place-items: last baseline normal; place-items: stretch legacy; /* Global values */ place-items: inherit; place-items: initial; place-items: revert; place-items: unset; Values
One of the following forms:
A singlealign-items value, which is used to set alignment in both block and inline directions. An align-items value, which sets alignment in the block direction, followed by a justify-items value, which sets alignment in the inline direction. Formal definition
| Initial value | as each of the properties of the shorthand:align-items: normaljustify-items: legacy |
|---|---|
| Applies to | all elements |
| Inherited | no |
| Computed value | as each of the properties of the shorthand:align-items: as specifiedjustify-items: as specified |
| Animation type | discrete |
Formal syntax
<'align-items'> <'justify-items'>?
Examples
Placing items in a flex container
In flexbox justify-self or justify-items do not apply, as on the main axis items are treated as a group. Therefore, the second value will be ignored.
#container { height:200px; width: 240px; place-items: stretch; /* You can change this value by selecting another option in the list */ background-color: #8c8c8c; display: flex; } ResultPlacing items in a grid container
The following grid container has items which are smaller than the grid areas they are placed in, therefore place-items will move them in the block and inline dimensions.
#gridcontainer { height:200px; width: 240px; place-items: stretch; /* You can change this value by selecting another option in the list */ background-color: #8c8c8c; display: grid; grid-template-columns: repeat(3, 1fr); } #gridcontainer > div { width: 50px; } ResultSpecifications
| Specification |
|---|
| CSS Box Alignment Module Level 3 # place-items-property |
See also
CSS Flexbox Guide: Basic Concepts of Flexbox CSS Flexbox Guide: Aligning items in a flex container CSS Grid Guide: Box alignment in CSS Grid layouts CSS Box Alignment Thealign-items property The align-self property The justify-items property The justify-self property Last modified: Feb 4, 2022, by MDN contributors
Select your preferred language English (US)Français日本語Русский中文 (简体) Change language