Search code examples
htmlcssfont-face

@font-face styling not working


I have put my @font-face styling in my css with a font that I downloaded and it doesn't seem to be working.

Here is my CSS:

@font-face {
font-family: "Quicksand";
src: url("fonts/Quicksand/Quicksand-Light.otf") format("opentype");
}

The font is called Quicksand and it is in my directory (a folder inside of where my index.html and main.css files are located) under a folder called "fonts" and there is a folder within this folder called "Quicksand", and the font that I want to use for the page is inside of this folder and its called "Quicksand-Light.otf".

Is there something that I'm missing?


Solution

  • This is the method with the deepest support possible right now. The @font-face rule should be added to the stylesheet before any styles.

    Ideal CSS should be like this

    CSS

    @font-face {
      font-family: 'MyWebFont';
      src: url('webfont.eot'); /* IE9 Compat Modes */
      src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
           url('webfont.woff2') format('woff2'), /* Super Modern Browsers */
           url('webfont.woff') format('woff'), /* Pretty Modern Browsers */
           url('webfont.ttf')  format('truetype'), /* Safari, Android, iOS */
           url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
    }
    

    Then use it to style elements like this:

    body {
      font-family: 'MyWebFont', Fallback, sans-serif;
    }
    

    checkout browser support and detail use https://css-tricks.com/snippets/css/using-font-face/