jsindos
jsindos

Reputation: 539

Why is Chrome not displaying my @font-face?

I am loading a Hello World html file in Chrome 95, with a declared @font-face loaded from Google fonts. The font is correctly loading, which I can verify in the Network tab, but for some reason my div is rendering as Times.

What am I doing wrong?

<html>
<div style='font-family:OpenSans-Regular;'>
    Hello World!
</div>
</html>
<style>
    @font-face {
      font-family: OpenSans-Regular;
      font-style: normal;
      font-weight: 400;
      font-stretch: 100%;
      font-display: swap;
      src: url(https://fonts.gstatic.com/s/opensans/v27/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTSKmu0SC55K5gw.woff2) format('woff2');
    }
</style>

Upvotes: 0

Views: 143

Answers (1)

vee
vee

Reputation: 4765

From Google fonts document, you should use <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Font+Name"> instead of write them directly.

Your <style> element are in wrong place, there are no <body> element in your HTML.

<html>
    <head>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans">

        <style>
            * {
                font-family: "Open Sans";
            }
        </style>
    </head>
    <body>
        <div style='font-family:Open Sans'>
            Hello World!
        </div>
    </body>
</html>

Upvotes: 1

Related Questions