Is there a way to style individual text-decoration when using multiple properties?

I would like to style to overline to be dashed and the underline to be dotted for a personal project of mine is there any way to achieve that using pure css?

p {
  color: green;
  text-decoration: underline overline;
  text-decoration-style: dashed;
  text-decoration-color: red;
}
<p>Decorated text</p><p>Decorated text</p><p>Decorated text</p>

>Solution :

If you know it’s on just one line then you could style the first-line to have one of the lines and the actual element to have the other.

This will work as well as setting a border, and is easier as the placement is already done for you (with border you have to worry about how to get the underline going through the descenders to make it look like a proper underline – which can vary depending on font used).

p {
  color: green;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: red;
}

p::first-line {
  text-decoration: overline;
  text-decoration-style: dashed;
  text-decoration-color: red;
}
<p>Decorated text</p>
<p>Decorated text</p>
<p>Decorated text</p>

Leave a Reply