Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@material/typography
Advanced tools
Typography classes, mixins, and variables for Material Components for the web
@material/typography is a package from the Material Design library that provides a set of typography styles and utilities to help developers implement consistent and visually appealing text styles in their web applications. It follows the Material Design guidelines for typography, ensuring that text elements are readable, accessible, and aesthetically pleasing.
Applying Typography Styles
This feature allows you to apply predefined typography styles to HTML elements. By importing the CSS file and adding the appropriate class to an element, you can style text according to Material Design guidelines.
import '@material/typography/dist/mdc.typography.css';
const myElement = document.createElement('div');
myElement.className = 'mdc-typography--headline1';
myElement.textContent = 'Hello, World!';
document.body.appendChild(myElement);
Customizing Typography
This feature allows you to customize typography styles programmatically. By using the `typography` function, you can define custom styles and apply them to elements.
import { typography } from '@material/typography';
const customTypography = typography({
fontFamily: 'Roboto, sans-serif',
fontSize: '16px',
fontWeight: '400',
lineHeight: '1.5'
});
const myElement = document.createElement('div');
myElement.style.cssText = customTypography;
myElement.textContent = 'Custom Typography';
document.body.appendChild(myElement);
The 'typography' package is a powerful toolkit for building beautiful websites with consistent typography. It provides a wide range of customization options and integrates well with various CSS-in-JS libraries. Compared to @material/typography, it offers more flexibility and customization options but does not strictly follow Material Design guidelines.
The 'styled-components' package allows you to write actual CSS code to style your components. It supports theming and dynamic styling, making it a versatile choice for managing typography in React applications. While it is not specifically focused on typography, it provides the tools to create and manage text styles effectively. It offers more flexibility than @material/typography but requires more setup for consistent typography.
The 'emotion' package is a library designed for writing CSS styles with JavaScript. It offers powerful and flexible styling capabilities, including support for theming and dynamic styles. Like styled-components, it is not focused solely on typography but provides the tools to manage text styles effectively. It offers more flexibility and customization compared to @material/typography but requires more effort to adhere to Material Design guidelines.
Material Design's text sizes and styles were developed to balance content density and reading comfort under typical usage conditions.
MDC Typography is a foundational module that applies these styles to MDC Web components. The typographic styles in this module are derived from thirteen styles:
npm install @material/typography
We recommend using Roboto from Google Fonts:
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
</head>
<body class="mdc-typography">
<h1 class="mdc-typography--headline1">Big header</h1>
</body>
@import "@material/typography/mdc-typography";
Some components have a set typographic style. For example, a raised MDC Card uses Body 1, Body 2, and Headline styles.
If you want to set the typographic style of an element, which is not a Material Design component, you can apply the following CSS classes.
CSS Class | Description |
---|---|
mdc-typography | Sets the font to Roboto |
mdc-typography--headline1 | Sets font properties as Headline 1 |
mdc-typography--headline2 | Sets font properties as Headline 2 |
mdc-typography--headline3 | Sets font properties as Headline 3 |
mdc-typography--headline4 | Sets font properties as Headline 4 |
mdc-typography--headline5 | Sets font properties as Headline 5 |
mdc-typography--headline6 | Sets font properties as Headline 6 |
mdc-typography--subtitle1 | Sets font properties as Subtitle 1 |
mdc-typography--subtitle2 | Sets font properties as Subtitle 2 |
mdc-typography--body1 | Sets font properties as Body 1 |
mdc-typography--body2 | Sets font properties as Body 2 |
mdc-typography--caption | Sets font properties as Caption |
mdc-typography--button | Sets font properties as Button |
mdc-typography--overline | Sets font properties as Overline |
Mixin | Description |
---|---|
mdc-typography-base | Sets the font to Roboto |
mdc-typography($style) | Applies one of the typography styles, including setting the font to Roboto |
mdc-typography-overflow-ellipsis | Truncates overflow text to one line with an ellipsis |
mdc-typography-baseline-top($distance) | Sets the baseline height of a text element from top. |
mdc-typography-baseline-bottom($distance) | Sets the distance from text baseline to bottom. This mixin should be combined with mdc-typography-baseline-top when setting baseline distance to following text element. |
A note about
mdc-typography-overflow-ellipsis
,mdc-typography-overflow-ellipsis
should only be used if the element isdisplay: block
ordisplay: inline-block
.
$style
ValuesThese styles can be used as the $style
argument for the mdc-typography
mixin.
headline1
headline2
headline3
headline4
headline5
headline6
subtitle1
subtitle2
body1
body2
caption
button
overline
All styles can be overridden using Sass global variables before the component is imported by setting a global
variable named $mdc-typography-styles-{style}
. The variable should be assigned a map that contains all the properties
you want to override for a particular style.
Example: Overriding the button font-size
and text-transform
properties.
$mdc-typography-styles-button: (
font-size: 16px,
text-transform: none,
);
@import "@material/button/mdc-button";
Example: Overriding the global font-family
property.
$mdc-typography-font-family: "Arial, Helvetica, sans-serif";
...
@import ...
Example: Overriding the font-family
property for headline1
and font-family
and font-size
for headline2
.
$mdc-typography-styles-headline1: (
font-family: unquote("Arial, Helvetica, sans-serif")
);
$mdc-typography-styles-headline2: (
font-family: unquote("Arial, Helvetica, sans-serif"),
font-size: 3.25rem
);
...
@import ...
12.0.0 (2021-07-27)
return
statement into MDCTooltipComponent#isShown
method. (4d95812)mdc-card__ripple
element rather than the mdc-card__primary-action
. (8ace3b8)#close
within #destroy
. (5631828)forceUpdate
option to #setSelectedIndex that forces a UI update of the selected item. (5d06051)transform-origin
for tooltips with caret so that the entrance animation originates from the caret. (1a8d064)tranform-origin
. (25751d2)data-hide-tooltip-from-screenreader="true"
(in addition to using data-tooltip-id
rather than aria-describedby
.PiperOrigin-RevId: 386490861
window.mdc.circularProgress
to window.mdc['circular-progress]
.PiperOrigin-RevId: 384568221
mdc-icon-button__ripple
. See README for details.PiperOrigin-RevId: 372153409
FAQs
Typography classes, mixins, and variables for Material Components for the web
The npm package @material/typography receives a total of 760,346 weekly downloads. As such, @material/typography popularity was classified as popular.
We found that @material/typography demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 15 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.