Optimal method for utilizing @font-face syntax

Recently, I've been utilizing this specific model

@font-face {
font-weight: WEIGHT;
font-style: STYLE;
font-family: 'NAME';
src: url('font.eot');
src: url('https://dl.dropboxusercontent.com/s/dey3lzjdpgszxzt/myriad-webfont.eot?#iefix') format('eot'), 
 url('font.woff') format('woff'), 
 url('font.ttf') format('truetype'), 
 url('font') format('svg'); }

and

font: SIZE "NAME", FALLBACK, GENERIC FAMILY;


However, I have received a caution that this method may not be the most optimal as it deviates from the "Bulletproof syntax", which was eventually declared outdated due to an issue in IE <9 and was revised three years ago by Fontspring.

Is the latter approach still considered flawless or has it also become outdated?

CSS-Tricks recently suggested that utilizing

@font-face {
  font-family: 'MyWebFont';
  src: url('myfont.woff') format('woff'), /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
       url('myfont.ttf') format('truetype'); /* Chrome 4+, Firefox 3.5, Opera 10+, Safari 3—5 */
}

should suffice, although without addressing compatibility with IE <9.

What is deemed the best practice and is there truly a bulletproof solution?

Answer №1

From my understanding, after reading extensively and gaining knowledge, it is important to take into account the following:

For example:

@font-face{ 
    font-family: 'MyWebFont';
    src: url('WebFont.eot');
    src: url('WebFont.eot?iefix') format('eot'),
         url('WebFont.woff') format('woff'),
         url('WebFont.ttf') format('truetype'),
         url('WebFont.svg#webfont') format('svg');
}

Points to consider:

  1. Always use relative (same domain) font URLs
  2. Include src: url('WebFont.eot'); at first even if it is there in the second src
  3. The first definition in the second src should be EOT definition, with a fix for the iefix hashtag
  4. Ensure to include .eot, .woff, .ttf, and .svg respectively in your CSS definition.
  5. Expect that it may not work on older devices like <=iPhone 4s, <=Galaxy S III, and others.

You can always visit , and download the webfont kit for any font there (while respecting their licenses) to see how CSS is included within.

An informative tutorial can be found here: INSTALLING WEB FONTS, START TO FINISH!

Answer №2

Today, I came across a fascinating comment on this website:

Interesting observation: @font-face was experiencing rendering issues in IE7 on windows vista but not in IE7 on windows xp and windows 7. The fix? Switching from single quotes to double quotes.

Who even still uses windows vista and IE7 these days? Shocking!

Apparently, using double quotes can greatly improve the situation.

In addition, incorporating more fonts can enhance the compatibility. I implemented this approach in a project, ensuring support for a wide range of browsers including old versions like IE 5, IE 7-11, Chrome, Firefox, Opera, as well as various desktop and mobile browsers - both old and modern ones:

@font-face {
  font-family: "Noto Sans";
  src: url("fonts/NotoSans/NotoSans-Regular.eot"); /* IE9 Compat Modes */
  src: url("fonts/NotoSans/NotoSans-Regular.eot?#iefix") format("embedded-opentype"), /* IE6-IE8 */
       url("fonts/NotoSans/NotoSans-Regular.woff2") format("woff2"), /* Super Modern Browsers */
       url("fonts/NotoSans/NotoSans-Regular.woff") format("woff"), /* Pretty Modern Browsers */
       url("fonts/NotoSans/NotoSans-Regular.ttf")  format("truetype"), /* Safari, Android, iOS */
       url("fonts/NotoSans/NotoSans-Regular.svg#NotoSans") format("svg"); /* Legacy iOS */
  font-stretch: normal;
  font-style: normal;
  font-weight: normal;
  font-display: swap;
}

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

utilizing jquery for dynamic color changes

Check out the code snippet below, which involves the bootstrap accordion and showcases certain elements within the title section. <dt><span><i class="fa fa-tachometer" aria-hidden="true"></i>&nbsp;&nbsp;Manage</span>& ...

Data from the session is not displayed when a redirect occurs

On the main page, I include the following code: <?php $required = array('post_question'); // Checking if post field is not empty $error = false; foreach($required as $field) { if (empty($_POST[$field])) { $error = true; } } if(isset($_POST[&a ...

Zooming out on mobile devices on a webpage using Bootstrap 4

After creating a web app and styling it with bootstrap 4, I incorporated a media query to adjust font size and padding on mobile devices. The code snippet used for this purpose is as follows: @media (max-width: 1200px) and (orientation: portrait) { .con ...

Universal CSS styling for scrollbar design across platforms

I'm feeling extremely frustrated right now because I can't seem to create a basic scroll bar with a specific color and thickness that will display properly on various web browsers and smartphones. Are there any resources available to help me fig ...

Methods for concealing the "image not found" icon in Internet Explorer and Chrome through CSS

I have images displayed on a webpage. Currently, when an image is not available, both Chrome and IE display a broken image indicator. I want to hide this indicator and only show the alternative text. Is there a CSS solution to achieve this? ...

Angular 10: A guide to dynamically highlighting navbar elements based on scrolling position

I am currently working on a single-page application using Angular 10. I have a simple page layout and I want to implement a feature that will highlight the navbar based on the scroll position. How can I achieve this functionality in a single-page applicati ...

Concealing categories within an accordion-styled menu

Recently, I put together a list that includes various pieces of information along with an accordion menu. Take a look at the list However, I've encountered a small issue which has left me quite perplexed. When a menu item is clicked - for instance, ...

BS grid malfunctioning in a non-uniform manner

When a division in the advantage grid is clicked, the card body of another division collapses. However, this does not occur in the disadvantage grid. Clicking on one section in the disadvantage grid does not collapse another section as it does in the advan ...

What is the best way to place multiple images on top of one another within a single div, and make them break apart with animation upon hovering?

HTML: <div class="mySlides"> <img src="1.jpg"> <img src="2.jpg"/> <img src="3.jpg"/> <img src="4.jpg"/> <img src="5.jpg"/> </div> CSS: .mySlides { padding-top: 25%; padding-left: 5%; ...

limited growth of float variable

I am utilizing CSS code to create column a and column b, using float in the code to dynamically expand column a as content is added to column b. However, this expansion is not occurring as expected. To see my code, please visit http://jsfiddle.net/hadinetc ...

The presentation of the Google graph with dynamically changing data appears to be displaying inaccurately

I am looking to incorporate a graph displaying sales and purchase data on my webpage. Users should be able to select from categories like Purchase, Sales, or Production. I have separate tables for Purchase (AccPurchase) and Sales (AccSales), with productio ...

Fuzzy text upon scrolling in Internet Explorer version 6

Having a problem with text in Internet Explorer. When the page initially loads, the text appears clean and sharp. However, when I double-click on some white space of the page, the text becomes distorted as shown in the following image: Click here for alt ...

Choosing various files from separate directories within an HTML input type="file" element

Is there a way to select multiple files from various directories using the HTML input type="file" element? I have been searching for resources on how to do this without any luck. Are there any npm packages that can assist with achieving this functionalit ...

Using JQuery to switch out images that do not have an ID or class assigned

Currently, I am using a Google Chrome Extension to apply an external theme to a website. Unfortunately, the logo on the site does not have an ID or class that can be used to call it. I am searching for a solution to replace it with a different image. My ...

Guide to incorporating flash into a form similar to the method used on http://www.mediafire.com

I'm looking to integrate a flash upload feature into my index file, but I'm not sure how to do it. Here is the link to the flash uploader: . I want it to work similar to how uploading works on when you click on UPLOAD. Thank you for any assistan ...

Tips for integrating properties into the class in jQuery

My goal is to assign properties to a class and then inherit them into individual DIV IDs. However, something seems to be off with my code. What could it be? var startItem1X = randomRange(50,100); var startItem1Y = randomRange(50,100); var startItem2X = ra ...

PHP - Utilize get_option to send styling options to style.php

I'm having trouble figuring out how to structure my question, but in my plugin folder I have 2 files: 1 - "index.php" add_action( 'wp_enqueue_scripts', 'register_plugin_styles' ); function my_admin_setting() { include(' ...

Creating a personalized design for MUI TextField spin button

Looking to customize the appearance of the up/down spin buttons in MUI TextField. https://i.sstatic.net/DcG66.png Desiring white arrows and a black surrounding area that's slightly larger, akin to this: https://i.sstatic.net/ZxMJw.png I'm aware ...

Preserving Scroll Location Through Back Button Usage and Ajax Manipulation of the Document Object Model

Currently, I am incorporating a feature where results are loaded in using ajax with an infinite scroll. However, there is an issue when a user clicks on an item in the list and navigates away from the page - upon returning by clicking the back button, they ...

Utilize jQuery to dynamically update the box-shadow property with inset added

I have a situation similar to this: $('.inset').click(function(){ if($('.inset').is(':checked')){ $('.box-shadow').css('boxShadow','inset'); }else{ $('.box-shadow&ap ...