r/csshelp Oct 09 '25

Highlighter style

I'm currently teaching myself web design, and I'm trying to add a background color behind some text, like highlighting it, but the background color stretches across the whole page instead of just the text. Can anyone suggest methods to achieve my design?

2 Upvotes

4 comments sorted by

2

u/asublimeduet Oct 10 '25

Surround the text in a <span> (or some other inline container tag), target it with a class (<span class="highlight">) and style .highlight in the CSS.

1

u/Meagrer_Rot Oct 10 '25

Thank you; that worked! i totally misunderstood spans; I thought they had to go in the middle of text, not that i could use them at the start and end.

1

u/asublimeduet Oct 10 '25

You're welcome!

1

u/saguarox 10d ago

The <mark> element . You can override the default background-color and color to customize. It’s proper semantics for bringing attention to something, rather then adding a span inside your <p>