Course contentsShow
← JavaScript
Lesson 1658 of 2,72335. Standard Library and Built-insFree lesson

Style Options: Long, Short, and Narrow

Choose between 'long' ('in 3 months'), 'short' ('in 3 mo.'), and 'narrow' ('in 3mo') formatting styles.

Style Options: Long, Short, and Narrow

You'll learn how to control the verbosity of relative time formatting by choosing between three different style options.

What Are Style Options?

When formatting relative time with Intl.RelativeTimeFormat, you can choose how verbose or compact you want the output to be. The style option accepts three values:

  • 'long' — Full words (e.g., "in 3 months")
  • 'short' — Abbreviated form (e.g., "in 3 mo.")
  • 'narrow' — Most compact (e.g., "in 3mo")

Think of it like choosing between formal writing, casual shorthand, or tight space constraints on a mobile UI.

How to Use Style Options

Pass the style option when creating your formatter:

const longFormat = new Intl.RelativeTimeFormat('en', { style: 'long' });
console.log(longFormat.format(3, 'month')); // "in 3 months"

const shortFormat = new Intl.RelativeTimeFormat('en', { style: 'short' });
console.log(shortFormat.format(3, 'month')); // "in 3 mo."

const narrowFormat = new Intl.RelativeTimeFormat('en', { style: 'narrow' });
console.log(narrowFormat.format(3, 'month')); // "in 3mo"

When to Use Each Style

  • Long: Default setting, best for readable prose and accessibility
  • Short: Good for UI labels where space is limited but readability matters
  • Narrow: Ideal for compact dashboards, charts, or mobile interfaces where every character counts

Note that 'narrow' output may be ambiguous in some languages (e.g., "m" could mean minutes or months), so use it only when context is clear.

Key Takeaway: Use the style option to control formatting verbosity—'long' for full words, 'short' for abbreviations, and 'narrow' for maximum compactness.