Skip to content
Tutorials Center
My learning

Topics

Lesson 15 of 122 Β· Text Content

Times, Data Values and Ruby Text

Give dates, times and numbers a machine-readable form with time and data, control line breaks in long words with wbr, and annotate East Asian text with ruby.

People and computers read text differently. You can write "next Tuesday evening", "half past six" or "Oct 13" and every human understands. A browser extension that adds events to a calendar, a search engine building a results snippet or your own JavaScript cannot β€” at least not reliably. HTML lets you keep the friendly text for people and attach a precise, machine-readable value for software.

This lesson covers four small elements that each solve one specific problem: <time> for dates and times, <data> for other values, <wbr> for line-break hints in long words, and <ruby> for pronunciation guides above East Asian characters.

Dates and times: <time>

The <time> element wraps a date, a time or a duration. Its datetime attribute holds the precise value in a standard format, while the content can be written however you like:

HTML
<p>The workshop starts <time datetime="2026-11-07T18:30">Saturday at 6:30 p.m.</time></p>

Readers see "Saturday at 6:30 p.m."; software sees 2026-11-07T18:30. If the visible text is already in a valid format, you can leave out the attribute:

HTML
<p>Last updated: <time>2026-10-13</time></p>

<time> does not change how text looks, and the browser does not reformat it for you. Its value is in the meaning it adds β€” and in what you can build on top of it with JavaScript.

Valid datetime formats

The formats come from the ISO 8601 standard, with a few simplifications. Here are the ones you will use:

What Format Example
Year YYYY 2026
Month YYYY-MM 2026-10
Date YYYY-MM-DD 2026-10-13
Date without year MM-DD 12-31
Week YYYY-Www 2026-W42
Time HH:MM, optionally with seconds 18:30, 18:30:05, 18:30:05.250
Local date and time date + T + time 2026-10-13T18:30
Global date and time local + time zone 2026-10-13T14:30Z, 2026-10-13T18:30+04:00
Time zone offset alone Z or Β±HH:MM +04:00
Duration P + days, T + hours, minutes, seconds PT1H45M, P3D, P1DT12H

A few details:

  • Hours use the 24-hour clock, and numbers need their leading zeros: 09:05, not 9:5.
  • Z means UTC. An offset like +04:00 means "four hours ahead of UTC". Without either, the time is a local time with no specific time zone.
  • You may use a space instead of the T between the date and time.
  • Durations can also be written in a friendlier form such as 1h 45m. Durations cannot use months or years, because their length varies.

Use a time zone for real moments. An online event happens at one instant worldwide, so write it as a global date and time (with Z or an offset). A shop's opening hours, on the other hand, are local times and need no zone.

Putting <time> to work

Because the value is machine-readable, JavaScript can turn it into something better for each visitor β€” for example, an event time converted into the reader's own time zone, or a "3 days ago" label for a blog post:

Formatting time elements for the reader

The script reads each element's dateTime property (the datetime attribute) and leaves the original text in place as a fallback for anyone without JavaScript. The same <time> element is also what you would use for the datetime of edits in Formatting Text and for publish dates in an article.

Other machine-readable values: <data>

For values that are not dates or times, use <data>. Its required value attribute holds the machine-readable version, and the content is the human-readable one:

HTML
<ul>
  <li><data value="TL-4471">Trail Lantern</data></li>
  <li><data value="TL-4472">Trail Lantern, rechargeable</data></li>
</ul>

Typical uses are product codes, IDs from a database and numbers whose display format differs from their raw value β€” "1.2k", "twelve" or "1,520" in English versus "1.520" in German. A script can then sort, filter or calculate using the clean values instead of parsing the text:

Sorting by data values

Notice that "just under 10k" would be impossible to sort from the text alone, but its value makes it easy. For dates and times, always prefer <time>; for structured data aimed at search engines, there are richer tools, covered in Structured Data.

Line-break opportunities: <wbr>

Browsers only break lines at spaces and a few punctuation marks. A very long "word" with no spaces β€” a URL, a file path, a long identifier β€” can overflow its box, especially on a phone.

The void element <wbr> (word break opportunity) marks a spot where the browser may break the line if it needs to. Unlike the soft hyphen &shy; from HTML Entities, it adds no hyphen β€” which is exactly right for URLs and code, where an extra hyphen would change the meaning.

wbr in a narrow box

The first box overflows; the second breaks neatly at a slash. If the line is wide enough, <wbr> does nothing at all, and copying the text never includes an extra character. For long text you do not control, the CSS property overflow-wrap: anywhere is an alternative that lets the browser break anywhere.

Pronunciation guides: <ruby>

In Japanese and Chinese texts, small annotations above characters often show how to pronounce them β€” helpful for children, language learners and rare names. These annotations are called ruby, and HTML supports them directly:

  • <ruby> wraps the base text and its annotations.
  • <rt> (ruby text) holds the annotation for the text just before it.
  • <rp> (ruby parenthesis) holds fallback parentheses, shown only by browsers that cannot display ruby. Every current browser supports ruby, so <rp> is mostly a safety net β€” for example for text copied out of the page or shown in very simple readers.
Ruby annotations

The first example annotates each character separately, because each one has its own reading. The second annotates the whole word at once, because "γ‚γ—γŸ" is the reading of the two characters together. The third shows Chinese pinyin placed under the characters with the CSS property ruby-position: under.

Always set the right lang attribute on ruby text: it helps browsers pick suitable fonts and helps screen readers pronounce the text.

Old markup alert: you may see <rb> and <rtc> in older tutorials. They are obsolete in the current HTML standard β€” a <ruby> with <rt> (and optional <rp>) is all you need.

Check your understanding

Quick check Β· 5 questions

of 5 answered You scored / 5 Β· perfect!

  1. 1. Which markup gives an online event a precise moment that works for every time zone?

    The Z makes it a global date and time in UTC. Without a zone it is only a local time, and the third format is not valid at all.
  2. 2. Which is a valid duration for one hour and forty-five minutes?

    Durations start with P, and hours, minutes and seconds must follow a T. P1H45M is missing the T, so it is not valid, and 1:45 is not a duration format.
  3. 3. A product list shows names, and you want scripts to read each product's ID. Which element fits?

    <data> pairs human-readable content with a machine-readable value. <time> is only for dates, times and durations.
  4. 4. What is the difference between <wbr> and &shy;?

    Both only break when needed, but &shy; adds a visible hyphen. <wbr> is better for URLs and code.
  5. 5. In <ruby>ζΌ’<rt>かん</rt></ruby>, what does the <rt> element contain?

    <rt> holds the ruby text, the small annotation. <rp> holds fallback parentheses.

Summary

  • <time> pairs human-friendly text with a machine-readable datetime value: dates, times, time zones, weeks and durations.
  • Use Z or an offset like +04:00 for real moments; local times need no zone.
  • <data value="…"> does the same for other values such as product codes and raw numbers.
  • <wbr> marks optional line-break points in long words and URLs without adding a hyphen.
  • <ruby>, <rt> and <rp> add pronunciation guides to East Asian text; set lang, and do not use the obsolete <rb> and <rtc>.

Next: Links in Depth β€” the start of the Links and Navigation section.