What is @fontsource/roboto?
@fontsource/roboto is an npm package that allows you to self-host the Roboto font in your web projects. It provides a convenient way to include the Roboto font family in your application without relying on external CDNs. This package supports various font weights and styles, making it versatile for different design needs.
What are @fontsource/roboto's main functionalities?
Basic Usage
This code imports the default Roboto font into your project. It includes the regular weight and normal style.
import '@fontsource/roboto';
Specific Font Weight
This code imports the Roboto font with a weight of 500. You can specify different weights by changing the number in the import path.
import '@fontsource/roboto/500.css';
Specific Font Style
This code imports the italic style of the Roboto font. You can combine this with different weights as needed.
import '@fontsource/roboto/italic.css';
Advanced Usage with CSS
This code imports the Roboto font with a weight of 500 and italic style. This is useful for more advanced typography needs.
import '@fontsource/roboto/500-italic.css';
Other packages similar to @fontsource/roboto
typeface-roboto
The typeface-roboto package is another option for self-hosting the Roboto font. It offers similar functionality to @fontsource/roboto but is part of the older 'typeface' package series. It may not be as actively maintained as @fontsource/roboto.
fontsource-open-sans
The fontsource-open-sans package allows you to self-host the Open Sans font, which is another popular sans-serif typeface. It offers similar features to @fontsource/roboto, including support for various weights and styles.
fontsource-lato
The fontsource-lato package provides the Lato font family for self-hosting. Like @fontsource/roboto, it supports multiple weights and styles, making it a versatile choice for web typography.
Fontsource Roboto
The CSS and web font files to easily self-host the “Roboto” font. Please visit the main Fontsource website to view more details on this package.
Quick Installation
Fontsource offers multiple methods to import the CSS, including using a bundler like Vite or using SASS. You can find full documentation here.
npm install @fontsource/roboto
Within your app entry file or site component, import it in.
import "@fontsource/roboto";
import "@fontsource/roboto/400.css";
import "@fontsource/roboto/400-italic.css";
Supported variables:
- Weights:
[100,300,400,500,700,900]
- Styles:
[italic,normal]
- Subsets:
[cyrillic,cyrillic-ext,greek,greek-ext,latin,latin-ext,vietnamese]
Note: italic
may not be supported by all fonts. To learn more about what weights and styles are supported, please visit the Fontsource website.
Finally, you can reference the font name in a CSS stylesheet, CSS Module, or CSS-in-JS.
body {
font-family: "Roboto";
}
Licensing
Always make sure to read the license for each font you use. Most of the fonts in the collection use the SIL Open Font License, v1.1. Some fonts use the Apache 2 license. The Ubuntu fonts use the Ubuntu Font License v1.0.
Copyright 2011 Google Inc. All Rights Reserved.
Apache-2.0
Other Notes
Font version (provided by source): v32
.
If you have any suggestions or ideas to improve the performance of font loading or expand the existing library, feel free to star and contribute to this repository. You can share your suggestions or ideas by creating an issue.