Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari kerning issue when using "f" and "i"

I am running Safari 8.0.5 on OS X 10.10.3.

I've ran into a letter-spacing issue whenever using the characters "f" and "i" right next to each other. My guess is that this is a Safari bug, and I've submitted it to Apple as such, but also wanted to see if I can find a workaround in the mean time.

The HTML outputs the phrase "The fish is large" in two separate fonts. To accentuate the issue, I've adding 10px of letter spacing between each character.

HTML:

<div class="p1">
    The fish is large
</div>
<div class="p2">
    The fish is large
</div>

CSS:

div { letter-spacing: 10px; margin-bottom: 10px; }

div.p1 { 
    color: #009900;
    font-family: Helvetica;
}
div.p2 {
    color: #000099;
    font-family: Arial;
}

This is what my output for the above looks like in Safari:

Safari Letter Spacing Issue

For testing purposes I added an HTML comment between the "f" and "i" characters and that seems to have worked:

<div class="p1">
    The f<!----->ish is large
</div>

Gets outputted like this:

HTML Comment Version

While that technically works, it's not really an ideal solution for me as the content here is actually being generated by a WYSIWYG editor.

It seems the issue is only when "f" and "i" being right next to each other. I'm not sure if those letters have special meaning in Safari, but it's a pretty common letter sequence in the English language, so they really shouldn't have any keywords so small.

I also tried adding this:

 -webkit-font-feature-settings: "kern";

That did push the "s" over to the right, but the "f" and "i" were still bunched up together.

webkit font features

A capitalized "F" doesn't have the same problem:

Capitalized F

And the character that follows the "fi", doesn't seem to matter. I can change it to anything else and it still has the same issue.

Other letters after fi

Also it does the same thing if "fi" appears mid-word:

fi mid-word

I've confirmed that this issue also seems to exist on my iPhone 6 Plus running the latest version of Safari as well, so I doubt it's just something on my end.

To illustrate the issue I've created a jsfiddle with the necessary HTML and CSS that will hopefully reproduce the issue on your end. https://jsfiddle.net/38keruv7/4/

Does anybody have any ideas for a workaround that doesn't involve asking my clients to insert HTML comments in the middle of their words in a WYSIWYG editor?

I suppose I could scan and replace that particular combination prior to outputting the data, but that seems like a rather inefficient use of server resources, when dealing with much larger chunks of data.

like image 655
David Stinemetze Avatar asked Apr 16 '15 17:04

David Stinemetze


People also ask

Why is IOS Safari adding extra letter spacing?

Mobile Safari is buggy rendering faux font weights, if you don't set the font-weight (to eg. font-weight: 400 or font-weight: normal ) You need to specifically set the css font weight for it to render correctly in mobile safari. This is the solution.

How do you fix kerning?

Enable and Adjust Kerning in Word on Windows Open the Font Dialog Box by clicking the arrow on the bottom right corner of the Font section of the ribbon. Select the Advanced tab in the window. Check the box for Kerning for fonts under Character Spacing. To the right, enter the minimum point value you want to use.

What is automatic pair kerning?

Automatic and manual kerning Automatic kerning refers to the kerning applied automatically by a program, as opposed to no kerning at all, or the kerning applied manually by the user. There are two types of automatic kerning: metric and optical.

What is a kerning error?

No room for letters to breathe You'll be shocked (and not in a good way) by the number of fonts with over-kerning issues. It occurs when there's not enough space between letters left and words end up appearing too “tight”. It's not pretty to look at and will make your text illegible.


1 Answers

It looks like you found a Safari bug. The joined "fi" is a typographic ligature. CSS3 has a font-variant-ligatures property that can be used to control them; Safari supports it with the -webkit prefix. It looks like -webkit-font-variant-ligatures: no-common-ligatures; solves the problem, at least in Safari 8.0.3:

div {
    -webkit-font-variant-ligatures: no-common-ligatures;
    letter-spacing: 10px;
    margin-bottom: 10px;
}

Here's an updated fiddle: https://jsfiddle.net/38keruv7/5/

If you're still having trouble, here's a related question that says rendering: optimizeSpeed; also solves the problem: Letters Connected in Safari

like image 118
Jordan Running Avatar answered Sep 29 '22 11:09

Jordan Running