Can I use a custom value for font-name
property in @font-face
section in CSS?
E.g. if I have the properly working CSS:
@font-face {
font-family: "foo";
src: url(foo.otf) format('otf');
}
Is the font-family: "foo"
related to the contents of the foo.otf
or will it be valid to change the above CSS to:
@font-face {
font-family: "bar";
src: url(foo.otf) format('otf');
}
given of course that I will update all the references to this font-family
everywhere else. I.e. I will change font-family: "foo";
to font-family: "bar";
.
Some context.
I come across the issue in the following scenario. I have a complex online website (website A). I am developing a microfrontend for that website. That website does not expect me to load any fonts and I do not want to load any fonts when microfrontend is run in context of that website.
But there is another website (website B), in context of which I want my microfrontend to load fonts. So, I need to have the @font-face
section in my CSS.
Now the issue seems to be that website A somewhere in its CSS has font-family: "foo";
and also it loads my microfrontend before it loads its fonts, i.e. before it processes its own @font-face
section. So, it seems to rely on my @font-face
to load the "foo"
font. And it fails due to CORS restrictions on the server which hosts my microfrontend. The CORS configruations can not be changed due to application domain, they are there as expected.
So, I am thinking to kind of scope my `@font-face' only to my microfrontend with the help of the custom font name and was worried to check if it is a sane approach.
Can I use a custom value for font-name
property in @font-face
section in CSS?
E.g. if I have the properly working CSS:
@font-face {
font-family: "foo";
src: url(foo.otf) format('otf');
}
Is the font-family: "foo"
related to the contents of the foo.otf
or will it be valid to change the above CSS to:
@font-face {
font-family: "bar";
src: url(foo.otf) format('otf');
}
given of course that I will update all the references to this font-family
everywhere else. I.e. I will change font-family: "foo";
to font-family: "bar";
.
Some context.
I come across the issue in the following scenario. I have a complex online website (website A). I am developing a microfrontend for that website. That website does not expect me to load any fonts and I do not want to load any fonts when microfrontend is run in context of that website.
But there is another website (website B), in context of which I want my microfrontend to load fonts. So, I need to have the @font-face
section in my CSS.
Now the issue seems to be that website A somewhere in its CSS has font-family: "foo";
and also it loads my microfrontend before it loads its fonts, i.e. before it processes its own @font-face
section. So, it seems to rely on my @font-face
to load the "foo"
font. And it fails due to CORS restrictions on the server which hosts my microfrontend. The CORS configruations can not be changed due to application domain, they are there as expected.
So, I am thinking to kind of scope my `@font-face' only to my microfrontend with the help of the custom font name and was worried to check if it is a sane approach.
Share Improve this question edited Feb 6 at 17:56 manymanymore asked Feb 6 at 17:44 manymanymoremanymanymore 3,1097 gold badges34 silver badges76 bronze badges 5- developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-family: "The value is used for name matching against a particular @font-face when styling elements using the font-family property. Any name may be used, and this overrides any name specified in the underlying font data." – C3roe Commented Feb 7 at 7:02
- 1 Basically, you can specify by which name you want to refer to the font. It doesn't need to match the "intrinsic" name of the font used. – C3roe Commented Feb 7 at 7:04
- 1 You can choose any font-family name you like. In other words: the browser doesn't care if the name specified in CSS font-face coincides with the intrinsic name records in the font-file. If you encounter errors it is caused by other problems like CORS restrictions, wrong file paths, syntax errors etc. – herrstrietzel Commented Feb 7 at 7:04
- @C3roe, feel free to post your comment as an answer. That is exactly what I was looking for while asking this question. Thanks.