text-underline-position
Quick Summary for text-underline-position
The text-underline-position CSS property specifies the position of the underline which is set using the text-decoration property's underline value.
Code Usage for text-underline-position
/* Single keyword */ text-underline-position: auto; text-underline-position: under; text-underline-position: left; text-underline-position: right;  /* Multiple keywords */ text-underline-position: under left; text-underline-position: right under;  /* Global values */ text-underline-position: inherit; text-underline-position: initial; text-underline-position: revert; text-underline-position: unset; 
More Details for text-underline-position

text-underline-position

The text-underline-position CSS property specifies the position of the underline which is set using the text-decoration property's underline value.

Syntax

/* Single keyword */ text-underline-position: auto; text-underline-position: under; text-underline-position: left; text-underline-position: right;  /* Multiple keywords */ text-underline-position: under left; text-underline-position: right under;  /* Global values */ text-underline-position: inherit; text-underline-position: initial; text-underline-position: revert; text-underline-position: unset; 

Values

auto

The user agent uses its own algorithm to place the line at or under the alphabetic baseline.

from-font

If the font file includes information about a preferred position, use that value. If the font file doesn't include this information, behave as if auto was set, with the browser choosing an appropriate position.

under

Forces the line to be set below the alphabetic baseline, at a position where it won't cross any descenders. This is useful for ensuring legibility with chemical and mathematical formulas, which make a large use of subscripts.

left

In vertical writing-modes, this keyword forces the line to be placed on the left side of the text. In horizontal writing-modes, it is a synonym of under.

right

In vertical writing-modes, this keyword forces the line to be placed on the right side of the text. In horizontal writing-modes, it is a synonym of under.

auto-pos

A synonym of auto, which should be used instead.

above

Forces the line to be above the text. When used with East-Asian text, using the auto keyword will lead to a similar effect.

below

Forces the line to be below the text. When used with alphabetic text, using the auto keyword will lead to a similar effect.

Formal definition

Initial valueauto
Applies toall elements
Inheritedyes
Computed valueas specified
Animation typediscrete

Formal syntax

auto | from-font | [ under || [ left | right ] ]

Examples

A simple example

Let's take a couple of simple example paragraphs:

<p class="horizontal">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam consectetur ac turpis vel laoreet. Nullam volutpat pharetra lorem, sit amet feugiat tortor volutpat quis. Nam eget sodales quam. Aliquam accumsan tellus ac erat posuere.</p>  <p class="vertical">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam consectetur ac turpis vel laoreet. Nullam volutpat pharetra lorem, sit amet feugiat tortor volutpat quis. Nam eget sodales quam. Aliquam accumsan tellus ac erat posuere.</p> 

Our CSS looks like this:

p {   font-size: 1.5rem;   text-transform: capitalize;   text-decoration: underline;   text-decoration-thickness: 2px; }  .horizontal {   text-underline-position: under; }  .vertical {   writing-mode: vertical-rl;   text-underline-position: left; } 

In this example we set both the paragraphs to have a thick underline. In the horizontal text we use text-underline-position: under; to put the underline below all the descenders.

In the text with a vertical writing-mode set, we can then use values of left or right to make the underline appear on the left or right of the text as required.

The live example looks like this:

Setting text-underline-position globally

Because the text-underline-position property inherits and is not reset by the text-decoration shorthand property, it may be appropriate to set its value at a global level. For example, the under value may be appropriate for a document with lots of chemical and mathematical formulas, which make a large use of subscripts.

:root {   text-underline-position: under; } 

Specifications

Specification
CSS Text Decoration Module Level 3 # text-underline-position-property

See also

The text-decoration property is a shorthand for setting most text-decoration properties, including text-decoration-line, text-decoration-color, and text-decoration-style. However, it does not set text-underline-position. Microsoft non-standard values documentation

Last modified: Feb 7, 2022, by MDN contributors

Select your preferred language English (US)DeutschFrançais日本語中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote

"Olivia, my eldest daughter, caught measles when she was seven years old. As the illness took its usual course I can remember reading to her often in bed and not feeling particularly alarmed about it. Then one morning, when she was well on the road to recovery, I was sitting on her bed showing her how to fashion little animals out of coloured pipe-cleaners, and when it came to her turn to make one herself, I noticed that her fingers and her mind were not working together and she couldn’t do anything. 'Are you feeling all right?' I asked her. 'I feel all sleepy,' she said. In an hour, she was unconscious. In twelve hours she was dead. The measles had turned into a terrible thing called measles encephalitis and there was nothing the doctors could do to save her. That was...in 1962, but even now, if a child with measles happens to develop the same deadly reaction from measles as Olivia did, there would still be nothing the doctors could do to help her. On the other hand, there is today something that parents can do to make sure that this sort of tragedy does not happen to a child of theirs. They can insist that their child is immunised against measles. ...I dedicated two of my books to Olivia, the first was ‘James and the Giant Peach’. That was when she was still alive. The second was ‘The BFG’, dedicated to her memory after she had died from measles. You will see her name at the beginning of each of these books. And I know how happy she would be if only she could know that her death had helped to save a good deal of illness and death among other children."

I just checked google books for BFG, and the dedication is there. 

https://www.google.com.au/books/edition/_/quybcXrFhCIC?hl=en&gbpv=1 


Roald Dahl, 1986
Random CSS Property

mask-border-width

The mask-border-width CSS property sets the width of an element's mask border.
mask-border-width css reference