Web API CSS Font Loading Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Web API CSS Font Loading is used to add CSS styles on web pages. It handles the dynamic change which occurs on the web page. We can create a @font-face rule and can add any kind of CSS that we want to load on a page. It also helps in not delaying the styling on the web page. It has many features like FontFace.status which can set the status for loading of FontFace. Web API CSS Font Loading InterfacesFontFace: It represents the font face.FontFaceSet: It checks for the download statuses of loading font faces.FontFaceSetLoadEvent: Invoked whenever a FontFaceSet loads.Web API CSS Font Loading PropertiesDocument.fonts: It returns the FontFaceSet interface of the document.WorkerGlobalScope.fonts: It returns the FontFaceSet interface of the worker.Web API CSS Font Loading EventsfontFaceSet.loading: It fires when the document starts loading the fonts. It is the same as the js property addEventListener.FontFaceSet.loadingdone: It fires when the document has loaded all the fonts. fontFaceSet.loadingerror: It fires when the loading of font has finished and some of them are not able to load properly.Example: In this example, we are loading a font and applying all the events of FontFaceSet. JavaScript const result = document.getElementById("result"); const canvas = document.getElementById("js-canvas"); canvas.width = 650; canvas.height = 75; const ctx = canvas.getContext("2d"); const oxygenFontFace = new FontFace( "FontFamily Kdam Thmor Pro", "url( https://fonts.googleapis.com/css2?family=Vina+Sans&display=swap)", ); document.fonts.add(oxygenFontFace); result.textContent += `font status: ${oxygenFontFace.status}\n`; document.fonts.load("36px FontFamily Oxygen").then( (fonts) => { result.textContent += `Bitter font: ${fonts}\n`; result.textContent += `Bitter font: ${oxygenFontFace.status}\n`; ctx.font = '36px "FontFamily Oxygen"'; ctx.fillText(" Kdam Thmor Pro font loaded", 20, 50); }, (err) => { console.error(err); }, ); document.fonts.addEventListener("loading", (event) => { result.textContent += `loading_event: ${event.fontfaces.length}\n`; }); document.fonts.addEventListener("loadingerror", (event) => { result.textContent += `loadingerror_event: ${event.fontfaces.length}\n`; }); document.fonts.addEventListener("loadingdone", (event) => { result.textContent += `loadingdone_event: ${event.fontfaces.length}\n`; event.fontfaces.forEach((value) => { result.textContent += ` fontface: ${value.family}\n`; }); }); document.fonts.ready.then(function () { result.textContent += `\nFontFaces in document: ${document.fonts.size}.\n`; for (const fontFace of document.fonts.values()) { result.textContent += "FontFace:\n"; for (const property in fontFace) { result.textContent += ` ${property}: ${fontFace[property]}\n`; } } }); HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <canvas id="js-canvas"></canvas> <textarea id="result" rows="30" cols="50"> </textarea> </body> </html> Output: OutputBrowser compatibility:ChromeEdgeFirefoxOperaSafari Comment More infoAdvertise with us Next Article Web API CSS Font Loading S strikeackr Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League Web-API Geeks Premier League 2023 +1 More Similar Reads CSS Web Safe Fonts There are a variety of fonts available in CSS and one can use any type of font in their stylesheets. However, all fonts may not be supported by the browser or operating system of the user. To overcome this problem, a fallback system with web safe fonts are used to ensure maximum compatibility. We as 2 min read How To Add Font In CSS? Adding fonts to a website enhances its design and readability. In CSS, custom fonts can be applied using several techniques that allow web designers to include specific fonts that arenât system defaults.PrerequisitesHTMLCSSThese are the approaches to add a font in CSS: Table of ContentUsing web-safe 2 min read CSS Web Fonts CSS Web fonts allow the use of different fonts, which are not installed on the local system. After choosing the not installed font, just include the font file on the web server and it will be automatically downloaded when needed. Syntax: @font-face { font details}Types of Font Formats: There are man 4 min read How to use web fonts in CSS ? While designing web pages, developers use different fonts based on what the text represents and which fonts suit the best. Each system comes with some pre-installed fonts which are called system fonts. Since these are limited, one may come across the need to use a different font other than the pre-i 3 min read Tailwind CSS Font Weight This class accepts lots of value in tailwind CSS in which all the properties are covered in class form. It is the alternative to the CSS font-weight property. This class is used to set the weight or thickness of the font being used with the HTML Text. The font-weight applied will depend on the font- 2 min read Like