x

Can we use font-display- Swap by editing main.less file in weebly editor?

I want to add a font-display attribute to all the texts on my Weebly site, as having a site on Weebly free plan I don't have enough flexibility, so can I use the font-display CSS feature by editing Weebly editor like this:

(I am a beginner in HTML/ CSS)

Weebly editor > Themes > edit HTML/CSS > main.less > then adding this CSS code:

body {

font-display: swap;

}

Thank you for the support.

3,407 Views
Message 1 of 9
Report
8 REPLIES 8
Square

I'm not super familiar with editing the code, @Jitesh. What are you trying to do with the font? What is the purpose of the "swap"? 

3,377 Views
Message 2 of 9
Report

Hi @Bernadette ,

When browser loads a webpage then texts remains invisible for a few seconds and gets visible again when the font files are loaded, right. So by adding swap CSS property the browser would load a default font until the font files are loaded. After the webpage font file are fully loaded then the browser would "swap" the default fonts with that font.

It is useful to improve your website lighthouse score.

We can also add other css attributes instead of swap like auto, optional, fallback, etc.

Give this a quick read: 

3,373 Views
Message 2 of 9
Report
Square

Did you add that CSS rule to your site theme's CSS, @Jitesh? You can probably add that to any of the .less files, although it would probably make the most sense to see what CSS rules are already there for the body tag in main.less, then add it with those.

3,357 Views
Message 2 of 9
Report

Hi @Adam,

I am on a free Weebly plan (I have a Weebly subdomain), so I could not see the CSS on main.less files as they are called by using the import command. Moreover, I can't edit those CSS files even if I find those out as they might be hosted on the main Weebly domain.

3,351 Views
Message 2 of 9
Report
Square

The other less files should be listed there - you may need to look through them to find which one has body styling in it. You're going to Theme > Edit HTML / CSS, right?

3,342 Views
Message 2 of 9
Report

Yes @Adam, there are more folders (global.less and font.less), global one has the body tag and font folder has the @font-face tags, so on which folder should I place the font-display CSS property?

3,309 Views
Message 2 of 9
Report
Square

I would put it in the global less file; it's usually a good idea to keep everything together like that so you don't have to look through a bunch of different files later.

3,305 Views
Message 2 of 9
Report

Ok, Thanks @Adam 

3,289 Views
Message 2 of 9
Report