Search code examples
cssgoogle-font-api

Google webfonts - is there a way to @import instead of <link> embed?


Working on a website for a client - long story, but I'm not allowed to edit markup, just include an override stylesheet and make tweaks through there.

I need to import a google font, but because of the requirement I can't use the normal embed method. Is there a way to @import a google font inside a stylesheet?

EDIT: To clarify, I've already added the following code with zero success (returns a 404):

@import url(http://fonts.googleapis.com/css?family=Open+Sans+Condensed:300,700,300italic);


Solution

  • Sure. If you have access to the style sheets just add the code generated by google url directly.

    This is the google generated url for the font "Dancing Script": http://fonts.googleapis.com/css?family=Dancing+Script Paste that in a browser address bar and you will be shown the code you need to place in CSS file.

    See fiddle: http://jsfiddle.net/David_Knowles/XVMzf/3/

    @font-face {
        font-family: 'Dancing Script';
        font-style: normal;
        font-weight: 400;
        src: local('Dancing Script'), local('DancingScript'), url(http://themes.googleusercontent.com/static/fonts/dancingscript/v3/DK0eTGXiZjN6yA8zAEyM2bDH3ri20rYH10B2w3wbVeU.woff) format('woff');
    } 
    
    a {font-family: 'Dancing Script',serif,cursive;}