DEV Community

Discussion on: How to load a google font in a web component ?

Collapse
 
kodertian profile image
kodertian

Ex.: Assuming we have in the index.html head a link tag to the google font, eg:
.

In an external index.css file we have declared something like:
:root {
--jos: 'josefin slab';
} .

Then in the web component's style we could do:
:host {
font-family: var(--jos)
}

But I believe you don't want the google font declared in the outside index.html file, so in the WC style we could do something like:

@import url("fonts.googleapis.com/css?family=Jo...);

:host {
font-family: "Josefin Slab";
}

That would work.

Collapse
 
remjx profile image
Mark Jackson • Edited

This isn't working for me, I can only get the font to load if I put the font <link> in the html <head>