-
Notifications
You must be signed in to change notification settings - Fork 23k
Add docs for the CSS text-decoration-inset property #41901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add docs for the CSS text-decoration-inset property #41901
Conversation
|
Preview URLs
Flaws (41)URL:
URL:
External URLs (1)URL:
(comment last updated: 2025-11-13 10:03:05) |
files/en-us/web/css/reference/properties/text-decoration-inset/index.md
Outdated
Show resolved
Hide resolved
estelle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just a few suggestions.
files/en-us/web/css/reference/properties/text-decoration-inset/index.md
Outdated
Show resolved
Hide resolved
|
|
||
| ## Description | ||
|
|
||
| The `text-decoration-inset` property allows you to adjust the start and/or end points of a text container's text decoration, as set by the {{cssxref("text-decoration")}} shorthand and associated longhand properties. This is useful for creating effects where you want the text decoration to be inset or outset from the text itself, or shifted in position. See [Basic use cases](/en-US/docs/Web/CSS/Reference/Properties/text-decoration-inset#basic_use_cases) for an example of each. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The `text-decoration-inset` property allows you to adjust the start and/or end points of a text container's text decoration, as set by the {{cssxref("text-decoration")}} shorthand and associated longhand properties. This is useful for creating effects where you want the text decoration to be inset or outset from the text itself, or shifted in position. See [Basic use cases](/en-US/docs/Web/CSS/Reference/Properties/text-decoration-inset#basic_use_cases) for an example of each. | |
| By default, an element's text decoration is the same size as the rendered text. The `text-decoration-inset` property allows you to adjust the start and/or end points of a text container's text decoration, as set by the {{cssxref("text-decoration")}} shorthand and associated longhand properties. This is useful for creating effects where you want the text decoration to be inset or outset from the text itself, or shifted in position. See [Basic use cases](/en-US/docs/Web/CSS/Reference/Properties/text-decoration-inset#basic_use_cases) for an example of each. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saying this is a good idea, but I've shifted the order of the text around a bit, so that the first sentence says:
By default, an element's text decoration, as set by the {{cssxref("text-decoration")}} shorthand and associated longhand properties, is the same size as the rendered text.
I think it reads better this way.
|
|
||
| The `text-decoration-inset` property can also take the `auto` keyword, which causes the browser to choose a value to ensure that, if two decorated text boxes appear side-by-side, a gap is created between them so they do not appear to have a single text decoration. The `auto` value is particularly important when rendering Chinese text, as underlining is used to [punctuate proper nouns](https://www.w3.org/TR/clreq/#id88), and adjacent proper nouns should have separate underlines. See [Effect of the `auto` value](/en-US/docs/Web/CSS/Reference/Properties/text-decoration-inset#effect_of_the_auto_value) for an example. | ||
|
|
||
| The `auto` value does not have the same effect as a `text-decoration-inset` value of `0` (which is the initial value) — `0` causes there to be no space between decorations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The `auto` value does not have the same effect as a `text-decoration-inset` value of `0` (which is the initial value) — `0` causes there to be no space between decorations. | |
| The `auto` value does not have the same effect as a `text-decoration-inset` value of `0`. The initial value `0` causes there to be no space between decorations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, but I've reordered this to:
The
autovalue does not have the same effect as the initial value0. Settingtext-decoration-insetto0causes there to be no space between decorations. I thought it better to mention it is the initial value on the first mention of0, not the second.
files/en-us/web/css/reference/properties/text-decoration-inset/index.md
Outdated
Show resolved
Hide resolved
| text-decoration-inset: 1em -1em; | ||
| } | ||
| ``` | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add something like the following to both examples as "css hidden":
@supports not (text-decoration-inset: auto) {
body::before {
content: "Your browser doesn't support the `text-decoration-inset` property.";
background-color: wheat;
display: block;
width: 100%;
text-align: center;
}
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea. I've tweaked the styles a little bit and added the block to both examples. Works nicely.
files/en-us/web/css/reference/properties/text-decoration-inset/index.md
Outdated
Show resolved
Hide resolved
| ```css live-sample___auto-example | ||
| u { | ||
| text-decoration-color: red; | ||
| text-decoration-thickness: 3px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would go with text-decoration: red 3px underline , but not required edit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not do this; I was kind of going for a subtle hint that the underline created on <u> is a text decoration. But at the same time, I didn't want to waffle on about that explicitly because it seemed out of scope for the article.
| We define two groups of side-by-side {{htmlelement("u")}} elements: | ||
|
|
||
| ```html live-sample___auto-example | ||
| <p id="one"><u>石井</u><u>艾俐俐</u></p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add the lang attribute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that's probably a good idea. Added.
|
|
||
| {{embedlivesample("auto-example", "100%", "200")}} | ||
|
|
||
| Note how the `auto` value creates a gap in the underlines, whereas the `0` value results in no gap. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Note how the `auto` value creates a gap in the underlines, whereas the `0` value results in no gap. | |
| Note how the `auto` value insets the text decoration, creating a gap in the underline between the two elements (but adding no space between the two elements), whereas the `0` value results in no gap. |
it insets on both sides, which is subtle, so may not be noticed if not pointed out, so suggest explicitly pointing it out. Also, the "gap" is in the underlines but not in the text, so want to point that out too. My suggestion may not be the best verbiage, but i think it is important to point out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not between two elements, but rather the underscore shortens at both ends, creating the appearance of a gap.
I believe it's important to explicitly clarify the rendering method here, as it's otherwise prone to misunderstanding. Before this property existed, Chinese developers would create gaps using u+u { margin-left: .125em;}. but it's not the same as text-decoration-inset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, the approach in this article that uses border-image to simulate text-decoration-inset can be considered a polyfill. Could you look into adding it to this documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. I played with the text a bit and ended up updating it to:
Note how the
autovalue insets the text decoration subtly on both sides, creating a gap in between the underlines of the two elements (no space is added between the two elements themselves). The0value results in no gap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not between two elements, but rather the underscore shortens at both ends, creating the appearance of a gap.
@yisibl OK, thanks for the clarification. In light of your comment, I've improved the auto value description on the page further.
In terms of adding polyfill/previous technique information, I'm not sure about this — this is not something we generally do on MDN, at least not these days. Polyfills change and go out of date, and adding previous technique information would also create a huge maintenance burden. So, I'm going to leave this information out.
|
|
||
| A single `<length>` value will set the inset (if positive) or outset (if negative) on the start and end positions of the text decoration. To set the start and end positions separately, you can use two `<length>` values — the first one applies to the start position of the text decoration and the second one applies to the end. | ||
|
|
||
| The `text-decoration-inset` property can also take the `auto` keyword, which causes the browser to choose a value to ensure that, if two decorated text boxes appear side-by-side, a gap is created between them so they do not appear to have a single text decoration. The `auto` value is particularly important when rendering Chinese text, as underlining is used to [punctuate proper nouns](https://www.w3.org/TR/clreq/#id88), and adjacent proper nouns should have separate underlines. See [Effect of the `auto` value](/en-US/docs/Web/CSS/Reference/Properties/text-decoration-inset#effect_of_the_auto_value) for an example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The `text-decoration-inset` property can also take the `auto` keyword, which causes the browser to choose a value to ensure that, if two decorated text boxes appear side-by-side, a gap is created between them so they do not appear to have a single text decoration. The `auto` value is particularly important when rendering Chinese text, as underlining is used to [punctuate proper nouns](https://www.w3.org/TR/clreq/#id88), and adjacent proper nouns should have separate underlines. See [Effect of the `auto` value](/en-US/docs/Web/CSS/Reference/Properties/text-decoration-inset#effect_of_the_auto_value) for an example. | |
| The `text-decoration-inset` property can also take the `auto` keyword, which causes the browser to inset the start and end positions ensuring that, if two decorated text boxes appear side-by-side, a gap is created between them so they do not appear to have a single text decoration. The `auto` value is particularly important when rendering Chinese text, as underlining is used to [punctuate proper nouns](https://www.w3.org/TR/clreq/#id88), and adjacent proper nouns should have separate underlines. See [Effect of the `auto` value](/en-US/docs/Web/CSS/Reference/Properties/text-decoration-inset#effect_of_the_auto_value) for an example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, good to make this clear. In my next commit, I've added a variation of this, but also made a few other tweaks to the paragraph.
…/index.md Co-authored-by: Estelle Weyl <[email protected]>
…/index.md Co-authored-by: Estelle Weyl <[email protected]>
…/index.md Co-authored-by: Estelle Weyl <[email protected]>
pepelsbey
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just a small nit below
|
|
||
| The `auto` value does not have the same effect as the initial value `0`. Setting `text-decoration-inset` to `0` causes there to be no space between decorations. | ||
|
|
||
| The `text-decoration-inset` property is not inherited, and it is not a constituent property of the {{cssxref("text-decoration")}} shorthand. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest saying it a little simpler.
| The `text-decoration-inset` property is not inherited, and it is not a constituent property of the {{cssxref("text-decoration")}} shorthand. | |
| The `text-decoration-inset` property is not inherited, and it is not a part of the {{cssxref("text-decoration")}} shorthand. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I agree with this. My text is precise, and we do use this term commonly around the CSS section of CSS.
estelle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* Add docs for the CSS text-decoration-inset property * Add extra information on Chinese punctuation * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Fixes for estelle review comments plus other tweaks * improve auto description further --------- Co-authored-by: Estelle Weyl <[email protected]>
* Add docs for the CSS text-decoration-inset property * Add extra information on Chinese punctuation * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Fixes for estelle review comments plus other tweaks * improve auto description further --------- Co-authored-by: Estelle Weyl <[email protected]>
* Add docs for the CSS text-decoration-inset property * Add extra information on Chinese punctuation * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Fixes for estelle review comments plus other tweaks * improve auto description further --------- Co-authored-by: Estelle Weyl <[email protected]>
* Add docs for the CSS text-decoration-inset property * Add extra information on Chinese punctuation * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Fixes for estelle review comments plus other tweaks * improve auto description further --------- Co-authored-by: Estelle Weyl <[email protected]>
* Add docs for the CSS text-decoration-inset property * Add extra information on Chinese punctuation * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Fixes for estelle review comments plus other tweaks * improve auto description further --------- Co-authored-by: Estelle Weyl <[email protected]>
* Add docs for the CSS text-decoration-inset property * Add extra information on Chinese punctuation * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Fixes for estelle review comments plus other tweaks * improve auto description further --------- Co-authored-by: Estelle Weyl <[email protected]>
* Add docs for the CSS text-decoration-inset property * Add extra information on Chinese punctuation * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Fixes for estelle review comments plus other tweaks * improve auto description further --------- Co-authored-by: Estelle Weyl <[email protected]>
* Add docs for the CSS text-decoration-inset property * Add extra information on Chinese punctuation * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Update files/en-us/web/css/reference/properties/text-decoration-inset/index.md Co-authored-by: Estelle Weyl <[email protected]> * Fixes for estelle review comments plus other tweaks * improve auto description further --------- Co-authored-by: Estelle Weyl <[email protected]>
Description
Firefox 146 onwards has the
text-decoration-insetproperty enabled by default (see https://bugzilla.mozilla.org/show_bug.cgi?id=1993043; it was calledtext-decoration-trim, but it got renamed). I've tested it, and it doesn't work in Chrome/Safari yet.This PR adds a reference page for the new property, and links to it from the text decoration module page.
Motivation
Additional details
Related issues and pull requests