CSS place-self
The CSS place-self
property is a shorthand property for the align-self
and justify-self
properties.
The first value sets align-self
and the second value sets justify-self
. If only one value is provided, it sets both properties.
Syntax
These values are explained below.
Possible Values
auto
- Uses the value provided by the
justify-items
property on the parent container. If the element has no parent, then this value computes tonormal
. normal
- Represents the "default" alignment for the layout mode.
stretch
-
If the combined size of the alignment subjects is less than the size of the alignment container, any auto-sized alignment subjects have their size increased equally (not proportionally), while still respecting the constraints imposed by the
max-height
/max-width
properties (or equivalent functionality), so that the combined size exactly fills the alignment container.The default fallback alignment for this value is
flex-start
. baseline-position
-
The
first
andlast
values give a box a baseline alignment preference. The default value isfirst
.Values:
baseline
- Computes to
first baseline
. first baseline
- Aligns the alignment baseline of the box's first baseline set with the corresponding baseline of its alignment context. The fallback alignment for
first baseline
isstart
. last baseline
- Aligns the alignment baseline of the box's last baseline set with the corresponding baseline of its alignment context. The fallback alignment for
last baseline
isend
.
self-position
-
Possible values:
center
- Centers the alignment subject within its alignment container.
start
- Aligns the alignment subject to be flush with the alignment container's start edge in the appropriate axis.
end
- Aligns the alignment subject to be flush with the alignment container's end edge in the appropriate axis.
self-start
- 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.
self-end
- 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.
left
- 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
start
. right
- 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
start
. flex-start
- 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.
flex-end
- 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:
initial
- Represents the value specified as the property's initial value.
inherit
- Represents the computed value of the property on the element's parent.
unset
- This value acts as either
inherit
orinitial
, 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
auto
- Applies To
- Block-level boxes, absolutely-positioned boxes, and grid items
- Inherited?
- No
- Media
- Visual
- Animatable
- No
Example Code
Basic CSS
Working Example within an HTML Document
This example uses CSS grid. It aligns grid items within a grid container.
CSS Specifications
The place-self
property is defined in CSS Box Alignment Module Level 3 (W3C Working Draft).
Vendor Prefixes
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.