search
HomeWeb Front-endCSS TutorialCSS Underlines Are Too Thin and Too Low in Chrome

Detailed explanation and repair suggestions for CSS underline display of Chrome browser

CSS Underlines Are Too Thin and Too Low in Chrome

This article will discuss two issues encountered when testing the new CSS properties text-decoration-thickness and text-underline-offset in Chrome.

Table of contents

  • The default underscore is inconsistent
  • Override the browser default style
  • Chrome Bug 1: The underlined under macOS system is too thin
  • Chrome Bug 2: Underlined position too low
  • How to help solve Chrome browser bugs first

The default underscore is inconsistent

Add text links to a simple web page, set the font to Arial, and then compare the underlined display effects under different browsers and operating systems. The results show that the default underscore thickness and vertical position (baseline offset) of different browsers are inconsistent. This complies with the provisions of the CSS text decorating module, which specifies the following default behavior (auto value):

The user agent selects the appropriate text decorative line thickness. [...] User agent selects the appropriate underscore offset.

Override the browser default style

Two new CSS properties can accurately define the thickness and offset of the underscore:

  • text-decoration-thickness
  • text-underline-offset

Using these two properties, you can create consistent underscore effects even on different browsers such as Firefox (Gecko engine) and Safari (WebKit engine).

 h1 {
  text-decoration: underline;
  text-decoration-thickness: 0.04em;
  text-underline-offset: 0.03em;
}

Note: text-decoration-thickness property also has a special from-font value that instructs the browser to use the preferred underline width of the font itself (if available). After testing, the underscore effect of different fonts is still inconsistent.

Chrome Bug 1: The underlined under macOS system is too thin

If text-decoration-thickness property is set to a font-related length value that is calculated as a non-integer pixel value, Chrome will round down instead of rounding. For example, if the declared weight is 0.06em and the calculation is 1.92px , Chrome will draw an underscore of 1px weight instead of 2px. This issue is limited to macOS systems only.

 a {
  font-size: 2em; /* The calculation result is 32px */
  text-decoration-thickness: 0.06em; /* The calculation result is 1.92px */
}

Screenshots show that the text decorating line in Chrome (third line) is twice as thin as in Safari and Firefox browsers.

For more information, please refer to Chromium issue #1255280.

Chrome Bug 2: Underlined position too low

text-underline-offset property allows precisely setting the distance between the letter baseline and the underscore (the offset of the underscore relative to the baseline). Unfortunately, Chrome browser does not implement this correctly at the moment, resulting in the underscore position being too low.

 h1 {
  text-decoration: underline;
  text-decoration-color: #f707;

  /* Disable "Skip Ink" */
  -webkit-text-decoration-skip: none; /* Safari */
  text-decoration-skip-ink: none;

  /* Cover the entire sinking line*/
  text-decoration-thickness: 0.175em; /* sinking line height*/
  text-underline-offset: 0; /* baseline without offset*/
}

Due to this bug, the underscore cannot be moved completely to the baseline.

For more information, please refer to Chromium issue #1172623.

Note: As shown in the above image, Safari draws underlines at the top of the sinking line instead of the bottom. This is a WebKit bug that has been fixed recently. This fix should be included in the next version of Safari.

How to help solve Chrome browser bugs first

The two new CSS properties used to style underline are welcome additions to CSS. I hope these two related Chrome bugs can be fixed as soon as possible. If these CSS features are important to you, add starring to these bugs in Chromium’s bug tracker to express your concern.

The above is the detailed content of CSS Underlines Are Too Thin and Too Low in Chrome. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
A Little Reminder That Pseudo Elements are Children, Kinda.A Little Reminder That Pseudo Elements are Children, Kinda.Apr 19, 2025 am 11:39 AM

Here's a container with some child elements:

Menus with 'Dynamic Hit Areas'Menus with 'Dynamic Hit Areas'Apr 19, 2025 am 11:37 AM

Flyout menus! The second you need to implement a menu that uses a hover event to display more menu items, you're in tricky territory. For one, they should

Improving Video Accessibility with WebVTTImproving Video Accessibility with WebVTTApr 19, 2025 am 11:27 AM

"The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect."- Tim Berners-Lee

Weekly Platform News: CSS ::marker pseudo-element, pre-rendering web components, adding Webmention to your siteWeekly Platform News: CSS ::marker pseudo-element, pre-rendering web components, adding Webmention to your siteApr 19, 2025 am 11:25 AM

In this week's roundup: datepickers are giving keyboard users headaches, a new web component compiler that helps fight FOUC, we finally get our hands on styling list item markers, and four steps to getting webmentions on your site.

Making width and flexible items play nice togetherMaking width and flexible items play nice togetherApr 19, 2025 am 11:23 AM

The short answer: flex-shrink and flex-basis are probably what you’re lookin’ for.

Position Sticky and Table HeadersPosition Sticky and Table HeadersApr 19, 2025 am 11:21 AM

You can't position: sticky; a

Weekly Platform News: HTML Inspection in Search Console, Global Scope of Scripts, Babel env Adds defaults QueryWeekly Platform News: HTML Inspection in Search Console, Global Scope of Scripts, Babel env Adds defaults QueryApr 19, 2025 am 11:18 AM

In this week's look around the world of web platform news, Google Search Console makes it easier to view crawled markup, we learn that custom properties

IndieWeb and WebmentionsIndieWeb and WebmentionsApr 19, 2025 am 11:16 AM

The IndieWeb is a thing! They've got a conference coming up and everything. The New Yorker is even writing about it:

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment