What is the purpose of specifying the font-weight parameter when defining @font-face?

I am currently engaged in a React project.

origin

The font file resides within the following folder structure.

- src
    assets
       Fonts
           - NotoSansKR-Bold.otf
           - NotoSansKR-DemiLight.otf
           - NotoSansKR-Medium.otf
           - NotoSansKR-Regular.otf

In App.css located at the root, @font-face is configured as shown below.

@font-face {
  font-family: 'Noto Sans KR-Bold';
  src: url('./assets/Fonts/NotoSansKR-Bold.otf');
}

@font-face {
  font-family: 'Noto Sans KR-Medium';
  src: url('./assets/Fonts/NotoSansKR-Medium.otf');
}

@font-face {
  font-family: 'Noto Sans KR-Regular';
  src: url('./assets/Fonts/NotoSansKR-Regular.otf');
}

@font-face {
  font-family: 'Noto Sans KR-DemiLight';
  src: url('./assets/Fonts/NotoSansKR-DemiLight.otf');
}

Within the components situated in src/pages/, the font is utilized through styled-components in the subsequent manner.

const UserName = styled.div`
  margin-left: 6px;
  font-family: 'Noto Sans KR-Regular';
  font-style: normal;
  font-size: 14px;
  line-height: 20px;
  color: #262e33;
`;

Dilemma

The outcome remains consistent regardless of whether Bold, Medium, Regular, or DemiLight is designated. Essentially, it appears that the font style is not being implemented.

Upon investigation, it was uncovered that specifying font-weight as depicted below results in the appropriate font application when the corresponding font-weight and font-family are stipulated.

@font-face {
  font-family: 'Noto Sans CJK KR';
  font-style: normal;
  font-weight: 100;
  src: url("styles/fonts/NotoSansKR-Light.woff2") format('woff2'),
  url("styles/fonts/NotoSansKR-Light.woff") format('woff'),
  url("styles/fonts/NotoSansKR-Light.otf") format('truetype')
}

@font-face {
  font-family: 'Noto Sans CJK KR';
  font-style: normal;
  font-weight: normal;
  src: url("styles/fonts/NotoSansKR-Regular.woff2") format('woff2'),
  url("styles/fonts/NotoSansKR-Regular.woff") format('woff'),
  url("styles/fonts/NotoSansKR-Regular.otf") format('truetype')
}


@font-face {
  font-family: 'Noto Sans CJK KR';
  font-style: normal;
  font-weight: 500;
  src: url("styles/fonts/NotoSansKR-Medium.woff2") format('woff2'),
  url("styles/fonts/NotoSansKR-Medium.woff") format('woff'),
  url("styles/fonts/NotoSansKR-Medium.otf") format('truetype')
}

@font-face {
  font-family: 'Noto Sans CJK KR';
  font-style: normal;
  font-weight: bold;
  src: url("styles/fonts/NotoSansKR-Bold.woff2") format('woff2'),
  url("styles/fonts/NotoSansKR-Bold.woff") format('woff'),
  url("styles/fonts/NotoSansKR-Bold.otf") format('truetype')
}

Query

Yet, from my perspective, Bold, Medium, etc., merely signify variance in weight, and I remain puzzled about why indication of weight is necessitated despite the font thickness already being divided by otf file. Where do you think the error lies within my configurations?

Answer №1

Your configurations are correct. The issue lies within the @font-face rule.

The defined set of @font-face rules dictates which fonts can be used in documents where these rules are present. When matching fonts, those specified in these rules take precedence over other available fonts on a given system.

Documentation source

To simplify, check out this blog post on @font-face

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Choose all elements following the first child element

My goal is to create a LESS rule that targets every element following the current element, excluding the first child. I've tried using this syntax: (& ~ *):not(:first-child) { margin-left: 5px; } and also this one: & ~ *:not(:first-child ...

The function Router.transitionTo is not defined in React/Redux

I need help with redirecting within the re-base post callback in my component. Visit this link for more information My setup involves using re-base to store data in Firebase and Redux for state management. I attempted to pass the router via context, but ...

Tips for minimizing the dimensions of images in a slideshow within a gallery

Check out this website: The slideshow images on there are too tall. Can someone assist me in lowering the height of the images? I want both images to be displayed at the same height. Thank you in advance. ...

Having trouble getting the align-items-end property in Bootstrap 4 to function

After dedicating almost two full weeks to this project, I'm still struggling to achieve the desired outcome. I suspect that the issue may lie in the depth of the rows and columns I'm working with, but I'm open to any external perspectives or ...

"Enhance your client-side PDF capabilities with the pdfMake plugin, offering support for multiple languages

I am in search of a plugin that can convert HTML content into a PDF format and is compatible with javascript/jQuery/AngularJS. It must also provide multilingual support. I have experimented with the following two plugins, but encountered limitations with ...

Exploring an array in React using typescript

I have a persistent data structure that I'm serving from the API route of my Next.js project. It consists of an array of objects with the following properties: export interface Case { id: string; title: string; participants: string[]; courtDat ...

Rendering the Antd table in React without any data loaded

I'm new to using React and I'm facing an issue with populating an ant design table component through my API call. It seems that the table is rendering before the data is fetched completely from the API. I tried using conditional rendering but it ...

Employ jQuery to display a text box with a sliding motion upon hovering the mouse cursor over a specific area

Beginner inquiry about jQuery. Imagine I have a label on my webpage and I am looking to create a sliding effect for an input box when hovering over the label. Can anyone offer tips on utilizing jQuery to make this happen? ...

Checkbox fails to display as checked

I am currently working on implementing checkbox inputs in React JS. I have encountered an issue where the checkboxes do not visually show as checked when clicked, but I am still able to retrieve the value of the checkbox. Here is my code: Simple Checkbox I ...

"Exploring the Impact of Font Style on Text Color in Gtk3 Text

After creating a CSS provider using gtk_css_provider_new and loading it with gtk_css_provider_load_from_data, the style data "textview { color: red; font: 30px serif; }" is applied to a gtk_text_view using gtk_style_context_add_provider. However, the resul ...

Please provide the text to be shown on the button as a parameter

I have created an HTML code that includes a call to an uploader component. <app-uploader [Details]="Details" (onSubmit)="onSubmitEvent($event)"> </app-uploader> The app-uploader component contains the following line: <bu ...

Is your NextJS Link component failing to redirect correctly?

I'm currently delving into Next.js and embarking on a small experimental project to get more comfortable with it. However, I'm having some issues with the Link tag. It does redirect me to the specified friends page, but for some reason, the conte ...

Exploring the utilization of attributes with slots in Vue.js

Can attributes be set on a slot so that the element from the parent inherits those attributes? Parent <vDropdown> <button slot="button">new button</button> <ul>content</ul> </vDropdown> Dropdown.vue <d ...

Balancing the heights of div-columns using YAML code

I am currently working on creating a three-column layout using YAML. The grid feature of this framework is being utilized to position the columns (navigation, content, sidebar). Here's my question: How can I ensure that all three divs have the same h ...

Tips for showcasing individual row information in a popup window with Angular 9

Here is the code snippet for utilizing the open dialog method in the component: import { Component, OnInit } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { AuthService } from '../_services/auth.se ...

Troubleshooting: How can I resolve the issue of "Module not found: Can't resolve '@heroicons/react/solid' in my React application?

I stumbled upon this amazing article as I delve into learning React. However, I seem to be encountering some missing elements. Upon opening the application in my browser, I encounter the following error: ./src/components/Navbar.js Module not found: Can& ...

The site cache appears to be deactivated, but the source of the deactivation remains unclear. Can you help identify the issue?

On my PHP website, the <head> tag in the HTML includes: <meta http-equiv="Cache-Control" content="max-age=300"/> However, when checking the headers, it shows: Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre- ch ...

Is there a way to execute a Django For Loop within an HTML Div using JavaScript triggered by a Click Event?

I have a unique HTML div structured like this, <div class="coment-area "> <ul class="we-comet"> {% for j in comment %} <div id="delete_comment{{j.id}}" clas ...

Separate a single large table into two smaller tables based on the information found in the third column of every row

Looking for a Greasemonkey script that can split a single table on a page into two separate tables based on a specific column. For example, if we have the following table: <table> <tr> <td>Jill</td> <td>Smith</td ...

Rotating Images from an Amazon S3 Bucket within a React Application

My app allows users to take photos and store them in an AWS S3 bucket. The URL for each image is saved so that it can be viewed later. Oddly, when viewing the image directly in the S3 bucket, it appears correctly oriented. However, when accessed via the ap ...