Skip to main content
Elastic UI
Elastic UI
Getting startedComponentsPatternsContentData visualization
EUI ChangelogGitHubFigma
  • Setup
  • Theming
    • Theme provider
    • Tokens
      • Borders
      • Breakpoints
      • Colors
      • Sizing
      • Typography
        • Font weight
        • Font settings
        • Font scale hook
    • Color mode
    • High contrast mode
    • Utilities
  • Accessibility
  • Testing
  • Utilities
  • EUI
  • Theming
  • Tokens
  • Typography
  • Font scale hook

Font scale hook


The typographic scale is loosely based on the Major Third (1.250) typographic scale.

While these functions and hooks exist to get precise font sizing and associated line-height, we still highly recommend using the

EuiText and EuiTitle components as wrappers of your content instead.

useEuiFontSize() hook

Font sizing is provided through this React hook (or function version) and not the global theme. It returns both the font-size and line-height for the provided scale.

The quick brown fox jumped over the blue moon to catch a snail

โœ„๐˜—
tsx code block:
โœ„๐˜—css` ${useEuiFontSize('l')} `

useEuiFontSize().fontSize

To use precisely only the font-size value, you will still use the same hook (or function) to grab the individual property via the returned object.

The quick brown fox jumped over the blue moon to catch a snail

โœ„๐˜—
tsx code block:
โœ„๐˜—css` font-size: ${useEuiFontSize('xs').fontSize}; `

We strongly recommend using relative (rem or em) units instead of px when possible

Relative font units respect configured browser default font sizes, which some users may set to larger than than the 16px default due to, e.g. visual impairment, monitor size, or personal preference. Read more on accessible text resizing.

Font units

The font sizing function also supports three main units for font size and line height: rem | px | em, with rem being default for all EUI components.

Value unit to show in table
๐˜‚๐˜‚
โœ„๐˜—โœ„๐˜—
Sample
โ†ฆ
Function
โ†ฆ
Font size
โ†ฆ
Line height
โ†ต
Sample
The quick brown fox jumped over the blue moon to catch a snail
โ†ฆ
Function
โœ„๐˜—
js code block:
โœ„๐˜—useEuiFontSize('xxxs')
โ†ฆ
Font size
0.6429rem
โ†ฆ
Line height
1.1429rem
โ†ต
Sample
The quick brown fox jumped over the blue moon to catch a snail
โ†ฆ
Function
โœ„๐˜—
js code block:
โœ„๐˜—useEuiFontSize('xxs')
โ†ฆ
Font size
0.7857rem
โ†ฆ
Line height
1.1429rem
โ†ต
Sample
The quick brown fox jumped over the blue moon to catch a snail
โ†ฆ
Function
โœ„๐˜—
js code block:
โœ„๐˜—useEuiFontSize('xs')
โ†ฆ
Font size
0.8571rem
โ†ฆ
Line height
1.4286rem
โ†ต
Sample
The quick brown fox jumped over the blue moon to catch a snail
โ†ฆ
Function
โœ„๐˜—
js code block:
โœ„๐˜—useEuiFontSize('s')
โ†ฆ
Font size
1.0000rem
โ†ฆ
Line height
1.7143rem
โ†ต
Sample
The quick brown fox jumped over the blue moon to catch a snail
โ†ฆ
Function
โœ„๐˜—
js code block:
โœ„๐˜—useEuiFontSize('m')
โ†ฆ
Font size
1.1429rem
โ†ฆ
Line height
2.0000rem
โ†ต
Sample
The quick brown fox jumped over the blue moon to catch a snail
โ†ฆ
Function
โœ„๐˜—
js code block:
โœ„๐˜—useEuiFontSize('l')
โ†ฆ
Font size
1.4286rem
โ†ฆ
Line height
2.0000rem
โ†ต
Sample
The quick brown fox jumped over the blue moon to catch a snail
โ†ฆ
Function
โœ„๐˜—
js code block:
โœ„๐˜—useEuiFontSize('xl')
โ†ฆ
Font size
1.7143rem
โ†ฆ
Line height
2.2857rem
โ†ต
Sample
The quick brown fox jumped over the blue moon to catch a snail
โ†ฆ
Function
โœ„๐˜—
js code block:
โœ„๐˜—useEuiFontSize('xxl')
โ†ฆ
Font size
2.1429rem
โ†ฆ
Line height
3.1429rem
โ†ต
๐˜‚๐˜‚
Edit this page

Previous
Font settings
Next
Color mode
  • useEuiFontSize() hook
  • useEuiFontSize().fontSize
EUI is dual-licensed under Elastic License 2.0 and Server Side Public License, v 1 | Crafted with โค by Elastic