Understanding the CSS from-font Value in 4 Demos
The CSS from-font Value Explained in 4 Demos
CSS from-font is a powerful way to add fonts to your website in a way that enables your visitors to have their preferred font style easily. In this article, we'll explain what CSS from-font is and provide four demos of how to use it. By the end of this article, you'll know how to implement the from-font value in your own projects.
What is CSS from-font?
The from-font property is a CSS value that allows you to specify which font to use when displaying text on a web page. It allows you to specify a specific font-family for each individual element on the page, allowing visitors to have their preferred font style displayed. This is especially useful for sites with complex designs that require multiple font styles. The from-font value also enables you to set the same font style across all elements of a website with minimal effort, ensuring a consistent look and feel.
Demo 1 - Setting multiple typefaces with from-font
The following example shows how to set multiple typefaces using the from-font property. In this demo, we are setting two different font families (Arial and Times New Roman) to the body tag and the h1 tag each with its own styling.
<style> body { font-family: from-font(Arial); } h1 { font-family: from-font (Times New Roman); } </style>
Demo 2 - Setting the Default Font with from-font
The following example shows how to set the default font family using the from-font value. In this demo, we are setting the font family for all elements (except those specified by other rules) to Arial.
<style> * { font-family: from-font(Arial); } </style>
Demo 3 - Overriding Specific Fonts with from-font
The following example shows how to override specific fonts using from-font. In this demo, we are setting the font family for all elements except links to Arial, but overriding the font family for all links to Times New Roman.
<style> * { font-family: from-font(Arial); } a { font-family: from-font(Times New Roman); } </style>
Demo 4 - Loading Fonts from an External Source with from-font
The following example shows how to load fonts from an external source using from-font. In this demo, we are loading a font from Google Fonts with the from-font value.
<style> * { font-family: from-font('Roboto', 'https://fonts.googleapis.com/css?family=Roboto'); } </style>
By utilizing the from-font property, you can easily add fonts and allow your visitors to have their preferred font styles displayed. If you follow the examples provided in this article, you'll be able to set multiple typefaces, set the default font, override specific fonts, and load external fonts using from-font.