Skip to main content

Using CK Editor 5, I needed to add instructions to a page that held FontAwesome (FA) icons.  Included in these instructions were a couple of FA icons.  Initially adding them was going to be resolved using Pseudo-elements.  Accordingly they would be applied as follows:


.download-icon, .portal-icon {
  position: relative;
  display: inline-block;
  text-rendering: auto;
  -webkit-font-smoothing: antialiased;
}

.download-icon::before,
.portal-icon::before {
  font-family: FontAwesome;
  top: 0;
  left: -5px;
  padding-left: 4px;
  padding-right: 0;
}

.download-icon::before {
  content: "\f33d";
}

.portal-icon::before {
  content: "\f14c";
}

However, one of the icons partially worked (wrong weight) and the other had the doomed FA square.

To get the weight correct you can use

font: var(--fa-font-light);

But issues remained getting the icon instead of the square.

Pseudo-elements have there challenges.

 

What about if I applied the FontAwesome i tag.  The key to remember is i tags in CKEditor are removed if there is no content.  The following line

<p>Reports are available as a downloadable PDF <i aria-hidden="true" class="fal fa-arrow-to-bottom"></i> or via the portal <i aria-hidden="true" class="fal fa-external-link-square"></i></p>

On saving would become

<p>Reports are available as a downloadable PDF  or via the portal </p>

Adding a space will keep them as display

<p>Reports are available as a downloadable PDF <i aria-hidden="true" class="fal fa-arrow-to-bottom">&nbsp;</i> or via the portal <i aria-hidden="true" class="fal fa-external-link-square">&nbsp;</i></p>

 

Related articles

Andrew Fletcher04 Apr 2025
Managing .gitignore changes
When working with Git, the .gitignore file plays a critical role in controlling which files and folders are tracked by version control. Yet, many developers are unsure when changes to .gitignore take effect and how to manage files that are already being tracked. This uncertainty can lead to...
Andrew Fletcher26 Mar 2025
How to fix the ‘Undefined function t’ error in Drupal 10 or 11 code
Upgrading to Drupal 10.4+ you might have noticed a warning in their code editor stating “Undefined function ‘t’”. While Drupal’s `t()` function remains valid in procedural code, some language analysis tools — such as Intelephense — do not automatically recognise Drupal’s global functions. This...
Andrew Fletcher17 Mar 2025
Upgrading to PHP 8.4 challenges with Drupal contrib modules
The upgrade from PHP 8.3.14 to PHP 8.4.4 presents challenges for Drupal 10.4 websites, particularly when dealing with contributed modules. While Drupal core operates seamlessly, various contrib modules have not yet been updated to accommodate changes introduced in PHP 8.4.x. This has resulted in...