Suppose we have the following element:
<div>STACKOVERFLOW</div>
And we want to make the A
red, but without changing the kerning properties of the word. In other words we want the word to display exactly the same way it did before. There is a similar question here:
change-color-of-one-character-in-a-text-box-html-css
However using a span
element changes the kerning properties of the word (Adds more space in front of the A
).
Here's a screenshot from the jsfiddle in the referenced SO question
As you can see it looks like the span
element adds a little more space.
Update
I'll add a screenshot along with some code to show what I mean. If you look at the word ICON
in the screen shot it is marked up like this (And the spans are causing additional space to be added):
<span class="u-text-uppercase u-text-color-md-grey-900 u-font-weight-900">Ic</span>
<span class="u-text-uppercase u-text-color-md-pink-a200 u-font-weight-900">o</span>
<span class="u-text-uppercase u-text-color-md-grey-900 u-font-weight-900">n</span>
<span class="u-text-uppercase u-text-color-md-grey-800 u-font-weight-100">Utility Tests</span></h1>
div { font-size: 3em; background: blue; display: inline-block; }
span { color: red; }
<div>STACKOVERFLOW</div>
<div>ST<span>A</span>CKOVERFLOW</div>
<img src="https://i.stack.imgur.com/EjnDF.png">
Per request in the comments color utilities come from SuperflyCSS Color Utilities
The font utilities come from the SuperflyCSS Font Utilities
And the u-text-uppercase
utility comes from The font utilities come from the SuperflyCSS Format Utilities
Another Update
Thanks you guys - The key - as mentioned in the accepted answer, is to keep the <span>
elements on the same line. When I do that is done this is the result: