'font-' vs 'text-' in CSS property names - css

What is the difference between the terms 'text' and 'font' as used in CSS property names? Do they mean the same thing, or is there a semantic difference between a CSS property name starting with font- and one starting with text-?
For example, why do we have these CSS properties:
font-size: 34px;
text-decoration: underline;
instead of them being named like this?
font-size: 34px;
font-decoration: underline;
or like this?
text-size: 34px;
text-decoration: underline;
Is there a semantic difference in the way font- and text- are being used here, or is the choice of prefix completely arbitrary?

As far as my understanding goes about this:
Text: The way the layout and presentation is computed.
Font: A character to glyph mapping. The 1-to-1 'mapping' doesn't entirely hold up when you consider ligatures and other advanced font features, but in general it is a good mental model. The font determines the shape of the characters.
You can underline text drawn with a certain font, but you cannot underline the font itself. You can, though, resize the shapes such that text drawn with that font has larger glyphs. (hence, font-size)
That's also why you have font-style: italic and not text-style: italic, since the actual shapes change when you typeset in italic. The same goes with font-weight vs text-weight.
Hope this helps.
If you look at the properties starting with text- and those starting with font- you can see a clear difference:
text-align
text-decoration
text-indent
text-justify
text-outline
text-overflow
text-shadow
text-transform
text-wrap
These are all used for layout, positioning or visual presentation of the text.
font
font-family
font-size
font-style
font-variant
font-weight
#font-face
font-size-adjust
font-stretch
And these are all used to transform the shapes of the characters, the glyphs.

The parts of a CSS property name have no meaning, and the property name as a whole has only the meaning assigned to it in CSS specifications (or drafts). Usually the names, when interpreted as English words, are suggestive of the meaning, but the name does not define the meaning, and some names are outright misleading. (For example, white-space affects division into lines even in contexts where no whitespace characters are involved.)
So the names are just identifiers, but there might be some systematics in the assignment of names. As it happens, property names that start with font- relate to the choice of typeface used to render characters or a specific way of using a typeface. Property names that start with text- relate to other aspects of formatting text (characters).
This division is relatively clear, but it depends on the techniques: some features of formatting are font-related, due to the way font technologies work, some are not.
The division is reflected in CSS3 “module” division: font-related features are defined in CSS Fonts Module Level 3 (which defines properties with names beginning with font), whereas other text-formatting features are mostly defined in CSS Text Module Level 3 (which defines some properties with names beginning with text-, but also other properties).

Looking over the font- properties listed on MDN's CSS Reference, it seems to me that properties starting with font- affect, or at least have the potential to affect, the choice of which font from within the font-family to use to draw a particular character. Properties starting with text- never do this, but do all kinds of other stuff, including post-rendering to add text effects like shadows that are independent of glyph choice.
For instance...
font-family - provides a list of font families from which to choose a font with which to render each character; obviously, this affects glyph selection.
font-weight - where possible, shows the text at the correct level of boldness by selecting an appropriately bold font from within the font-family.
font-size - may apparently affect the actual font chosen, because not all font formats are arbitrarily scalable. This is corroborated by the following quote from the font-family docs (emphasis mine):
When a font is only available in some styles, variants, or sizes, those properties may also influence which font family is chosen.
(Although I'd guess this is mostly a historical issue, since I don't think non-scalable font formats are still in use today.)
font-size-adjust - much like the above.
font-stretch - to quote the docs:
This property does not change the geometry of an arbitrary font by stretching or shrinking it. Like font-feature-settings or font-variant, it is merely a mean to choose the most appropriate face of the font, if this one offers several of them.
... and so on. Not all these properties always affect font selection; for instance, font-size is obviously about glyph rendering, not font selection, in the case of scalable fonts, and the font-weight and font-style properties may result in the browser synthesising bold or italic glyphs rather than using a bold or italic font, as noted by W3:
Although the practice is not well-loved by typographers, bold faces are often synthesized by user agents for faces that lack actual bold faces.
The thing that the font- properties have in common, though, is that they are the properties that can potentially affect font and glyph selection. So the choice of when to use the font- or text- prefix seems not to have been made arbitrarily.

Related

web fonts that support small-caps?

is there any open web font that fully supports small-caps?
For example if I set Roboto to small-caps, the result will look like this:
You see that the uppercased letters R and A have a higher weight than the surrounding lowercased letters. This font does not support small-caps properly.
Give a call to the foundry, every font is designed differently, if they don't have the glyphs you wont be able to have that, when I purchased the license for the webfont for the company that I work, I called the foundry I was budgeting they helped me to choose the perfect font that had the Small caps with it.
Yes, this is possible. Try using the font-variant and font-variant-caps css rules. Take a look at the MDN Docs on these properties for more info, here and here.
small-caps, all-small-caps, petite-caps, all-petite-caps, unicase, titling-caps
Specifies the keywords and functions related to the font-variant-caps longhand property.
small-caps
This keyword forces the use of small capitals letters for lower case characters. It corresponds to the OpenType value smcp; if the font doesn't support them, it synthesizes the glyphs.
.my_style {
font-variant: small-caps;
}
<p>Hello</p>
<p class="my_style">hello</p>

CSS Webfont not rendering missing character

I'm using the "Quicksand" font for a web project (http://www.google.com/fonts/specimen/Quicksand) and I've a problem : the ² character doesn't exist for that font. I thought that it would be rendered in other fonts (written after Quicksand in the font-family property), but it is not. When I write ², the only thing rendered is a white space.
Is there a way to render not supported characters by other fonts ?
Here's the CSS used :
font-family: "Quicksand", Helvetica, Arial, sans-serif;
There is a bug in the Quicksand font: for the Unicode code position U+00B2, SUPERSCRIPT TWO, it has an empty glyph. It is 396 units wide, so it is wider than a normal SPACE (300 units) in the font. Another character with a similar problem is U+201A SINGLE LOW-9 QUOTATION MARK “‚”, which has an empty glyph 230 units wide.
In principle, you could circumvent the bug by using unicode-range in a #font-face rule to specify that a particular character be taken from a different font. However, browser support is still too limited (and the approach would require that you host the font files instead of using them from the Google server).
Another possibility would be to edit the font. This requires a font editor and a permission from the copyright holder (and your hosting the font files of course).
A third option is to wrap each occurrence of “²” in a span element with a class and setting font-family on them suitably. Beware that this means mixing glyphs from different fonts, which should be avoided in good typography.
Finally, consider using a different font. There are several questions about rendering problems with the Quicksand font at SO.

Setting different line heights depending on the font

I'd like to set different line-height for different fonts from a list fall-back fonts. For example:
body {
font-family: "Small x-height font", "Larger x-height font", sans-serif;
}
When the preferred Small x-height font is used, I'd like to set line-height to 1.3. When Larger x-height font is used because the preferred font is not available, I'd like to set line-height to 1.5. When both fonts are not available and the sans-serif fallback is used, I'd like to set line-height to normal.
Is this possible using CSS 2.1 or CSS 3 without resorting to JavaScript?
Rationale The problem is that different fonts have different x-height (the height of lowercase letters such as x relative to the font size). To make text with larger x-height look good, it must be set with a larger line height. The x-height of the default fonts (sans-serif in the example above) is unknown and may differ drastically from the x-height of the font of our choice. So a line height that looks good with our font may look ugly when the font failed to load.
I don't believe there is a way to do this in the exact way you are requesting.
However, I can tell you that if you are using a font service (eg Typekit), you may be able to style fallback fonts depending on whether the font has been loaded or not.
In Typekit's case, they add classes to the element when the font is loading, loaded, or inactive. They also provide classes for the specific fonts/weights.
You can then provide specific styling depending on the situation.
Here's a rough example:
body {
font: 400 16px/1.5 "typekit-font", "fallback-font";
}
.wf-inactive body {
font-weight: normal;
line-height: 1.8;
}
More information can be found in their corresponding help article.
There is a font-size-adjust property in CSS3 which addresses this problem. You can specify font-size-adjust: 0.6 for your body and all fonts will be transparently scaled to have the x-height of 0.6em. This has the additional benefit that you can combine fonts with different original x-height on the same line and they will have roughly the same lowercase letter size without the need to adjust font sizes manually.
Only Firefox implements font-size-adjust (as of November 2012). WebKit does not.
See the CSS3 Fonts specification for more information and David Baron's post for some examples.
In CSS, you cannot make the value of a property depend on the choice of a font. Basically, properties are independent of each other, with some exceptions that do not apply here.
Normally, fonts in a font-family list should be more or less similar in general characteristics. It’s not just a line-height matter. The choice of a font affects the page as a whole.
A different strategy is to use a downloadable font via #font-face. Then you can be reasonably sure that your font will be used, and you can set line height and other properties according to it.

Assigining different font-size per each font in one font-family

I'm making a webpage in a language other that English.
So the text contains English and other languages mixed.
I assigned font-family like
p{
font-family: 'EnglishFont', 'NonEnglishFont';
font-size:14px;
}
It works fine, but the original vector size of the fonts differs, causing the sentence looks weird in mixed languages.
so I want to assign different size for font in one css class, something like
p{
font-family: 'EnglishFont', 'NonEnglishFont';
font-size:14px, 16px;
}
is there any way to do that?
You cannot set font size so that it would depend on the font family.
Instead, try and find a font that is suitable for both (or all) languages on the page. The font designer should have taken the different characteristic of different writing systems into account. Usually fonts designed for e.g. Asian languages have Latin letters, too (at least the basic Latin letters, which mostly suffice for English).
If you really want to set different font properties for different writing systems, you need to use markup that distinguishes between different languages, e.g. using lang attributes in HTML and selectors based on them in CSS. But normally the use of different fonts is a problem to be avoided, rather than a solution.

Are all CSS font-weight property's values useful?

font-weight:normal
font-weight:bold
font-weight:bolder
font-weight:lighter
font-weight:100
font-weight:200
font-weight:300
font-weight:400
font-weight:500
font-weight:600
font-weight:700
font-weight:800
font-weight:900
I've only used font-weight:bold and sometimes font-weight:normal to override bold so far. What are the usages of the others?
I created this example page with all the values for the property, but there's not much difference in many of them.
http://jsbin.com/omaha3
If the font you are displaying has more weights like semi-bold, light, etc. the browser may be able to render those weights if you use one of the numeric values. Most end-user fonts come with two or three styles only, though, so I don't think this is much applicable to the real world. I would rely on normal (=400 I think) and bold (=700) only.
There's good additional info in the W3C reference on font-weight: bold as well.
Update: Here is an in-depth blog post on how the styles are rendered in modern browsers. It is titled "Font-weight is still broken in all but one browser" :)
2nd Update: As clagnut.com suffered a catastrophic dataloss here is the archived post
It depends on the browser/OS too. Firefox on the Mac tends to support more graduations (5 different weights for Myarid pro) and Firefox 3 on Windows will sometimes display a light font. The other browsers on Windoows or Mac only display two weights - bold or normal.
When I want cross-browser control of font-weight, I set my text color to a grey - say #777 and then my bold colors can be #444 and #000 and my lighter colors can be #aaa and #ddd. It doesn't change the thickness like font-weight does but it still gives the visual impact.
edited to add the IE6 craziness with font-weight
font-weight:600 in a print stylesheet causes IE6 to print out bold and italic but print preview shows only bold.
Depends on requirement, and can be useful when you are creating proportional font sizing for stylish textual looks.

Resources