惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

SecWiki News
SecWiki News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
博客园 - 叶小钗
S
SegmentFault 最新的问题
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
腾讯CDC
D
Darknet – Hacking Tools, Hacker News & Cyber Security
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
L
Lohrmann on Cybersecurity
量子位
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
J
Java Code Geeks
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
博客园 - 三生石上(FineUI控件)
Attack and Defense Labs
Attack and Defense Labs
AI
AI
The Cloudflare Blog
T
Tailwind CSS Blog
S
Schneier on Security
爱范儿
爱范儿
PCI Perspectives
PCI Perspectives
Stack Overflow Blog
Stack Overflow Blog
S
Secure Thoughts
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
The Exploit Database - CXSecurity.com
博客园 - 【当耐特】
V2EX - 技术
V2EX - 技术
S
Securelist
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
Help Net Security
Help Net Security
C
Cisco Blogs
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
K
Kaspersky official blog
T
The Blog of Author Tim Ferriss
G
Google Developers Blog
S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Simon Willison's Weblog
Simon Willison's Weblog

CSS-Tricks

pointer-events | CSS-Tricks What’s !important #15: Boundary-aware CSS, Time-based CSS, Full-bleed CSS, and More | CSS-Tricks Get Ready For the Powerful CSS border-shape Property! | CSS-Tricks What’s !important #14: Gap Decorations, random(), <select> field sizing, and More | CSS-Tricks The Shifting Line Between CSS States and JavaScript Events | CSS-Tricks translateZ() | CSS-Tricks translateY() | CSS-Tricks translateX() | CSS-Tricks translate() | CSS-Tricks Using Scroll-Driven Animations for Opposing Scroll Directions | CSS-Tricks A First Look at Scroll-Triggered Animations | CSS-Tricks The Siren Song of  ariaNotify() | CSS-Tricks Prop For That | CSS-Tricks What’s !important #13: @function, alpha(), CSS Wordle, and More | CSS-Tricks There’s no need to include ‘navigation’ in your navigation labels | CSS-Tricks Why Isn't My 3D View Transition Working? | CSS-Tricks Creating Memorable Web Experiences: A Modern CSS Toolkit | CSS-Tricks Scroll-Driven, Scroll-Triggered, Scroll States, and View Transitions | CSS-Tricks Another Stab at the Perfect CSS Pie Chart... Sans JavaScript! | CSS-Tricks offset-path | CSS-Tricks @custom-media | CSS-Tricks @function | CSS-Tricks ::search-text | CSS-Tricks Astro Markdown Component Utility for Any Framework | CSS-Tricks What’s !important #12: Safari Testing, ::checkmark, HTML Anchor Positioning, and More | CSS-Tricks Revealing Text With CSS letter-spacing | CSS-Tricks Technical Writing in the AI Age | CSS-Tricks Cross-Document View Transitions: Scaling Across Hundreds of Elements | CSS-Tricks The State of CSS Centering in 2026 | CSS-Tricks Stack Overflow: When We Stop Asking | CSS-Tricks Cross-Document View Transitions: The Gotchas Nobody Mentions | CSS-Tricks What’s !important #11: 3D Voxel Scenes, Flying Focus, CSS Syntaxes, and More | CSS-Tricks Computing and Displaying Discounted Prices in CSS | CSS-Tricks rotateX() | CSS-Tricks rotateY() | CSS-Tricks rotateZ() | CSS-Tricks rotate() | CSS-Tricks Soon We Can Finally Banish JavaScript to the ShadowRealm | CSS-Tricks Using CSS corner-shape For Folded Corners | CSS-Tricks contrast() | CSS-Tricks contrast-color() | CSS-Tricks hypot() | CSS-Tricks saturate() | CSS-Tricks
justify-self | CSS-Tricks
Juan Diego R · 2026-04-09 · via CSS-Tricks

The CSS justify-self property aligns an individual element, overriding its parent container’s justify-items value.

.container {
  display: grid;
  grid-template-columns: 2fr 1fr;
  justify-items: center; /* overrides this value */
}

.item:nth-child(1) {
  justify-self: start;
}

.item:nth-child(2) {
  justify-self: center;
}

.item:nth-child(3) {
  justify-self: end;
}

.item:nth-child(4) {
  justify-self: stretch;
}

Although justify-self works along the inline axis, its exact behavior depends on the context we are working on. It can be applied to grid items and, more recently, to block layouts as well as absolutely positioned elements.

While there are other types of display layouts (e.g., flex and table), the justify-self property only works in the grid, block, and absolutely-positioned layouts we mentioned.

The justify-self property is defined in the CSS Box Alignment Module Level 3 specification.

Syntax

justify-self: 	auto | <overflow-position>? [ normal | <self-position> | left | right ] | stretch | <baseline-position>

<overflow-position> = unsafe | safe
<self-position> = center | start | end | self-start | self-end | flex-start | flex-end
<baseline-position> = [ first | last ]? && baseline
  • Initial Value: auto
  • Applies to: block-level boxes, absolutely-positioned boxes, and grid items
  • Inherited: no
  • Percentages: N/a
  • Computed value: the specified keyword
  • Canonical order: per grammar
  • Animation type: discrete

Values

/* Initial Values */
justify-self: auto;
justify-self: normal;

/* <self-position> */
justify-self: center;
justify-self: start;
justify-self: end;

justify-self: left;
justify-self: right;

justify-self: self-start;
justify-self: self-end;

justify-self: flex-start; /* Same as start */
justify-self: flex-end; /* Same as end */

/* stretch */
justify-self: stretch;

/* <baseline-position> */
justify-self: baseline;
justify-self: first baseline;
justify-self: last baseline;

/* Anchor Positioning */
justify-self: anchor-center;

/* <overflow-position> */
justify-self: safe center;
justify-self: unsafe end;

/* Global values */
justify-self: inherit;
justify-self: initial;
justify-self: revert;
justify-self: revert-layer;
justify-self: unset;

auto (Default)

If the element doesn’t have a parent or is absolutely positioned, auto will default to normal. Otherwise, it will take the value defined by its parent justify-items property.

start, center and end

With align-self, we can place an element along its alignment container’s inline axis using startcenter and end. While center remains the same regardless of the writing mode, start and end depend on the alignment container’s writing mode.

For example, for left-to-right (ltr) containers, start places the item on the left, while for right-to-left (rtl) it’s on the right.

While flex-start and flex-end are valid values, since justify-self doesn’t work on flex items, they act the same as start and end, respectively.

self-start and self-end

Since start and end depend on the alignment container’s writing mode, we can instead use self-start and self-end to honor the element’s own writing mode.

left and right

If we want to place an item on one of two sides, regardless of the writing mode, we can use the left and right values. These align an element on their respective side.

stretch

With stretch, the element’s width increases to try and fill the alignment container, respecting relevant sizing properties like min-widthmax-width or width.

baseline, first baseline and last baseline

In typography, the baseline is an imaginary line upon where most characters in a line of text rest. These lines may vary from element to element depending on their font-familyfont-size or font-weight.

Source: Wikimedia Commons contributors

Using baseline-related values, we can align elements by their baseline. However, the baseline runs along the inline axis, so we usually align them perpendicularly along the block axis. For example, in English the baseline runs horizontally so we move it up or down to align it.

Since justify-self aligns items along the inline axis but baselines are aligned along the block axis, baseline values most times don’t have the expected result in justify-* properties.

In the case of grid elements, baseline works in one of two ways:

  • baseline or first baseline aligns the item’s left edge, keeping items them as close to the start as possible.
  • last baseline aligns the item’s left edge, keeping items as close to the end as possible.

In block layout, both baseline values seem to default to start. For absolutely positioned elements, they default to safe start and safe end, respectively.

It will only work if there is more than one element with that type of baseline alignment. Otherwise, baseline/first baseline fallbacks to safe start, and last baseline to safe end

anchor-center

For the case of absolutely positioned elements with a default anchor, the anchor-center let us justify the element so it matches its anchor’s center.

safe and unsafe

If the alignment container is too small or the element is too big, it may overflow outside its alignment container. This isn’t a big issue if the container is scrollable since we could scroll to see the rest of the element. But for some type of alignments (mainly center and end), the element may overflow outside the scrollable region, causing data loss.

In these situations, we can set safe first so that in case of overflow, the item behaves as start. On the contrary, we can set unsafe so it always honors the defined alignment.

normal

Like in everything, what’s normal depends on the context. And for justify-self, this depends on the type of element, whether it is absolutely positioned, and its parent’s layout setting.

As far as “type of element,” I’m referring to whether the element falls in either of these categories:

  • Block/Inline. A block element (<div><p><section>, etc.) tries to take up all the width available, while an inline element (<a><span><b>, etc.) only takes the necessary space. This distinction will be useful for alignment in block layouts.
  • Replaced/Non-replaced. Replaced elements are those whose content is replaced by an external source like an <iframe><img> or <video> (here is the exact list). Non-replaced elements are the rest, like <li><div> or <section>, etc.

We care about replaced elements since they have an intrinsic size that affects how they are aligned. This means that, in practice, elements with a defined aspect-ratio or defined dimensions act as replaced elements.

With the normal value:

  • Absolutely positioned elements depend on the type of element: replaced have a normal value of start, while non-replaced behave as stretch.
  • For elements in a block layoutnormal lays elements according to the default rules for block layouts. So, block elements still grow to take the available width, while inline elements don’t.
  • Elements in a grid container also depend on the type of element. If the element is replaced, it acts as start. Otherwise, it behaves as stretch.

As a rule of thumb, elements will try to stretch unless they are an inline element or have a defined dimension preventing it, in which case, they’ll remain at the start.

Using it With CSS Grid

Inside a grid layout, justify-self justifies elements along the inline axis within their grid area, which is composed of any number of grid cells and can be defined in a variety of ways.

In the next demo, we have four grid items placed each on a grid area. By default, these have a value of stretch so they cover their whole grid area, but we can move them around using both justify- and align- properties.

Using it With a Block Layout

For the purpose of alignment, elements in a block layout can be either be block elements or inline elements, which includes inline-block elements too. The main difference between them is that block elements can be justified within their containing block, while inline elements ignore justify-self.

At the time of writing, alignment in block layouts is something relatively new, which is limited to alignment in the inline axis. In other words, we can only move block elements within the space they usually occupy. Since block elements grow to fill the available width, from an alignment lens, we could say that block elements have a normal value of stretch

One thing you’ll notice is that both baseline and last baseline seem to default to start, instead of aligning the element’s left edge (either to the start or end) like in grid elements.

Using it With Absolute Positioning

Lastly, we can use both justify-self and align-self on absolutely positioned elements, i.e., aligning an item along the inline and block axes, respectively.

Their exact behavior might be a little unintuitive since applying any of the properties to a normal absolute element won’t work:

/* Doesn't work */
.element {
  position: absolute;
  align-self: center;
  justify-self: center;
}

This is because, for absolutely positioned elements, justify-self and align-self align the item within its Inset-Modified Containing Block (IMCB).

By default, the IMCB is the same size as the item, so that means justify-self and align-self don’t have room for any alignment. To fix this, we can set the inset to 0 so that the IMCB is the same size as the element’s containing block.

The containing block is the closest ancestor with a new stacking context. By default, the initial containing block has the same dimensions as the viewport and covers the start of the page.

/* Works */
.element {
  inset: 0;
  position: absolute;
  align-self: center;
  justify-self: center;
}

Additionally, if the absolutely-positioned element had an attached anchor, we could use the anchor-center value to align it with the anchor’s center.

Specification

The justify-self property is defined in the CSS Box alignment Module Level 3 specification, which is currently in Editor’s Drafts.

Browser support

Usage in CSS Flexbox:

Usage in CSS Grid:

Usage in absolute positioning can be found over at Caniuse. At the time of writing, it basically works everywhere but Safari, but it’s supported in Safari Technology Preview so we’ll likely see it with full support soon.

More information