Displaying Unicode CSS Font Awesome Icons as Boxes in a React Project

I have incorporated the jPlayer example into a create-react-app. Encountering an issue where font-awesome icons are displaying as boxes in this CodeSandbox illustration.

https://codesandbox.io/s/peaceful-heisenberg-d59nz?fontsize=14&hidenavigation=1&theme=dark

The icons are rendered using css rules that define content as unicode for <i> tags with the class fa.

I have installed the font-awesome dependency listed in the jPlayer example's package.json. Then, I created an AudioPlayer component and utilized the predefined skins by jPlayer. Despite successfully rendering the component, the icons appear as boxes, with the unicode content visible in the source code.

For instance, here is the play button in /src/AudioPlayer/AudioPlayer.jsx:

<Play><i className="fa">{/* Icon set in css */}</i></Play>

Subsequently, the AudioPlayer component is imported into App.jsx, which also imports a stylesheet containing this important rule:

.fa, .fas, .far {
    font-family: FontAwesome !important;
}

App.jsx is then rendered within index.js. The audio player's stylesheets are imported inside index.js as follows:

// Styles the jPlayer to look nice
import 'react-jplayer/dist/css/skins/sleek.min.css';
// Styles Play/Pause/Mute etc when icons (<i />) are used for them
import 'react-jplayer/dist/css/controls/iconControls.min.css';

The rule defining the play button in iconControls.css appears like this:

.jp-jplayer .jp-icon-controls .jp-play i:before {
  content: "\F04B";
  font-family: 'Font Awesome\ 5 Free';
  font-weight: 900;
}

In a final effort to resolve the issue of box rendering instead of font-awesome icons, I have included the font-awesome CDN within the head section of index.html.

Answer №1

It appears that in the styles.css file, there is a CSS rule using FontAwesome !important which seems to be overriding the FontAwesome 5 Free font. To display the correct fonts, you may want to consider removing this style.

fa, .fas, .far {
    font-family: FontAwesome !important;
}

Answer №2

When you see open squares instead of font characters:

  1. If the specified Unicode character is not in the font file.
  2. The requested font file cannot be found and there is no fallback option available.

With Font Awesome, this issue arises because there is no fallback font and the character may not exist in other fonts either.

This usually occurs when the browser cannot locate the font file due to path errors. Check your CSS for @font-face declarations to ensure paths are correct for your project. It is likely in the player's CSS file expecting a local file rather than from a CDN.

Webpack can sometimes modify file locations and update CSS paths, so consider moving files to a "static" directory if needed.

Verify that the font name matches what is available on your system. Font Awesome's Docs suggest using

font-family: "Font Awesome 5 Free";
, ensuring there are no extra backslashes in the declaration.

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

Using CSS3 to clear floats without altering the HTML structure

Despite searching for multiple solutions to this issue, I have yet to find one that works without requiring me to modify my HTML code. Here is the current HTML in question: <div class="name">Daiel</div> <div class="amount">30€</div ...

Make the background image draggable while maintaining its size with background-size:cover

I'm working on a fixed div with an image as the background, set up like this: <div style=' width:230px; height:230px; background-repeat: no-repeat; background-image:url(img/myimage.jpeg) background-size: cover;'&g ...

What is the best way to expand the width of my Bootstrap 4 navbar dropdown menu?

Need help creating a full-width dropdown for a Bootstrap 4 navbar using the standard boot4 Navbar? Check out the navbar template I am currently working with. Here is an example of how I want it to look: Desired design image link <nav class="navbar fix ...

Lost in Context: Uploading an Image Texture onto a Plane

I'm attempting to use a basic image as a texture for a plane in react-three-fiber. Feel free to take a look at the code-sandbox example here. Upon running this locally, I encounter the following message in the console: THREE.WebGLRenderer: Context Lo ...

"Utilize binding in ReactJS to maintain the correct context

I'm currently learning how to update states in ReactJS by following a tutorial. In the tutorial, I came across this line of code: this.updateLanguage = this.updateLanguage.bind(this). Although I grasp the basics of 'this' and 'bind&apos ...

Unable to initiate Next.js

After following the steps to set up the next.js environment, I encountered an error when trying to run yarn dev. Error Message: warning package.json: No license field error Command "dev" not found. Commands executed: ・yarn create next-app ・ ...

Update an API call to switch from promises to observables, implementing axios

Recently, I have been experimenting with using rxjs for API requests in a React application and this is the approach that I have come up with. What are your thoughts on this method? Are there any best practices that you would recommend following? If you ...

Is there a workaround for retrieving a value when using .css('top') in IE and Safari, which defaults to 'auto' if no explicit top value is set?

My [element] is positioned absolutely with a left property set to -9999px in the CSS. The top property has not been set intentionally to keep the element in the DOM but out of the document flow. Upon calling [element].css('top') in jQuery, Firef ...

Anticipated the server's HTML to have a corresponding "a" tag within it

Recently encountering an error in my React and Next.js code, but struggling to pinpoint its origin. Expected server HTML to contain a matching "a" element within the component stack. "a" "p" "a" I suspect it may be originating from this section of my c ...

Encountering a 404 error in my Next.js 14 application when attempting to render my file manually or through the use of the <Link> component

I'm having trouble accessing todolist.js. As a beginner, I believe the issue may be on my end. Here is the code and directory tree Even when I manually type localhost:3000/todolist, I still receive a 404 (Not Found) error. I want the todolist to rend ...

The render props on the child component are not appearing on the screen as expected

Recently diving into React Native, I created a stateless component designed to iterate through props that contain objects with arrays of tags. The goal was to extract and display a single tag from each array item. (Refer to the console log in the screensh ...

Is it feasible to have fixed headers adopt the width property?

Is there a way to align the widths of table elements while maintaining a fixed header row? If the 'fixed' property is disabled, the width spaces correctly but the header won't stay fixed and will scroll out of the container div. Enabling the ...

Encountering limitations in accessing certain object properties with the openweathermap API

As I integrate axios into my react application to retrieve weather data from the openweathermap api, I'm encountering some issues with accessing specific properties from the JSON object returned by the API call. For instance, I can easily access data. ...

Stylesheets do not have the capability to support template tags

Imagine you have created a stylesheet in Django within the static files and everything is working smoothly. However, when trying to use the following line, an error occurs: .PostProfilePic { width: 50px; height: 50px; border-radius: 50%; background ...

Changing the background image within a CSS class on an imported Vue component

Is there a way to dynamically change the background-image on a CSS class within an imported component? I have successfully installed 'vue-range-slider' and imported RangeSlider. The setup for the range-slider is as follows: <template> ...

Tips for accurately aligning the internal state of the input field with the value of React Hook Form

Currently, I am utilizing the MUI component library along with RHF for my form needs. In order to quickly generate forms, I wish to have my set of form fields managed by RHF. However, I am encountering an issue when it comes to syncing the internal state ...

Tips on implementing the setTimeout function within a conditional statement?

How can I display an alert message on the screen indicating whether the message was successfully sent (status 200) or if there were errors (else), with the message disappearing after 3 seconds? I typically implement this functionality within the useEffect ...

What is the best way to remove a property from an object in React if the key's value is set to false?

I'm currently working on a form component and I've encountered an issue. Whenever I submit the form, it returns an object with various fields such as email, fieldName1, fieldName2, first_name, last_name, and organization. Some of these fields are ...

React component performing AJAX requests

I have a React component that utilizes highcharts-react to display a chart fetched from an API using some of its state properties. export default class CandlestickChart extends React.Component { constructor (props) { super(props); this ...

Design a clickable div element embedded within an interactive article using HTML5

Currently, I am facing an issue with placing clickable div elements inside an article tag in HTML5. The problem is that when I try to click the divs, it registers as a click on the article itself. Below is an example of my code: HTML: <article id=&apo ...