Close Menu
    Latest Post

    AI Wrapped: The 14 AI terms you couldn’t avoid in 2025

    January 6, 2026

    GPT Function Calling: 5 Underrated Use Cases

    January 6, 2026

    Stop using the wrong Gemini: The one setting you need to change for Gemini 3

    January 6, 2026
    Facebook X (Twitter) Instagram
    Trending
    • AI Wrapped: The 14 AI terms you couldn’t avoid in 2025
    • GPT Function Calling: 5 Underrated Use Cases
    • Stop using the wrong Gemini: The one setting you need to change for Gemini 3
    • Coros Nomad Review: A Robust and Affordable Outdoor Smartwatch
    • ICE Seeks Enhanced Cyber Surveillance for Employee Investigations
    • Fun graph from Peter Attia’s book Outlive
    • UK Social Media Campaigners Among Five Denied US Visas
    • Enhancing HDR on Instagram for iOS With Dolby Vision
    Facebook X (Twitter) Instagram Pinterest Vimeo
    NodeTodayNodeToday
    • Home
    • AI
    • Dev
    • Guides
    • Products
    • Security
    • Startups
    • Tech
    • Tools
    NodeTodayNodeToday
    Home»Dev»Enhancing Text Decorations with CSS text-decoration-inset
    Dev

    Enhancing Text Decorations with CSS text-decoration-inset

    Samuel AlejandroBy Samuel AlejandroJanuary 2, 2026No Comments4 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    src 10uuevb featured
    Share
    Facebook Twitter LinkedIn Pinterest Email

    The CSS property text-decoration-inset addresses a long-standing issue on the web: text decorations like underlines often extend past the actual text characters, reaching the content box edges. This can lead to visual misalignment.

    A default blue link zoomed in to the spacing between the text underline and border box, showing that the underline extends all the way to the border box.

    While some users might not notice or care about this detail, designers often find this misalignment visually bothersome.

    Previously, attempting to fix this issue was often more trouble than it was worth. A common workaround involved using text-decoration: none and a custom ::after pseudo-element with a background, but this method can be complex. Many prefer to utilize native text decoration features like text-decoration-thickness, text-underline-position (for adjusting the underline’s position relative to font metrics, such as the baseline), and text-underline-offset (to control the offset from that position).

    So, how does text-decoration-inset function? By trimming an underline just enough to align it vertically with the text, a more precise appearance can be achieved. (Note: This functionality is currently supported in Firefox 146+).

    A default blue link zoomed in to the spacing between the text underline and border box, showing that the underline does not extend all the way to the border box.

    This property allows for extensive trimming of text decorations, opening up possibilities for creative designs and even animated effects.

    text-decoration-inset basic usage

    The text-decoration-inset property, previously known as text-decoration-trim, allows clipping from the ends of an underline or any other computed text-decoration-line. The syntax is as follows:

    text-decoration-inset: <left-inset> <right-inset>;

    This property allows for distinct inset values to be applied to the left and right sides of the decoration.

    The values for text-decoration-inset must be <length> units. Relative lengths, like em units, are particularly useful as they scale with the computed font-size. This ensures that if the font size changes, the insets adjust proportionally. For instance, a value like 0.076em (representing 7.6% of the computed font-size) can be used to align the left inset with the left stem of a character like “N”. While this value might require some trial and error to find, it typically only needs to be determined once per font.

    If the initial character were, for example, “W”, the inset might not align perfectly, indicating that this is not a universally flawless solution. It is most effective in scenarios where the content is known in advance.

    The W3C may eventually develop a solution for automatically and accurately aligning text decorations and multiple lines of text. In the meantime, text-decoration-inset offers a valuable method for achieving precisely aligned effects, such as those involving both overlines and underlines with customized text-decoration-thickness.

    Animating text-decoration-inset

    The text-decoration-inset property becomes particularly compelling when considering transitions and animations. While custom ::after pseudo-elements are often used for animating underlines, text-decoration-inset allows for native animation. An example might involve multiplying the inset values on :hover. It is important to remember that only <length> values are permitted, so using em units is advisable, and testing with various font sizes is recommended.

    Currently, Firefox 146 or newer is required for this functionality:

    a {
      transition: 300ms;
      text-decoration-inset: 0.046em 0.009em;
    
      &:hover {
        text-decoration-inset: calc(0.046em * 10);
      }
    }

    A more advanced demonstration utilizes a CSS @keyframes animation to achieve a “shooting star” underline effect. This is accomplished by pushing the left inset across the element. Since only <length> values are allowed (percentages like 100% are not), a specific em value, such as 4.5em representing the element’s width, can be used. Precision in this value improves the animation or transition quality. Further details can be found in the code comments:

    a {
      /*
        The value at the start and end of the
        animation, as well as the default value
      */
      text-decoration-inset: 0.046em 0.009em;
    
      &:hover {
        animation: 1s next-level;
      }
    }
    
    @keyframes next-level {
      /* By half-way through the animation... */
      50% {
        /*
          ...the left inset has shifted 4.5em, 
          which is the full width of the element
        */
        text-decoration-inset: 4.5em 0.009em;
    
        /* It’s faded out as well */
        text-decoration-color: transparent;
      }
    
      /* Immediately after that... */
      50.999% {
        /* ...both insets are set to the left */
        text-decoration-inset: 0.046em 4.5em;
      }
    
      /* Then it animates back to the default value */
    }

    In summary, text-decoration-inset is a valuable CSS feature. While it has some limitations, like any property, its ability to natively refine details is a significant benefit. Specifically, it allows for improved text decoration alignment relative to the text and enables native transitions or animations for these decorations.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleThe E-WIN Champion Upgraded Gaming Chair: A Review of Comfort and Adjustability
    Next Article ChatGPT’s rivals, Kwai’s quiet rise: the top Internet services of 2025
    Samuel Alejandro

    Related Posts

    Dev

    GPT Function Calling: 5 Underrated Use Cases

    January 6, 2026
    Dev

    Optimized for Change

    January 6, 2026
    Dev

    Explaining HTML and CSS to a Child: Unexpected Lessons Learned

    January 5, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Latest Post

    ChatGPT Mobile App Surpasses $3 Billion in Consumer Spending

    December 21, 202512 Views

    Automate Your iPhone’s Always-On Display for Better Battery Life and Privacy

    December 21, 202510 Views

    Creator Tayla Cannon Lands $1.1M Investment for Rebuildr PT Software

    December 21, 20259 Views
    Stay In Touch
    • Facebook
    • YouTube
    • TikTok
    • WhatsApp
    • Twitter
    • Instagram
    About

    Welcome to NodeToday, your trusted source for the latest updates in Technology, Artificial Intelligence, and Innovation. We are dedicated to delivering accurate, timely, and insightful content that helps readers stay ahead in a fast-evolving digital world.

    At NodeToday, we cover everything from AI breakthroughs and emerging technologies to product launches, software tools, developer news, and practical guides. Our goal is to simplify complex topics and present them in a clear, engaging, and easy-to-understand way for tech enthusiasts, professionals, and beginners alike.

    Latest Post

    AI Wrapped: The 14 AI terms you couldn’t avoid in 2025

    January 6, 20260 Views

    GPT Function Calling: 5 Underrated Use Cases

    January 6, 20260 Views

    Stop using the wrong Gemini: The one setting you need to change for Gemini 3

    January 6, 20260 Views
    Recent Posts
    • AI Wrapped: The 14 AI terms you couldn’t avoid in 2025
    • GPT Function Calling: 5 Underrated Use Cases
    • Stop using the wrong Gemini: The one setting you need to change for Gemini 3
    • Coros Nomad Review: A Robust and Affordable Outdoor Smartwatch
    • ICE Seeks Enhanced Cyber Surveillance for Employee Investigations
    Facebook X (Twitter) Instagram Pinterest
    • About Us
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    • Disclaimer
    • Cookie Policy
    © 2026 NodeToday.

    Type above and press Enter to search. Press Esc to cancel.