Dynamic Text

Text content that self adjust to avaliable width, no javascript, pure css!

v0.0.1
🍰
🏃
🎓
Intermediate

Dynamic Text

Text content that self adjust to avaliable width, no javascript, pure css!

Example Usage

<DynamicText
  content={{
    stages: [
      { text: "Short text" },
      { text: "Medium length text" },
      { text: "This is a longer text that will be shown when there's more space" }
    ]
  }}
/>

Features

  • Automatically adjusts text content based on available width
  • No JavaScript required for the core functionality
  • Supports multiple text variations for different space constraints
  • Debug mode to visualize the text switching mechanism
  • Responsive design with mobile support
  • Customizable styling and colors
  • Support for various text formats (dates, times, currencies, etc.)
  • International date and time formatting with Intl API

Props

  • content: Object containing the stages array of text variations (Required)
  • enableAutoSortForMonoFont: Whether to automatically sort text by length for monospace fonts (default: false)
  • className: Additional CSS classes to apply (default: '')
  • showDebug: Whether to show the debug overlay (default: false)

Content Structure

The content prop should be an object with a stages array. Each stage is an object with:

type Stage = {
  text: string
  color?: string
}

Examples

Basic Usage

<DynamicText
  content={{
    stages: [
      { text: "Short" },
      { text: "Medium length" },
      { text: "This is a longer text" }
    ]
  }}
/>

With International Date Formatting

const dateStages = [
  { year: 'numeric', month: 'long', day: 'numeric', weekday: 'long', era: 'long' },
  { year: 'numeric', month: 'long', day: 'numeric', weekday: 'long' },
  { year: 'numeric', month: 'long', day: 'numeric', weekday: 'short' },
  { year: 'numeric', month: 'short', day: 'numeric' },
  { month: 'short', day: 'numeric', weekday: 'short' },
  { month: 'short', day: 'numeric' },
  { day: '2-digit' }
].map((format, index) => ({
  text: new Intl.DateTimeFormat('en-GB', format).format(new Date()),
  color: `blue-${700 - index * 100}`
}));

<DynamicText
  content={{
    stages: dateStages
  }}
/>

With Colors

<DynamicText
  content={{
    stages: [
      { text: "Short", color: "red-500" },
      { text: "Medium length", color: "blue-500" },
      { text: "This is a longer text", color: "green-500" }
    ]
  }}
/>

With Debug Mode

<DynamicTextWrapper
  content={{
    stages: [
      { text: "Short" },
      { text: "Medium length" },
      { text: "This is a longer text" }
    ]
  }}
  showDebug={true}
/>

Live Demo

Good day, madam/sir! 🎩✨ Please try resizing me—I am dynamic content that adjusts to available space.
Hi there! 😊 Try resizing me—I am dynamic content that adjusts to available space.
Please try resizing me! 🙌 I am dynamic content that adjusts to available space.
I am dynamic content that adjusts to available space 🌍 Resize me!
I am dynamic and adjust to available space 🚀 Resize me!
I adjust to available space dynamically 🔀 Resize me!
I change depending on available space 🤹 Resize me!
I can adjust to available space 🎯 Resize me!
I adjust to available space 😎 Resize me!
I adjust dynamically 🔄 Resize me!
I adjust to space 📏 Resize me!
I am dynamic! Resize me! ✨
↔️ Resize me!
Resize me!
Resize me
Resize
↔️
Resize
Resize me
Resize me!
↔️ Resize me!
I am dynamic! Resize me! ✨
I adjust to space 📏 Resize me!
I adjust dynamically 🔄 Resize me!
I adjust to available space 😎 Resize me!
I can adjust to available space 🎯 Resize me!
I change depending on available space 🤹 Resize me!
I adjust to available space dynamically 🔀 Resize me!
I am dynamic and adjust to available space 🚀 Resize me!
I am dynamic content that adjusts to available space 🌍 Resize me!
Please try resizing me! 🙌 I am dynamic content that adjusts to available space.
Hi there! 😊 Try resizing me—I am dynamic content that adjusts to available space.
Good day, madam/sir! 🎩✨ Please try resizing me—I am dynamic content that adjusts to available space.

Other Examples

The text wrap wrapper let browser dynamically adjust the content without any javascript!

Date and Time Formats

Re-distribute the width with the handle in the middle to give more space for the date or the time.

Monday, 30 June 2025 Anno Domini
Monday, 30 June 2025
Mon, 30 June 2025
30 Jun 2025
Mon 30 Jun
30 Jun
30
30 Jun
Mon 30 Jun
30 Jun 2025
Mon, 30 June 2025
Monday, 30 June 2025
Monday, 30 June 2025 Anno Domini
6:44:30 in the evening Coordinated Universal Time
6:44:30 in the evening UTC
6:44:30 in the evening UTC
6:44:30 pm
18:44:30
6:44 pm
18:44
6 pm
18:44
6:44 pm
18:44:30
6:44:30 pm
6:44:30 in the evening UTC
6:44:30 in the evening UTC
6:44:30 in the evening Coordinated Universal Time

Country Name Variations

Different ways to refer to the United Kingdom, from shortest to most formal naming conventions.

The United Kingdom of Great Britain and Northern Ireland (UK)
The United Kingdom of Great Britain and Northern Ireland
The United Kingdom of Great Britain and NI (UK)
The United Kingdom of Great Britain and NI
The United Kingdom of GB & NI
United Kingdom of GB and NI
United Kingdom of GB & NI
United Kingdom (UK)
United Kingdom
UK of GB & NI
The UK
UK
🇬🇧
UK
The UK
UK of GB & NI
United Kingdom
United Kingdom (UK)
United Kingdom of GB & NI
United Kingdom of GB and NI
The United Kingdom of GB & NI
The United Kingdom of Great Britain and NI
The United Kingdom of Great Britain and NI (UK)
The United Kingdom of Great Britain and Northern Ireland
The United Kingdom of Great Britain and Northern Ireland (UK)

Currency Formats

Various ways to format currency values, from full text representation to compact notations.

1,234,567.00 British pounds
GBP 1,234,567.00
GBP 1,234,567
£1,234,567
£1.2M
£1M
£1.2M
£1,234,567
GBP 1,234,567
GBP 1,234,567.00
1,234,567.00 British pounds