Open In App

How to Set the Gap Between Text and Underlining using CSS?

Last Updated : 14 Nov, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The gap between text and underlining is the space you can create between the text and underline, making it text easier to read and look better.

Using text-underline-offset Property

To set the gap between text and its underline in CSS, use the text-underline-offset property. This property defines the distance between the text and the underline, improving the readability of the content.
 

HTML
<!DOCTYPE html>
<html>

<head>
    <style>
        .normal-underline {
            text-decoration: underline;
            text-underline-offset: 0px; 
        }

        .spaced-underline {
            text-decoration: underline;
            text-underline-offset: 10px; 
            text-decoration-thickness: 3.1px; 
        }
    </style>
</head>

<body>
    <h1 class="normal-underline">
       Code World : with normal underline
    </h1>

    <h1 class="spaced-underline">
       Code World : with spaced underline
    </h1>
</body>

</html>

Output

Output


Similar Reads