Home > Article > Web Front-end > How Do I Implement .OTF Fonts for Web Browsers and Ensure Cross-Browser Compatibility?
To embed and utilize .OTF fonts in web browsers, you can utilize the @font-face rule. Here's an example:
@font-face { font-family: GraublauWeb; src: url("path/GraublauWeb.otf") format("opentype"); }
Note: OTF fonts are now supported in most major browsers.
Alternatives for Wider Browser Support
For more universal browser compatibility, consider using Web Open Font Format (WOFF) and TrueType Font (TTF) fonts.
Using WOFF and TTF Fonts
@font-face { font-family: GraublauWeb; src: url("path/GraublauWebBold.woff") format("woff"), url("path/GraublauWebBold.ttf") format("truetype"); }
Comprehensive Font Support for Legacy Browsers
To support browsers such as IE6-9, Android 2.3-4.3, and iOS 4-5, add additional font types:
@font-face { font-family: GraublauWeb; src: url("webfont.eot"); /* IE9 Compat Modes */ src: url("webfont.eot?#iefix") format("embedded-opentype"), /* IE6-IE8 */ url("webfont.woff") format("woff"), /* Modern Browsers */ url("webfont.ttf") format("truetype"), /* Safari, Android, iOS */ url("webfont.svg#svgFontName") format("svg"); /* Legacy iOS */ }
Refer to the following resources for more information on browser support for various font formats:
The above is the detailed content of How Do I Implement .OTF Fonts for Web Browsers and Ensure Cross-Browser Compatibility?. For more information, please follow other related articles on the PHP Chinese website!