![CSS @font-face Rule](https://codetofun.s3.ap-south-1.amazonaws.com/large/css-font-face.webp)
CSS Properties
CSS text-underline-offset Property
![CSS text-underline-offset Property](https://codetofun.s3.ap-south-1.amazonaws.com/large/css-text-underline-offset.webp)
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 (%).
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
Value | Description |
---|---|
length | Specifies the distance in pixels, points, or percentages by which the underline is offset from the text baseline. |
auto | Automatically 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.
<!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:
Author
![author](https://codetofun.s3.ap-south-1.amazonaws.com/mari-selvan-400.webp)
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
If you have any doubts regarding this article (CSS text-underline-offset Property), please comment here. I will help you immediately.