CSS <overflow-position> Data Type
The <overflow-position> data type is the keyword safe or unsafe, used with alignment properties to decide what happens when an item overflows.
Description
The <overflow-position> CSS data type represents the keywords safe and unsafe, which control what the box alignment properties do when an item is larger than the space it is being aligned in. It is used as an optional modifier in front of a position keyword in properties such as align-items, align-self, align-content, justify-content, justify-items and justify-self, for example align-items: safe center.
The problem it solves is data loss. When an item is centred inside a container that is too small for it, the item overflows equally on both sides. The part that sticks out on the start side (the top or left in most layouts) ends up outside the scrollable area, so the user cannot scroll to it and that content becomes unreachable. With safe, the browser notices the overflow and switches to start alignment instead, so the item overflows only on the end side, where it can still be scrolled into view.
unsafe tells the browser to always honour the requested alignment, even if that means some content becomes unreachable. If neither keyword is given, the browser uses a default that is somewhere between the two: it behaves like unsafe in most cases but may prevent content from overflowing a scroll container's start edge. Using safe explicitly is a simple way to make centred layouts robust when content size is unknown, such as with user-generated text or translated labels.
Examples:
/* Centre items, but fall back to start if they overflow */
.toolbar {
display: flex;
justify-content: safe center;
overflow-x: auto;
}
/* Vertically centred column that never hides its top */
.panel {
display: flex;
flex-direction: column;
align-items: safe center;
}
/* Explicitly keep the requested alignment */
.hero-title {
justify-self: unsafe center;
}
The <overflow-position> keywords can only be combined with <content-position> and <self-position> values such as center, start and end; they cannot be used with normal, stretch or baseline values.
Interactive Demo
Syntax
<overflow-position> = unsafe | safe
Values
- safeIf the item overflows the alignment container, the item is aligned as if the alignment were start, so that no content is pushed out of reach.
- unsafeThe requested alignment is always honoured, even if the item overflows the alignment container and some content becomes unreachable.
Example
Browser Support
The following information will show you the current browser support for the CSS overflow-position data type. Hover over a browser icon to see the version that first introduced support for this CSS data type.
Desktop





Tablets & Mobile





