Why does display: inline-block; remove an underline from a child element?

Text decorations are propagated from an element to certain descendants in certain cases. The spec describes all the cases in which this happens and doesn’t happen (as well as cases where the behavior is explicitly undefined). Here, the following portion is relevant:

Note that text decorations are not propagated to floating and absolutely positioned descendants, nor to the contents of atomic inline-level descendants such as inline blocks and inline tables.

Note that this propagation is not the same as inheritance and is a separate concept entirely; indeed, text-decoration: none and text-decoration: inherit do not affect propagation in the way you’d expect them to:

  • text-decoration: none simply means “this element has no text decorations of its own”, and
  • text-decoration: inherit means “this element has the same specified text-decoration value as its parent.”

In both situations, parent text decorations will still be propagated to the element where applicable. You can force an inline-block to have the same text decoration as its parent using inherit, but not any other decorations that the parent gains through propagation from its own ancestors.

This also means that simply having display: inline-block is enough to prevent the text decorations from being propagated. You do not need to specify text-decoration: none again — it’s already the initial value.

Leave a Comment