Search code examples
cssfontsfont-facewebfonts

Working with web (@font-face) fonts


I have a basic question that probably refers more to design field, but still it is a web programming.

Let say I need to use Palatino-Linotype font in my web application. How do I better embed it in to my web page application?

My known way:
1) Go to font.com and buy all kinds of palatino-linotype: normal, bold, italic, italic-bold. 4 different files.
2) Then I load fonts via fontface style

@font-face {
    font-family: "Palatino-Linotype-normal";
    src: "..."
}
@font-face {
    font-family: "Palatino-Linotype-italic";
    src: "..."
}

3) A I have 4 different fonts, in HTML markup I need explicitly set font of the element to make it bold, or italic, or italic-bold (that what I don't like the most).

Question:
1) is that workflow of using custom web fonts?
2) Maybe there is a way to treat this fonts as usual fonts in term of setting only one font on parent element, and for inner set only style="font-style: italic;" if I want them to be italic.
3) question about performance, does web font rendering speed differs from rendering of usual fonts?


Solution

  • The logical way, generally supported by browsers, is to declare each typeface in a separate rule, as in

    @font-face {
        font-family: foobar;
        src: url("foobar-regular.woff");
    }
    @font-face {
        font-family: foobar;
        font-style: italic;
        src: url("foobar-italic.woff");
    }
    

    and then just declare font-family: foobar and use font-style: italic directly or indirectely via <i>, <em>, and other markup that causes default rendering in italic.

    I have simplified the code in an obvious way; naturally you should normally make the font available in different formats, as recognized by browsers.

    Services like FontSquirrel generate different code, but it is fairly straightforward to fix the code they produce, or write the code from scratch.

    I have intentionally used “foobar” and not “Palatino Linotype”, since the latter is not legally available for use as a downloadable font; at least this is what presume until proven otherwise. (There are many sites on the web that distribute or sell fonts illegally.)