Skip to content
Merged
3 changes: 2 additions & 1 deletion files/en-us/web/css/guides/text_decoration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ p {

- {{cssxref("text-decoration")}}
- {{cssxref("text-decoration-color")}}
- {{cssxref("text-decoration-inset")}}
- {{cssxref("text-decoration-line")}}
- {{cssxref("text-decoration-skip")}}
- {{cssxref("text-decoration-skip-ink")}}
Expand All @@ -90,7 +91,7 @@ p {
- {{cssxref("text-underline-offset")}}
- {{cssxref("text-underline-position")}}

The specification also defines the `text-decoration-skip-box`, `text-decoration-skip-self`, `text-decoration-skip-spaces`, `text-decoration-trim`, and `text-emphasis-skip` properties, which are not yet supported by any browser.
The specification also defines the `text-decoration-skip-box`, `text-decoration-skip-self`, `text-decoration-skip-spaces`, and `text-emphasis-skip` properties, which are not yet supported by any browser.

## Guides

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
---
title: text-decoration-inset
slug: Web/CSS/Reference/Properties/text-decoration-inset
page-type: css-property
browser-compat: css.properties.text-decoration-inset
sidebar: cssref
---

The **`text-decoration-inset`** [CSS](/en-US/docs/Web/CSS) property enables adjusting the start and end points of an element's text decoration so it can be shortened, lengthened, or have its position shifted with respect to the rendered text.

{{InteractiveExample("CSS Demo: text-decoration-inset")}}

```css interactive-example-choice
text-decoration-inset: 20px;
```

```css interactive-example-choice
text-decoration-inset: -0.5em;
```

```css interactive-example-choice
text-decoration-inset: 20px 1em;
```

```css interactive-example-choice
text-decoration-inset: -0.5rem -1.5rem;
```

```css interactive-example-choice
text-decoration-inset: -2ex 10vw;
```

```html interactive-example
<section id="default-example">
<p id="example-element">Karmadrome</p>
</section>
```

```css interactive-example
#example-element {
font: 2.5em sans-serif;
text-decoration: underline 0.3em limegreen;
}
```

## Syntax

```css
/* auto keyword */
text-decoration-inset: auto;

/* One <length> value */
text-decoration-inset: 20px;
text-decoration-inset: -2rem;

/* Two <length> values */
text-decoration-inset: 20px 1em;
text-decoration-inset: -0.5rem -1.5rem;
text-decoration-inset: -2ex 1vw;

/* Global values */
text-decoration-inset: inherit;
text-decoration-inset: initial;
text-decoration-inset: revert;
text-decoration-inset: revert-layer;
text-decoration-inset: unset;
```

### Values

One or two {{cssxref("&lt;length>")}} values, or the keyword `auto`.

- {{cssxref("&lt;length>")}} values
- : Specifies the amount to adjust the text decoration position by. Positive values inset the text decoration (make it shorter) while negative values outset the text decoration (make it longer). If one value is specified, it applies to both the text decoration start and end points. If two values are specified, the first one applies to the text decoration start point and the second one applies to the text decoration end point.
- `auto`
- : The browser chooses an inset amount to ensure that, if two decorated text boxes appear side-by-side, a gap is created between the two so they do not appear to have a single text decoration.

## 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor Author

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.


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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor Author

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.


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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor Author

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 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. I thought it better to mention it is the initial value on the first mention of 0, not the second.


The `text-decoration-inset` property is not inherited, and it is not a constituent property of the {{cssxref("text-decoration")}} shorthand.
Copy link
Member

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.

Suggested change
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.

Copy link
Contributor Author

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.


## Formal definition

{{CSSInfo}}

## Formal syntax

{{csssyntax}}

## Examples

### Basic use cases

In this example we demonstrate an outset, inset, and "shifted" use case.

#### HTML

We define an unordered list with three list items, each with a separate `id`.

```html live-sample___use-case-examples
<ul>
<li id="one">Outset decoration</li>
<li id="two">Inset decoration</li>
<li id="three">Shifted decoration</li>
</ul>
```

#### CSS

We give each list item a different {{cssxref("text-decoration")}} and `text-decoration-inset`:

- The first one has a thick lime green underline, which is outset equally by `10px` on both sides.
- The second one has a medium thickness white strike-through, which is inset equally by `0.5em` on both sides.
- The third one has a thin wavy blue underline, which is moved to the right by `1em`.

```css hidden live-sample___use-case-examples
li {
font-family: sans-serif;
font-size: 2em;
margin-bottom: 20px;
}
```

```css live-sample___use-case-examples
#one {
text-decoration: underline 0.3em limegreen;
text-decoration-inset: -10px;
}

#two {
text-decoration: line-through 5px white;
text-decoration-inset: 0.5em;
}

#three {
text-decoration: underline wavy 2px blue;
text-decoration-inset: 1em -1em;
}
```

Copy link
Member

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;
  }
}

Copy link
Contributor Author

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.

#### Result

This renders like so:

{{embedlivesample("use-case-examples", "100%", "200")}}

### Effect of the `auto` value

This example demonstrates the effect of the `text-decoration-inset: auto` value.

#### HTML

We define two groups of side-by-side {{htmlelement("u")}} elements:

```html live-sample___auto-example
<p id="one"><u>石井</u><u>艾俐俐</u></p>
Copy link
Member

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?

Copy link
Contributor Author

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.


<p id="two"><u>石井</u><u>艾俐俐</u></p>
```

#### CSS

Each `<u>` element has a `red` color and `3px` thickness set on its underline. The first group of `<u>` elements has a `text-decoration-inset` value of `auto` set on them, while the second set has a `text-decoration-inset` value of `0` set on them, for comparison purposes:

```css hidden live-sample___auto-example
u {
font-family: sans-serif;
font-size: 2em;
}
```

```css live-sample___auto-example
u {
text-decoration-color: red;
text-decoration-thickness: 3px;
Copy link
Member

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.

Copy link
Contributor Author

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.

}

#one u {
text-decoration-inset: auto;
}

#two u {
text-decoration-inset: 0;
}
```

#### Result

This renders like so:

{{embedlivesample("auto-example", "100%", "200")}}

Note how the `auto` value creates a gap in the underlines, whereas the `0` value results in no gap.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link

@yisibl yisibl Nov 13, 2025

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.

Copy link

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?

https://chaoli.club/index.php/7000

Copy link
Contributor Author

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 auto value 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). The 0 value results in no gap.

Copy link
Contributor Author

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.


## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{cssxref("text-decoration")}}
- The [CSS text decoration](/en-US/docs/Web/CSS/Guides/Text_decoration) module