Is it safe to use the CSS rule "text-rendering: optimizelegibility;" on all text? - css

I noticed this woo theme for example has it set on the HTML tag and therefore the whole site's text has it set. I read that it can cause performance problems but that was a while ago. Some people suggested only adding it to headers and big text.
Have the rules changed now? Do browsers perform well with it?

No: there have been many bugs over the years on various platforms which cause text not to be displayed or displayed incorrectly (see below). If your goal is to enable ligatures, there's actually standard property font-variant-ligatures defined in CSS Fonts Level 3 which offers full control:
font-variant-ligatures: common-ligatures;
font-variant-ligatures: common-ligatures discretionary-ligatures historical-ligatures;
See font-variant for other typographic features which can be enabled such as small caps, alternate letter forms, etc.
History
Before font-variant-ligatures & the related properties were added, the older font-feature-settings property allowed the same feature to be enabled. This is a lower-level interface and is no longer recommended except to enable OpenType features which do not have a higher-level interface.
http://blog.fontdeck.com/post/15777165734/opentype-1 has a simple example:
h1 {
-webkit-font-feature-settings: "liga", "dlig";
-moz-font-feature-settings: "liga=1, dlig=1";
-ms-font-feature-settings: "liga", "dlig";
font-feature-settings: "liga", "dlig";
}
http://elliotjaystocks.com/blog/the-fine-flourish-of-the-ligature/ has more discussion as well.
Bug Gallery
The popular HTML5 Boilerplate project removed it two years ago due to various rendering problems:
https://github.com/h5bp/html5-boilerplate/issues/78
Two Chromium bugs which I just fixed this morning caused Chrome 21 on Windows XP to either fail to perform font substitution at all, displaying the missing character symbol rather than using one from a different font, and displaying text incorrectly overlapping other elements:
http://code.google.com/p/chromium/issues/detail?id=114719
http://code.google.com/p/chromium/issues/detail?id=149548
See http://aestheticallyloyal.com/public/optimize-legibility/ for a few other concerns.
http://bocoup.com/weblog/text-rendering/ highlighted compatibility problems on Android and general performance issues

from the MDN text-rendering page, last updated on 18:27, 29 Apr 2012, it reads:
The text-rendering CSS property provides information to the rendering engine about what to optimize for when rendering text. The browser makes trade-offs among speed, legibility, and geometric precision. The text-rendering property is an SVG property that is not defined in any CSS standard. However, Gecko and WebKit browsers let you apply this property to HTML and XML content on Windows, Mac OS X and Linux.
which tels us that it is not defined in any CSS standard, thus leading to cross-browser issues, as seen on the Browser compatibility table.
By default
The browser makes educated guesses about when to optimize for speed, legibility, and geometric precision while drawing text.
So, is safe to assume that the best option is to let the browser take care of details like this, since this feature is not a standard (yet), and most browsers don't support it.

text-rendering: optimizeLegibility; was used in one of our web apps. it rendered properly in all browsers, except one - chrome (64) on windows 7.
Had to remove the property as most of our end users were from that category.

I've just fixed a bug where Chrome was refusing to render web fonts (it always fell back to a non-web one, for no reason we could discern). In the end - after considerable amount of head-scratching - the problem was fixed by setting text-rendering from optimizeLegibility (which had been set by Twitter Bootstrap, for what it's worth) to auto.
So I would say for the moment the answer is probably "no". Which isn't to say don't use it, but don't apply it to everything. Use it where needed and test it carefully for weirdnesses or unexpected effects (especially in Chrome!).

using "text-rendering: optimizelegibility" also causes rendering errors in android native browser (4.2 & 4.3). If you use this attribute in combination with loading new fonts via #font-face, the font will not display at all (only fallback). without "text-rendering: optimizelegibility" and #font-face the font loads and gets displayed as expected.

CSS text-rendering looks shaky. Instead of grinding time with a poor CSS property, it may be worthwhile to go with this...
If Javascript is an option for you, Kerning.js looks promising, a javascript approach to kerning and kerning pairs hosted on Github.
http://kerningjs.com
Also worth noting, if you are getting serious about typography, there is Font Squirrel free use web fonts.
http://www.fontsquirrel.com

Related

How can I prevent this ndash from disappearing at small font sizes?

I have an – character that becomes invisible when the text is rendered at a smaller font size (the applicable font-size rule is 14px, at which it is invisible; if I zoom in one level in Firefox, it becomes visible.) I have only seen this behavior on Firefox on Windows. With Firefox on Linux, I see the character at all sizes. I believe that what happens is that at smaller sizes, the dash is allowed to render as a line of zero width. So the question is, how can I remedy this? Here's what I can think of -
Try a different dash character and hope for the best
wrap the dash in a span and force it to be bigger - seems clunky
maybe my font definition is broken - this is embedded Open Sans
any other approach I'm overlooking?
Don't use any of the legacy 90's Microsoft core fonts in Windows (Arial, Verdana, etc). They have very aggressive hints intended to prevent "fat" or "blurry" stems at all costs, that result in some of those stems disappearing at small sizes. Perpetuating the pixelated look Windows users were accustomed to was the only thing Microsoft cared about at the time (there are built-in workarounds in the Microsoft rendering stack to hide the bugs of those fonts, but they don't exist in third-party apps).
Have you tried a different font-family to see if it's showing the same problem?
This is a problem of fonts, not browser support. Try to use another font like "Times New Roman" to verify.
In the case of the small icons, the most reliable solution is to use the CSS #font-face rule to ask the browser to download a particular font. Then you'll know for sure that the user has an appropriate font installed. There are even some fonts designed specifically for this use, with extra icons built in: "Font Awesome" is a well-known example.
Please look here for more information: Does every browser support all unicode?

CSS fallback for OpenType small caps

I'm working on a site where small caps are important: setting the text of the Bible. In the Old Testament the name of God is transliterated as Lord but in small caps—not LORD. However, the state of OpenType small caps support at the moment is… less than optimal. Safari (even up through Safari 8 on Yosemite, from which I am typing this) still doesn't support the -webkit-font-feature-settings: 'smcp' option, and a lot of the hits for this website will be coming from mobile.
Unfortunately, "graceful degradation" is problematic here: if you specify both font-variant: small-caps and font-feature-settings: 'smcp' in a browser that supports the latter (e.g. Chrome), the font-variant declaration overrides it, so the horribly ugly old-style version still comes into play. (Note: this is as it should be per the spec: the font-variant declaration has a higher priority than the font-feature-settings declaration). Given the current implementations of font-variant: small-caps, though—shrunken capitals rather than actual small capitals—the result is that using font-variant: small-caps realists in not-so-gracefully degrading everyone's reading experience.
In the past, I have exported the small caps as a distinct webfont and specified them directly; see this post for a simple example: the first line of each paragraph is specified that way.
While I can do the same thing here (and at least in theory could deliver a pretty small typeface, since I really only need three characters: o, r, and d), I'd prefer simply to enable sane fallbacks. As noted above, however, that's not possible. I am open to but would very much prefer to avoid server-side solutions (browser detection, etc.) as a point of complexity that is better to minimize, especially given how rapidly browsers change. How else might one solve this problem, and especially are there existing solutions for it?
Edit: clarifying based on comments—in the future, font-variant: small-caps will handle this nicely, as per the spec it should display a small-capitals-variant of the typeface if the typeface supplies it. However, at present, no browser supports this (at least, none that I can find!). This means that instead, they all render fake small capitals simply by scaling down actual capitals. The result is typographically unpleasant, and unacceptable on this project.
Last updated 2016/02/28.
I spent a considerable amount of time researching this and wrestling with it.
After digging around as best I could, the top solutions for now are:
#supports
Take advantage of the #supports rule in browsers. This is what I initially
opted to do on this project.[1] You use the rule this way:
.some-class {
font-variant: small-caps;
}
#supports(font-feature-settings: 'smcp') {
.some-class {
font-variant: normal;
font-feature-settings: 'smcp';
}
}
I've simplified by leaving out the prefixed versions; you'll need to add the
-webkit- and -moz- prefixes to get this actually working. Update,
2012/02/28: you no longer need the -moz- prefix, and this will work in
Safari in the next release (iOS 9.3 and OS X Safari 9.1).
This has the advantage that support for real small caps and
support for the #supports rule are very similar:
#supports: Can I Use Feature Queries?: Chrome 31+, Firefox
29+, Opera 23+, Android 4.4+, Safari 9+, Edge 12+, Chrome for Android
Update, 2016/02/28: as the chart linked above will make clear, all
evergreen browsers now have #supports support.
font-feature-settings: Using Small Caps & Text Figures on the Web:
Chrome, Firefox, IE10+
This isn't perfect: since IE10/11 don't implement #supports, you miss one
browser. (Edit, 2015/09/31: IE proper doesn't have #supports, but Edge 12+
does, and that should increasingly cover all consumer users of the site.)
Still, this gets you most of the way there, and it should be future-facing: this
should progressively enhance the site nicely. The normal (bad, but functional)
small caps are displayed in the meantime, and when browsers eventually get
around to using OpenType small caps by default for font-variant: small-caps,
this will continue to work just fine. It's "progressive enhancement" and it'll
work nicely for most purposes.[2]
Typeface subsetting
As mentioned in the question, one can create a subset of the typeface that
includes only small capitals. This is what I have done for the small caps on my
own website; see the first line of the first
paragraph in this post for an example.
To pull this off, you'll need to start by subsetting the typeface. You can do
this manually with a font tool, or (the simpler way) you can use FontSquirrel's
custom subsetting tool in their webfont generator. (Note: You
must check the license and confirm that the typeface in question allows this
kind of modification. See below.) In the web font generator, first upload the
file you wish to modify. Then choose the Expert radio button. Most of the
settings you can leave as they are; they're good sane defaults. Midway down the
page you'll see OpenType Flattening options. Here, select only "Small Caps".
Run the generator. The result will be a complete replacement of the normal
lowercase letters with the small caps set.[3]
In that case, you can simply apply a style to the elements you want to have
small capitals, e.g.:
.divine-name {
font-family: 'my_typeface_smcp', 'my_typeface', serif;
}
The major advantage to this approach is consistency: that typeface is going to
display on every browser out there, back to IE5.5, as long as you deliver it
correctly using the various hooks required by #font-face.
There are a few disadvantages to this approach, though:
It means delivering another font file. In my case, this would be an
acceeptably low size (since I actually only need four characters), but it's
still something to consider in general. It is in any case another HTTP
request, which is going to further slow the page load time or at least give
you some flash of unstyled text when it reloads.
It may violate the licenses of the typefaces in question. For at least one
of the fonts I am using on this project, it does: the license explicitly
forbids rebuilding the font using tools like FontSquirrel. (FontSquirrel was
the tool I used for this approach before, and it works quite well.) This is
a make-or-break issue for using a subset of a typeface to accomplish the
goal. That being said, if you have a good reason to do it, you may be able
to get support from the vendor (especially if they're a small shop). For the
project that prompted this question, I was able to do just that with a nice
email—the designer is a great guy.
The other major reason not to do it this way is that it has a significantly
higher maintenance cost. If at any point you need to change or update the
typeface, you have to go through the subsetting process all over again. By
contrast, the first option will simply work, though admittedly not as
pleasantly as one might hope, and will not only continue to work but will
actually improve over time as browsers increase their implementation of the CSS3
standard.
Notes
For various reasons (especially see note 2 below), I actually opted for the
second approach outlined here, which is the same approach I was trying to
avoid. Alas.
Issues remain: even in the latest Chrome (38 as of the time of this
edit), using the font-feature-settings: 'smcp' approach has some
issues. For example, if you turn on letter-spacing (a fairly common
recommendation for small caps), the small caps will revert
to normal lowercase letters. Fixed in Chrome 48. HT to answerer
below.
From the FontSquirrel blog post that introduced the feature:
If you have a font with OpenType features, you can now flatten some of
them into your webfont. For instance, some fonts have small caps built in,
but they are completely inaccessible in a web browser. By selecting the
"Small Cap" option, the Generator will replace all the lowercase glyphs
with the small cap variants, giving you a small cap font. Please note that
not all OpenType features are supported and if the font lacks OpenType
features, using these options won't create them.
Support for font-feature-settings:"smcp" has improved in recent browsers. Chrome 48 fixes the letter-spacing bug. And according to caniuse.com, upcoming versions of Safari for both iOS and Desktop will support it. The prefixed version is still required for -webkit, though.
You already mentioned it here, graceful degradation.
Use the font-feature setting and if a browser does not support opentype features then the user will receive all the content still, with the worst-case scenario being full-size capitals; nothing is lost. I'd say that is a graceful degradation.
Aa an alternative you might want to consider using Typogruby (http://avdgaag.github.io/typogruby/), or similar, or manually adding a class to that word which you can target directly in your html, faking it with CSS2 e.g.:
.caps {font-size: .83em; letter-spacing: .25em; text-transform: uppercase;}
Edit: Of course, with the above method you can also specify a different font for the .caps class, one with full caps that will work well at small sizes in place of true small caps.
Stop thinking OpenType for a moment and think content: you need different styling for semantically different data (in this case, smallcaps styling for a special religious word) That's literally what HTML markup was invented for. Just auto-wrap those words in <span class="smallcapped"> markup with javascript, and have its class use a dedicated small-caps font. This is very easy to do, and even allows you to find the best suite smallcaps look independent of the main text typeface.
Simply run some code every time a section is DOM-loaded (emphatically not after your entire content is done, unless you're only ever showing short stretches of text):
function wrapSmallcaps(element) {
var content = element.innerHTML;
["LORD"].forEach(function(term) {
var search = new RegExp(" W?"+term+" W?",'g');
content = content.replace(search, function(a,b) {
return a.replace(term, "<span class='smallcapped'>"+term+"</span>");
});
});
element.innerHTML = content;
}
ex: http://jsbin.com/cowumaxe/1/edit
We could solve this by trying to make use of OpenType fonts, but you'd be tying yourself to one font, rather than one for for each style, making it extremely hard to improve the looks later on without violating font licenses when a better running text typeface or smallcaps typeface is found, or user feedback prompts you to improve the looks.
(and of course, this code is literally universal for any browser since IE8 -- http://caniuse.com/#search=queryselector shows zero "no support" or even "partial support" for all browsers people actually use)

How do I prevent different browsers from adding more width to words via #font-face?

See images:
Firefox on Mac:
Firefox on Chrome:
On chrome you can see that the same font using the same styling takes more room. What can I do so that all browsers will render the font the same way rather than adding more width to it?
I am using a font with #font-face property.
Unfortunately, there isn't much you can do about the way each browser renders your chosen typeface. Check out this article, it explains how different browsers and operating systems render different type face files:
http://www.smashingmagazine.com/2012/04/24/a-closer-look-at-font-rendering/
In the meantime, you can do two things.
1.) There are many fonts that can be used that are effected by this rendering difference much less. Experiment with different fonts that hold the same esthetic value of the font that you are using, and try to find one that not only fits your typographic needs but also have a less distinctive difference between their individual renderings across different platforms.
2.) Create a script to sense the user's browser/OS and use that script to adjust your font-weight accordingly.
Best of luck.
You forgot to mention which of the two cases is the correct font rendering.
A few ideas that come to mind:
Since you mentioned using font-weight:600 I would try to replace it with normal/bold (depending which result you want) and check if it makes any difference. If the font file does not support a weight for 600 the browser will go on interpreting it by itself - sometimes it takes bold sometimes normal.
If the problematic browser is Chrome you can also try playing with font-smoothing - sometimes it helps improving the font rendering:
-webkit-font-smoothing: none || antialiased || subpixel-antialiased
Also I'm not sure how you are implementing the #font-face - if you wrote it yourself I suggest generating your #font-face rule trough some service like Fontsquirell since it will generate a crossbrowser compatible code which often eliminates a few problems.
For more help you will need to expand your question with a bit more data - add the #font-face code, font name and specify which is the correct font rendering. Poor questions get poor answers.

Difference between -moz-linear-gradient and -webkit-gradient

What is the basic difference between -moz-linear-gradient and -webkit-gradient. I know the changes are in parameters and -moz is meant for mozilla. But why we have different CSS property for Mozilla. What does webkit represents here ?
Most often, though, the extensions are used to release and test
browser features that have been developed in the preparation of W3C
drafts that have not yet reached Candidate Recommendation status—the
extensions allow these new properties to be widely tested before they
become available as standard CSS properties.
http://reference.sitepoint.com/css/vendorspecific
Some of these properties have been included in draft CSS specification
for inclusion in the final recommendation, but are still experimental.
The final standard property may be different from the current prefix
implementation.
https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Mozilla_Extensions
Webkit CSS properties
http://css-infos.net/properties/webkit
WebKit is an open source web browser engine. WebKit is also the name of the Mac OS X system framework version of the engine that's used by Safari, Dashboard, Mail, and many other OS X applications. WebKit's HTML and JavaScript code began as a branch of the KHTML and KJS libraries from KDE.
CSS3 Gradients
Introduction
WebKit paved the way for gradients in CSS by adding support for -webkit-gradient back in early 2008, and they’ve become widely used since their introduction.
Over the past several months, the CSS Working Group has had extended discussions about making the gradient syntax easier to use, and recently Tab Atkins included a proposal in the latest draft of the Image Values and Replaced Content module. WebKit and Mozilla have now implemented this proposal so that web authors can experiment with it, and provide feedback to the Working Group. Note that the proposal is still an editor’s draft, which means that it’s still possible, and even likely to change due to user feedback.
The main goal of the new syntax is simplicity; it’s now really easy to code up common gradients, as you’ll see in the examples below. A secondary goal was to specify something where implementations were compatible across browsers.
If you’re not already running one, go and grab a recent nightly build so that you can see the examples in this post.
Here are some simple examples (note that all these examples are resizable, so you can see how resizing the box affects the gradients):

Spaces disappeared

For some reason, the spaces between words on a font that I am using disappeared. See:
http://www.fantasynews.com/
I'm using Twitter Bootstrap slightly modified to use Google Web fonts. The font in question is Oswald served up by Google web fonts:
http://www.google.com/webfonts/specimen/Oswald
And the spacing appears normal for me there.
I'm no CSS guru, but I have touched nothing in my code that should alter the way spaces are displayed. I don't know of anything that should target spaces in particular. I feel like this is some dumb mistake that I'm overlooking but I'm clueless. If I view the source, the spaces are clearly there as well as the spaces clearly being there when I inspect the element, in case some bit of javascript was playing a trick.
I am using the latest version of Chrome, although this also appears in Firefox.
I should say that the spacing problem appears specifically for the title in the boxes under latest player news
I forced it by adding word-spacing: 0.25em to my CSS, but I'm not yet 100% sure that fixed it in every browser. It's unfortunate that Google doesn't have an obvious way to link to a particular version of a font so you could be confident it won't change from under you.
Removing font-weight: normal; fixes the spacing (there are 2 instances being applied to it, Inspect Element and you will see them)
EDIT: This is a bad font, you should choose another one! It looks fine bold, but the normal version is awful.
Same problem here, i applied another font to the online website and pray for a solution :(
It may be a wrong encoded file on google's servers. Nobody's safe from minor issue like these, even the guy who encode typos in the webfont service.
I usually use Firefox(newest) for Ubuntu 12.10. Everything looks fine there. In Chrome however, your fonts are most definitely squished. I personally would choose a different font that renders more consistently. If you want to learn more check out Mozilla's MDC Kerning page to get started.
The main way that I use kerning is with the letter-spacing property.
h2 {
letter-spacing: -0.1em;
}
To say that this addresses "kerning" would be false. This actually affects "tracking". The only difference between the two is that kerning is the relationship between two character and tracking relates to a block of text.

Resources