JavaScript document.fonts Property

You are Here:

JavaScript document.fonts Property

The document.fonts property of the Document interface returns the FontFaceSet interface of the document.

The FontFaceSet interface is useful for loading new fonts, checking the status of previously loaded fonts etc.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p id="point"></p> <script> var x = document.getElementById("point"); x.innerHTML = document.fonts.status; </script> </body> </html>

Syntax

document.fonts

Return Values

ValueExplanation
ObjectReturns the FontFaceSet interface of the document.

Using Callback Function

You can use a callback function to execute after all fontSets of the current document is loaded.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p id="point"></p> <script> var x = document.getElementById("point"); document.fonts.ready.then(function() { //Run after all FontFaceSets are loaded x.innerHTML = "FontFaceSet of this document is ready"; }); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author