Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS text-underline-offset Property

Posted in CSS Tutorial
Updated on Jul 15, 2024
By Mari Selvan
👁️ 7 - Views
⏳ 4 mins
💬 1 Comment
CSS text-underline-offset Property

Photo Credit to CodeToFun

🙋 Introduction

The text-underline-offset property in CSS allows developers to control the position of the underline set by the text-decoration property.

This property is particularly useful when you want to adjust the space between the text and its underline, enhancing readability or achieving specific design effects.

💡 Syntax

The syntax for the text-underline-offset property is straightforward. It accepts length values, such as pixels (px), points (pt), or percentages (%).

Syntax
Copied
Copy To Clipboard
element {
  text-underline-offset: length;
}

Here, length is the distance by which the underline is offset from the default position of the text baseline.

🎛️ Default Value

The default value of text-underline-offset is auto, which means the browser determines the offset automatically based on font metrics and text decoration settings.

🏠 Property Values

ValueDescription
lengthSpecifies the distance in pixels, points, or percentages by which the underline is offset from the text baseline.
autoAutomatically determines the offset based on font metrics and text decoration settings.

📄 Example

In this example, we'll adjust the underline offset for a paragraph of text.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS text-underline-offset Example</title>
  <style>
    p {
      text-decoration: underline;
      text-underline-offset: 5px; /* Adjust the offset as needed */
    }
  </style>
</head>
<body>
  <h1>Text with Custom Underline Offset</h1>
  <p>This paragraph has a custom underline offset.</p>
</body>
</html>

🖥️ Browser Compatibility

The text-underline-offset property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it's recommended to test your implementation across different browsers to ensure consistent behavior.

🎉 Conclusion

The text-underline-offset property provides developers with precise control over the position of underlines in text elements.

Whether you need to adjust spacing for better readability or achieve specific design effects, this property allows you to fine-tune the presentation of underlined text on your website.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy