Course contentsShow
← JavaScript
Lesson 2225 of 2,72346. InternationalizationFree lesson

Style: long, short, and narrow

Choosing between full ('3 seconds ago'), abbreviated ('3 sec. ago'), or minimal ('3s ago') formats.

Style: long, short, and narrow

What you'll learn: How to control the verbosity of relative time strings by switching between full, abbreviated, and minimal style formats.


Choosing Your Format Level

When displaying relative times like "3 seconds ago," you have three style options that control how much space the output takes and how formal it feels:

  • long (default): Full words – "3 seconds ago"
  • short: Abbreviated – "3 sec. ago"
  • narrow: Minimal – "3s ago"

Think of it like choosing between a formal letter, a text message, or a Twitter post—each context demands a different level of brevity.

Using the style Option

You pass style when creating your RelativeTimeFormat instance:

const longFormat = new Intl.RelativeTimeFormat('en', { style: 'long' });
const shortFormat = new Intl.RelativeTimeFormat('en', { style: 'short' });
const narrowFormat = new Intl.RelativeTimeFormat('en', { style: 'narrow' });

console.log(longFormat.format(-3, 'second'));  // "3 seconds ago"
console.log(shortFormat.format(-3, 'second')); // "3 sec. ago"
console.log(narrowFormat.format(-3, 'second'));// "3s ago"

console.log(longFormat.format(5, 'day'));      // "in 5 days"
console.log(shortFormat.format(5, 'day'));     // "in 5 days"
console.log(narrowFormat.format(5, 'day'));    // "in 5 days"

When to Use Each Style

  • long: Default UI text, accessibility-first contexts
  • short: Compact dashboards, where space is limited but clarity matters
  • narrow: Tight mobile layouts, charts, badges, or icon labels

Note that narrow doesn't always produce shorter output than short—it depends on the locale and unit. Always test with your target languages.

Key Takeaway: Use the style option ('long', 'short', or 'narrow') to balance readability and space constraints when formatting relative times.