I am having trouble accessing a font stored locally using @font-face in React with CSS

Having some trouble loading the "Inspiration-Regular.tff" font from theme.js.

The URL is accurate and there are no issues there.

In line 137 of the code, I am setting "Inspiration-Regular.tff" as the body's font-family, but despite the element showing that the "font-family" has been updated, the visual default font remains unchanged. Why isn't the font changing?

To get an idea of how inspiration-regular should look, here is a snippet:

Answer №1

The @font-face declaration you have contains an error in the format specification:

To correctly specify truetype fonts, use format('truetype').

While most modern browsers can load the font without a specific format, including this value is recommended for better compatibility.

/* working example */

@font-face {
  font-family: 'FiraCorrect';
  font-style: normal;
  font-weight: 400;
  src: url(https://fonts.gstatic.com/s/firasans/v16/va9E4kDNxMZdWfMOD5Vvl4jO.ttf) format('truetype');
}


/* non-working examples */

@font-face {
  font-family: 'FiraIncorrect';
  font-style: normal;
  font-weight: 400;
  src: url(https://fonts.gstatic.com/s/firasans/v16/va9E4kDNxMZdWfMOD5Vvl4jO.ttf) format('ttf');
}


@font-face {
  font-family: 'FiraInDifferent';
  font-style: normal;
  font-weight: 400;
  src: url(https://fonts.gstatic.com/s/firasans/v16/va9E4kDNxMZdWfMOD5Vvl4jO.ttf);
}

.correct {
  font-family: 'FiraCorrect';
  font-weight: 400;
}

.inCorrect {
  font-family: 'FiraIncorrect';
  font-weight: 400;
}

.inDifferent {
  font-family: 'FiraInDifferent';
  font-weight: 400;
}
<p class="correct">Correct @font-face: format(truetype)</p>
<p class="inCorrect">Incorrect @font-face: format(ttf)</p>

<p class="inDifferent">Incorrect @font-face: no format specified</p>

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

The onChange function in CustomSelect is triggering an endless loop of renders in a React application using TypeScript and Material-

Currently, I am working with a mui element called CustomSelect. It functions perfectly on desktop, however, the handleChange function from onChange only console logs once. On mobile (even in development mode), it renders 51 times before crashing and displa ...

What is the best way to create a "select all" check box in HTML and display the selected values in a div?

$(function () { //This function selects all checkboxes and unchecks selectall if any checkbox is not checked. var checkall = $('#checkall'); var boxes = $('input[type="checkbox"]').not(checkall); checkall.click(function ...

Using the `map()` method in React's array

I stumbled upon an interesting example at http://codepen.io/lacker/pen/vXpAgj that closely resembles my current issue. Let's consider the following array: [ {category: 'Sporting Goods', price: '$49.99', stocked: true, name: &apo ...

A guide on implementing horizontal scrolling in React with mouse wheel functionality

Utilizing tailwind-CSS in react js, my aim is to enable horizontal scrolling via mouse wheel when a user hovers over the card section. This way, PC users can easily scroll horizontally using just the mouse wheel, eliminating the need for both the shift key ...

The CSS selector "not:nth-child" is failing to function properly within the template

Trying to apply a margin-top to all labels except the first one in a row using the :not() and :nth-child selectors. Having trouble with my selector, can anyone help? .form-group:not(:nth-child(1)) + .label { margin-top: 20px; } <div class="form- ...

When trying to refresh the page using react-router, the result is a blank page with the bundle.js not

I have encountered an issue where I am able to access all paths without any problems until I refresh the page. Upon refreshing, I am greeted with a blank page and no error messages. Despite searching for solutions related to this problem, none have seemed ...

The issue of NextJS React Context API not properly updating values even when implementing useState() functionality

In my NextJS web app, I have implemented a React Context API to persist a value across the application. While I am aware that I can utilize the Consumer tag within the Provider tag to update the value like this: <ProfileContext.Provider> <Prof ...

Enhancing the efficiency of a JavaScript smooth scrolling feature for numerous listed items

I have been experimenting with recreating the recent Apple Mac retrospective using only CSS and JavaScript to create a small timeline of projects. While I have successfully implemented the layout for the full-screen hero and the expand-on-hover effect, I a ...

Tips for adjusting the font color of certain elements in Numpy

I am seeking a method to change the font color of specific elements to highlight them in a numpy array. I found a solution to this problem on Stack Overflow at this link: Coloring entries in an Matrix/2D-numpy array? In my approach, I have created two func ...

Any ideas on how I can enable rotation of SVG images within a Bootstrap 4 Accordion card with just a click?

I'm working on a Bootstrap 4 accordion card that has an SVG arrow image in each header. I am trying to make the arrow rotate 180 degrees when the header is open, and return to its initial state when it is closed or another header is opened. Currently, ...

React - The mechanics behind a spinning roulette wheel

I've been attempting to create a React roulette spinner but I've encountered some issues with the transitions and functionality. Here is the initial version of the algorithm: The callback functions are triggered whenever the 'winner&apo ...

The property "state" of RouteComponentProps location does not exist in the provided type {}

We recently encountered a new error that was not present before. Previously, our code compiled without any issues and the compilation process went smoothly. However, individuals who installed the react application from scratch are now facing an error speci ...

Issue with props not being updated when Redux store state changes in Reactjs

When I make a call to the 'getGame' method after retrieving data from an API and updating the store, the props of my component do not update. However, everything works fine when using the 'getGames' method. I have confirmed that the ac ...

The video does not begin playing automatically after utilizing react-snap

I included a background video in my react app that auto-plays upon page load and functions perfectly. Here is the JSX code I used: <video autoPlay loop style={{ backgroundImage: `url(${topVideoImage})`, }} muted playsInl ...

What is the best way to make a DIV box span the entire webpage without overflowing to the left?

I am currently working on a client's website and running into some issues with the layout of the booking page. The address is supposed to be on the left side, the contact form on the right, and both should be contained within a white box that fills th ...

Don't give up on the entire task just because one promise was rejected

To handle multiple promises in redux saga, you can use the all function (equivalent to Promise.all): yield all( users.map((user) => call(signUser, user)), ); function* signUser() { yield call(someApi); yield put(someSuccessAction); } An issue ...

Encountering a problem with library functions while attempting to import a module

At the moment, I am utilizing NodeJS. I have been attempting to import a module into a component function and everything appears to be running smoothly. However, I keep encountering this error in the server console: error - src\modules\accountFu ...

What is the best way to create a responsive grid layout for my form using Bootstrap?

I have designed a form using bootstrap 5 with 1 row containing 4 columns (1 dropdown menu and 3 buttons). While it looks fine on my desktop, the problem arises when I view the page on a mobile device. The buttons shrink and remain on the same row instead o ...

Trying out basic form validation - Adjusting border color for an empty input

Currently, I am experimenting with a basic login form using PHP and testing it out on XAMPP in Chrome. Below is the code for the login form: <form action="login.php" method="POST"> <label>User: </label> <i ...

MaterialTable: Render HTML tag within the field property

For my react application, I am utilizing the MaterialTable library to showcase a table grid. The server responds with an object containing an HTML tag like this after making an API request: { "name": "Test", "link": ...