Using CSS font-family to select Droid fonts not working on Android

sorin picture sorin · Feb 22, 2011 · Viewed 14.5k times · Source

I discovered that the following HTML code does not work on Android (it will only use the default font: Droid Sans. On desktop it is working as expected.

<p style='font-family: "Droid Sans",sans-serif;'>vând whisky și tequila, preț fix.</p>
<p style='font-family: "Droid Sans Mono",monospace;'>vând whisky și tequila, preț fix.</p>
<p style='font-family: "Droid Serif",serif;'>vând whisky și tequila, preț fix.</p>

Answer

tadywankenobi picture tadywankenobi · Feb 23, 2011

You probably don't have an @font-face declaration for the other typefaces in your css. I imagine you only have one for Droid Sans. You need one for each typeface. For example, in your css you should have:

@font-face {
    font-family: 'DroidSans';
    src: url('font/DroidSans-webfont.eot?') format('eot'),
         url('font/DroidSans-webfont.woff') format('woff'),
         url('font/DroidSans-webfont.ttf') format('truetype'),
         url('font/DroidSans-webfont.svg#webfontw7zqO19G') format('svg');
    font-weight: normal;
    font-style: normal;

}

@font-face {
    font-family: 'DroidSansMono';
    src: url('font/DroidSans-Mono-webfont.eot?') format('eot'),
         url('font/DroidSans-Mono-webfont.woff') format('woff'),
         url('font/DroidSans-Mono-webfont.ttf') format('truetype'),
         url('font/DroidSans-Mono-webfont.svg#webfontSOhoM6aS') format('svg');
    font-weight: normal;
    font-style: normal;

}

@font-face {
    font-family: 'DroidSerif';
    src: url('font/DroidSerif-webfont.eot?') format('eot'),
         url('font/DroidSerif-webfont.woff') format('woff'),
         url('font/DroidSerif-webfont.ttf') format('truetype'),
         url('font/DroidSerif-webfont.svg#webfontw7zqO19G') format('svg');
    font-weight: normal;
    font-style: normal;

}

And then in your code, your font-family should be the same as those you declared in the css above (i.e. font-family: 'Droid Sans'; is not the same as font-family: 'DroidSans')

<p style='font-family: "DroidSans",sans-serif;'>vând whisky și tequila, preț fix.</p>
<p style='font-family: "DroidSansMono",monospace;'>vând whisky și tequila, preț fix.</p>
<p style='font-family: "DroidSerif",serif;'>vând whisky și tequila, preț fix.</p>

Try it and see how you get on.