justify-items property sets the default
justify-self for all child boxes (including anonymous boxes) participating in this box's formatting context.
This property can be overriden at the child level using the
justify-self property against the child box.
These values are explained below.
This keyword causes the value to effectively inherit into descendants. It can only be combined with the
- If the inherited value of
legacykeyword, auto computes to the inherited value. Otherwise this value computes to
- Represents the "default" alignment for the layout mode.
lastvalues give a box a baseline alignment preference. The default value is
- Computes to
- Aligns the alignment baseline of the box's first baseline set with the corresponding baseline of its alignment context. The fallback alignment for
- Aligns the alignment baseline of the box's last baseline set with the corresponding baseline of its alignment context. The fallback alignment for
These values deal with cases where the alignment subject is larger than the alignment container. In other words, the content will overflow, potentially causing a loss of data.
- If the size of the alignment subject overflows the alignment container, the alignment subject is instead aligned as if the alignment mode were
- The given alignment value is honored, regardless of the relative sizes of the alignment subject and alignment container.
- Centers the alignment subject within its alignment container.
- Aligns the alignment subject to be flush with the alignment container's start edge in the appropriate axis.
- Aligns the alignment subject to be flush with the alignment container's end edge in the appropriate axis.
- Aligns the alignment subject to be flush with the edge of the alignment container corresponding to the alignment subject's start side in the appropriate axis.
- Aligns the alignment subject to be flush with the edge of the alignment container corresponding to the alignment subject's end side in the appropriate axis.
- Aligns the alignment subject to be flush with the alignment container's line-left edge. If the property's axis is not parallel with the inline axis, this value behaves as
- Aligns the alignment subject to be flush with the alignment container's line-right edge. If the property's axis is not parallel with the inline axis, this value behaves as
- Only used in flex layout. The cross-start margin edge of the flex item is placed flush with the cross-start edge of the line.
- Only used in flex layout. The cross-end margin edge of the flex item is placed flush with the cross-end edge of the line.
In addition, all CSS properties also accept the following CSS-wide keyword values as the sole component of their property value:
- Represents the value specified as the property's initial value.
- Represents the computed value of the property on the element's parent.
- This value acts as either
initial, depending on whether the property is inherited or not. In other words, it sets all properties to their parent value if they are inheritable or to their initial value if not inheritable.
Basic Property Information
- Initial Value
- Applies To
- All elements
Working Example within an HTML Document
This example uses CSS grid. It aligns grid items within a grid container.
For maximum browser compatibility many web developers add browser-specific properties by using extensions such as
-webkit- for Safari, Google Chrome, and Opera (newer versions),
-ms- for Internet Explorer,
-moz- for Firefox,
-o- for older versions of Opera etc. As with any CSS property, if a browser doesn't support a proprietary extension, it will simply ignore it.
This practice is not recommended by the W3C, however in many cases, the only way you can test a property is to include the CSS extension that is compatible with your browser.
The major browser manufacturers generally strive to adhere to the W3C specifications, and when they support a non-prefixed property, they typically remove the prefixed version. Also, W3C advises vendors to remove their prefixes for properties that reach Candidate Recommendation status.
Many developers use Autoprefixer, which is a postprocessor for CSS. Autoprefixer automatically adds vendor prefixes to your CSS so that you don't need to. It also removes old, unnecessary prefixes from your CSS.
You can also use Autoprefixer with preprocessors such as Less and Sass.