Open In App

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 many types of font formats which are listed below:

Font Descriptors:

Descriptors can be defined inside the @font-face rule. We shall now explain the different types of font descriptors.

CSS Web Fonts Examples

Example 1: This example illustrates the use of web-fonts.

<!DOCTYPE html> 
<html> 
    
<head> 
    <style> 
        @font-face{ 
            font-family: monospace; 
            src:url(sansation_light.woff); 
        } 
        
        /* Sets font family to monospace */ 
        * { 
        font-family: monospace; 
        } 
    </style> 
</head> 

<body> 
    <div> 
        <h1>GeeksForGeeks</h1> 
        
        <p>A computer science portal for geeks.</p> 
    </div> 
    
    <h1>Great Geek's font face example.</h1> 
</body> 

</html>                     

Output:

CSS Web Fonts Examples

Example 2: This example illustrates the use of web-fonts.

<!DOCTYPE html> 
<html> 
    
<head> 
    <style> 
        @font-face{ 
                
            /* Set font family to monospace */ 
            font-family:monospace; 
            src:url(sansation_light.woff); 
        } 
        
        * { 
            font-family:monospace; 
            
            /** font style to italic */ 
            font-style:italic; 
            font-weight:bold; 
        } 
    </style> 
</head> 

<body> 
    <div> 
        <h1>GeeksForGeeks</h1> 
        <p>A computer science portal for geeks.</p> 
    </div> 
    
    <h1>Great Geek's font face example.</h1> 
</body> 

</html>                     

Output:

CSS Web Fonts Example Output
Article Tags :