# Embedding webfonts in css not working

**URL:** https://forum.codewithmosh.com/t/embedding-webfonts-in-css-not-working/18473
**Category:** HTML/CSS
**Created:** [March 1, 2023, 3:14am UTC](https://forum.codewithmosh.com/t/embedding-webfonts-in-css-not-working/18473 "2023-03-01T03:14:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![davidp71](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@davidp71](https://forum.codewithmosh.com/u/davidp71)
#### Post date: [March 1, 2023, 3:14am UTC](https://forum.codewithmosh.com/t/embedding-webfonts-in-css-not-working/18473/1 "2023-03-01T03:14:45Z")

</div>

I’ve followed the instructions on the embedding webfonts in the HTML/CSS course, module 2.

Copying the WOFF2 and WOFF files into the /fonts/opensans folder as per instructions and then when I go to add fonts in the property font-family: the opensans font-family isn’t on the list.

 ![Screenshot from 2023-03-01 14-13-21](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/8/8908eae4de24f187174739c3939ddbe87fdfd599.png)

Attached is a screenshot from my styles.css file with the missing font-family.

---

<div class="post-metadata">

### Author: ![UniqueNospaceShort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/uniquenospaceshort/32/1814_2.png) [@UniqueNospaceShort](https://forum.codewithmosh.com/u/UniqueNospaceShort)
#### Post date: [March 1, 2023, 6:28pm UTC](https://forum.codewithmosh.com/t/embedding-webfonts-in-css-not-working/18473/2 "2023-03-01T18:28:15Z")

</div>

Hi I actually did such operation on a project recently.  
I also had to convert True Type fonts to WOFF2 from a Linux machine.

> **Pro Tip**  
> For reference there is a Linux package to install. _woff2_ It has tool to convert TTF to WOFF/WOFF2.

As of your problem, it is difficult to say because you have a popup covering all the code.

I will give you an example that worked for me.

Say you have such folder structure.

- _index.html_
- _static_
  - _css_
    - _styles.css_
    - _fonts.css_

  - _fonts_
    - _myfont.woff2_
    - _myfont-italic.woff2_
    - _myfont-bold.woff2_

> _fonts.css_

```auto
 @font-face {
     font-family: "My Font";
     src: url(../fonts/myfont.woff2);
 }

 @font-face {
     font-family: "My Font";
     src: url(../fonts/myfont-italic.woff2);
     font-style: italic;
 }

 @font-face {
     font-family: "My Font";
     src: url(../fonts/myfont-bold.woff2);
     font-weight: bold;
 }

```

> _styles.css_

```auto
@import url(fonts.css);

```

> _index.html_

```auto
<link rel="stylesheet" href="static/css/styles.css" />

```

Hope this helps.

---

<div class="post-metadata">

### Author: ![davidp71](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@davidp71](https://forum.codewithmosh.com/u/davidp71)
#### Post date: [March 1, 2023, 9:29pm UTC](https://forum.codewithmosh.com/t/embedding-webfonts-in-css-not-working/18473/3 "2023-03-01T21:29:40Z")

</div>

Thanks for the advice.  
When I type in ‘opensans’ for font-family and save the CSS file.  
It applies to the HTML file its linked to.

It just doesn’t come up automatically after typing in the font-family property with all the other font options.

So it works. but not like in the lesson.

Thanks again.

---

<div class="post-metadata">

### Author: ![UniqueNospaceShort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/uniquenospaceshort/32/1814_2.png) [@UniqueNospaceShort](https://forum.codewithmosh.com/u/UniqueNospaceShort)
#### Post date: [March 2, 2023, 5:40pm UTC](https://forum.codewithmosh.com/t/embedding-webfonts-in-css-not-working/18473/4 "2023-03-02T17:40:01Z")

</div>

Ah ok so the problem is more related to the tool.  
I must say that VS Code surprised me with having those things work across files I edited. On the other hand it did not work when I expected it to.

I do not know how VS Code does that.

Now there are functionalities in VS Code that work only if you are trusting the environment.

For instance the markdown plugin I use inserts a new hyphen automatically upon line break if the environment is trusted but has no reaction if it is not. This is something to try.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/5/5823a1f92d53fdf3f765d0bf7ab735afffcc8c59.png)

I do not why I did not find the icon to trust my environment like I did in other machines. There was an icon on the bottom left corner of the window.

Now like almost everything use the magic Ctrl+⇑+P and type “Trust” then _Workspaces: Manage Workspace Trust_

Hopefully this helps.

Cheers

---

<div class="post-metadata">

### Author: ![techytony](https://avatars.discourse-cdn.com/v4/letter/t/e9bcb4/32.png) [@techytony](https://forum.codewithmosh.com/u/techytony)
#### Post date: [May 5, 2024, 5:25pm UTC](https://forum.codewithmosh.com/t/embedding-webfonts-in-css-not-working/18473/5 "2024-05-05T17:25:43Z")

</div>

I am not expert on this at all, but I am on this excat session as well, it’s my understanding fonts to not show in the list, that list is the “web safe fonts”

It’s my undertanding after you ghave registered the fonrt, you can do font-family then add the font you want manually

I could be wrong, this is what I got out of this section.
