The Wayback Machine - https://web.archive.org/web/20240914141105/https://www.geeksforgeeks.org/how-to-use-otf-fonts-on-web-browsers/
Open In App

How to use .otf fonts on web browsers ?

Last Updated : 22 Mar, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

OpenType Font (.otf) is a font format that was developed by Microsoft and Adobe. It is an extended version of the TrueType font format and it supports advanced typographic features like ligatures, small caps, and many more.

It is more widely preferred over another font format because it is over better cross-platform compactness and includes a wider range of typographic features. OTF can be created using various software tools, including font editors like FontForge. It is widely used in graphic design web design and desktop publishing applications.   

Syntax:

@font-face {
    font-family: 'MyFont';
    src: url('path/to/MyFont.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
}

 

Approach:

  • First, declare the .otf font using @font-face and specify its name and file path.
  • The font-family property is used to illustrate that the font is to be used for all the text on the page.
  • The file path mentioned in the @font-face rule will need to be adjusted to match the actual file address on the server.

Example 1: This example describes the basic usage of the .otf fonts on web browsers.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <meta charset="UTF-8">
    <title>My Web Page</title>
    <link rel="stylesheet" href="style.css">
</head>
  
<body>
    <header>
        <h1 class="name">GeeksforGeeks</h1>
    </header>
    <main>
        <h2>About Us</h2>
        <p>We are GfG</p>
        <h2>Our Services</h2>
        <ul>
            <li>Web design</li>
            <li>Web development</li>
            <li>DSA</li>
        </ul>
    </main>
</body>
  
</html>


CSS




@font-face {
    font-family: 'MyFont';
    src:
        url('path/to/CarandaPersonalUse-qLOq.ttf') 
        format('opentype');
    font-weight: normal;
    font-style: normal;
}
  
body {
    font-family: 'CarandaPersonalUse-qLOq.ttf', sans-serif;
    text-align: center;
}
  
header {
    background-color: #333;
    text-align: center;
    color: green;
    padding: 20px;
    font-size: large;
}
  
main {
    padding: 20px;
}


Output:

 

Example 2: This is another example that describes the use of the .otf fonts on web browsers.

HTML




<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" 
          content="IE=edge">
    <meta name="viewport" 
          content="width=device-width, 
                         initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
</head>
  
<body>
    <header>GeeksforGeeks</header>
    <main>
        <p>
            This is a paragraph written in otf format .
        </p>
    </main>
</body>
  
</html>


CSS




@font-face {
    font-family: 'MyFont';
    src: url('path/to/MyFont.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
 }
    
 body {
    font-family: 'MyFont', sans-serif;
    text-align: center;
}
  
header {
    background-color: #333;
    text-align: center;
    color: green;
    padding: 20px;
    font-size: large;
}
    
main {
    padding: 20px;
}


Output:

 

Note: In order to see the different font formats in the output, you need to download it on your local machine, & then locate & set the path for the downloaded font file in the URL.



Similar Reads

What are web safe fonts and fallback fonts in CSS ?
Web Safe Fonts: Web Safe fonts are those fonts that are usually installed across all of the browsers and operating systems. Some examples of fonts that can be used as Web Safe Fonts are as follows. VerdanaGeorgiaArialSerifSans-SerifTimes New RomanCandaraCalibriOptimaLucida Bright Fallback Fonts: No font is 100% web-safe fonts. There is always a pos
2 min read
Using Fonts in Next JS(Google Fonts, Tailwind CSS)
In Next.js, integrating fonts such as Google Fonts and using Tailwind CSS for styling can greatly enhance the design and user experience of your application. They play an important role in defining the looks and readability of a website or application. Integrating custom fonts on the platform make our text look more stylish and appealing to custome
2 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-installed one. In this article, we will discuss how
3 min read
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 assign several font names to the "font-family" prope
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 many types of font formats which are listed below: Tr
4 min read
How to use google fonts in Tailwind CSS ?
In this article, we will see how to use Google fonts on our webpage and gives it a unique look. Google Fonts is a free, open-source library of over 1000 font families that can be used on websites. The fonts are served by Google servers and can be easily integrated into a website by including a link to the Google Fonts API in the HTML file. It only
4 min read
How to use Google Fonts in CSS ?
Google Fonts provides a library of hundreds of free and open-source fonts that can be used in web design. we will explore how to use Google Fonts in CSS. The library contains a vast collection of fonts that can be used in web design, mobile apps, etc. In this article, we'll see how to use Google fonts in CSS. Google Fonts provide us with API, we ha
3 min read
How to use Google Fonts in React?
Google Fonts is a widely used popular library of open-source web fonts that provides a vast collection of typefaces to enhance the visual appeal of web applications. Google Fonts provides a vast collection of free and high-quality fonts that can easily be integrated into your React applications. In this React Google Fonts article, we will cover dif
5 min read
How to align checkboxes and their labels on cross-browsers using CSS ?
For aligning the checkboxes or radio buttons with their labels can be achieved in many ways. Some of the simplest methods to achieve this are described below with proper code and output in different browsers. Now styling can be done in various ways to align the checkboxes and their labels. For this article, we are using internal stylesheet which is
2 min read
How to Create Browsers Window using HTML and CSS ?
The browser window is a tool to view the pages from the internet. It is used to search the content on the internet and get relevant information from the internet. Creating Structure: In this section, we will create a basic site structure and also attach the CDN link of the Font-Awesome for the icons which will be used as a menu icon. CDN links for
3 min read
How to Configure Mouse Wheel Speed Across Browsers using JavaScript ?
The mouse wheel's scrolling speed varies with the choice of the web browser, even the DOM events and methods to change the scrolling speed are not the same. To provide zoom and animation on a web page, it is generally required to configure mouse speed. The speed of the wheel can be controlled by normalizing the distance the wheel has traveled. Ther
3 min read
How to change text selection color in the browsers using CSS ?
Most of the browsers by default highlight the selected text in a blue background. This can be changed by using the ::selection pseudo selector in CSS. The ::selectionselector is used for setting the CSS property to the part of the document that is selected by the user (such as clicking and dragging the mouse across text). Only some CSS properties a
1 min read
Maximum length of a URL in different browsers
In this article, we will discuss the overview of URL and Browser with examples of both of them. And finally will conclude with the Maximum length of a URL in different browsers. Let's discuss it one by one. URL Overview :URL stands for Uniform Resource Locator. URLs were defined in RFC 1738 in 1994. In this, it gives the specific location over the
3 min read
How can JavaScript codes be hidden from old browsers that do not support JavaScript ?
Nowadays all modern browsers support JavaScript, however, older browsers did not support JavaScript. In this article, we will learn how we can hide JavaScript code from running in older browsers. Approach: After opening the &lt;script&gt; tag, we will use a one-line HTML style comment without any closing character ( &lt;!-- ). We will then write th
2 min read
Why do browsers match CSS selectors from right to left ?
Cascading Style Sheets fondly referred to as CSS, is a simply designed language intended to simplify the process of making web pages presentable. CSS allows you to apply styles to web pages. More importantly, CSS enables you to do this independently of the HTML that makes up each web page. It describes how a webpage should look: it prescribes color
3 min read
Next.js Supported Browsers and Features
NextJs is a popular JavaScript library that helps developers create server-side rendered React applications. It’s one of the most popular frameworks for creating React applications, and it’s used by some of the biggest companies in the world, such as Airbnb, Netflix, and Reddit. In this blog post, we will explore what NextJs is, what browsers it su
4 min read
Why can't browsers read JSX ?
React, a JavaScript library for web applications utilizes JSX—a syntax extension allowing JavaScript objects within HTML elements, enhancing code clarity. JSX isn't directly supported by browsers, requiring conversion by tools like Babel to transform JSX into valid JavaScript. This transpilation ensures browsers can interpret and execute the JSX-em
2 min read
How to Access Localhost on Mobile Browsers?
Accessing localhost on a mobile browser is a useful skill for developers who need to test and debug their web applications on different devices. Whether you're developing a responsive website or a mobile app, being able to view localhost from your smartphone can significantly streamline your testing process. In this guide, we will show you how to a
3 min read
How to style scrollbar thumb for the webkit browsers and what are components of scrollbar ?
We use the scrollbar daily while using the web. Scrollbars are tools with the help of which we can scroll the content of our webpage. The problem with the default scrollbars is that they always appear in the same dull gray color. But then how to make them look good? In this article, we will learn how to make a scrollbar look good. What are the comp
2 min read
How to detect page zoom level in all modern browsers using JavaScript ?
In this article, we will discuss how the current amount of Zoom can be found on a webpage. These are the following methods: Table of Content Using outerWidth and innerWidth PropertiesUsing clientWidth and clientHeight PropertiesUsing the window.devicePixelRatio PropertyMethod 1: Using outerWidth and innerWidth PropertiesIt is easier to detect the z
3 min read
What are different video formats supported by browsers in HTML ?
In this article, we will see what are the different video formats that are supported by the browser, along with understanding their implementation. Browsers support text in different colors with different fonts and along with supporting various media which includes images, music, videos, animations, etc. A video exists in different formats such as
3 min read
Difference Between Web 1.0, Web 2.0, and Web 3.0
Web 1.0 was all about fetching, and reading information. Web 2.0 is all about reading, writing, creating, and interacting with the end user. It was famously called the participative social web. Web 3.0 is the third generation of the World Wide Web, and is a vision of a decentralized web which is currently a work in progress. It is all about reading
8 min read
W3.CSS Text And Fonts
W3.CSS is one of the most popular, open-source front-end framework which helps us in developing responsive, mobile-first websites, and web applications. As a part of its offering, it provides us with a collection of classes, called the Text Utility classes, which controls various text properties, such as, text alignment, text size, text opacity. Te
5 min read
How to Add Custom Fonts in VueJS ?
Vue.js is a JavaScript framework used in building powerful and beautiful user interfaces. The key feature of Vue.js is its component-based architecture that allows the developers to create reusable and modular components. Custom fonts can bring uniqueness and visual appeal to your Vue.js applications, enhancing the overall user experience. In this
2 min read
How to add Custom Fonts in a Tailwind CSS Project ?
Adding custom fonts to a Tailwind CSS project involves configuring the fontFamily property within the theme section of the tailwind.config.js file. You can then apply the custom font to specific elements using Tailwind utility classes. Syntax// tailwind.config.jsmodule.exports = { theme: { extend: { fontFamily: { custom: ['CustomFont', 'sans-serif'
1 min read
How to Add Custom Fonts to a WordPress Theme?
Adding custom fonts to your WordPress theme can significantly enhance the look and feel of your website. Custom fonts help establish your brand identity and improve readability. This step-by-step guide will show you how to add custom fonts to your WordPress theme using various methods. Steps to add Custom Fonts to a WordPress ThemeStep 1: Install a
1 min read
How to Import Google Fonts in HTML?
Choosing the right font for your webpage is a very important aspect of any design. Using a web font service enables you to use a wide variety of fonts fit for presenting the data on your webpage. Google Fonts is a free web font service that hosts a huge variety of fonts to choose from. We can use these fonts in our webpages. To use a custom font, w
2 min read
How to Add Custom Local Fonts in Next.js ?
Adding custom fonts in Next.js project enhances the typography. They can be integrated by importing font files into a project, defining @font-face rules in CSS, and applying them across components for consistent styling and branding. In this article, we will learn to add Custom Fonts to our Next.js project. ApproachIntegrate custom local fonts in N
2 min read
Fonts in Next JS
The font module in next.js allows to add any external or local fonts. Fonts are used to style the components and to increase the readability of the application. The font is associated with the style, size, width, and typeface i.e. design of the letters. We can customize the font according to our choice by simply adding them to the global CSS file a
6 min read
CSS Fonts
CSS fonts are used to style the text within HTML elements. The font-family property specifies the typeface, while font-size, font-weight, and font-style control the size, thickness, and style of the text. Combining these properties enhances the typography and readability of web content. Example: In this example, we will use a few CSS Font propertie
6 min read
Article Tags :