11

I markup a table which contains values with units of measurement. I thought about how to mark up the document for the best accessibility. Is it important to respect variable values and constant names for values?

I did not find any <value>, <unit> element or an appropriate attribute for this case.

My three markup approachs

<table>
   <td>Brain weight</td>
   <td>3.8<em>g</em></td>
</table>

———————————— o r ————————————

<table>
   <td>Brain weight</td>
   <td><em>3.8</em>g</td>
</table>

———————————— o r ————————————

<table>
   <td>Brain weight</td>
   <td>3.8<abbr title="Grams">g</abbr></td>
</table>
FelipeAls
  • 21,711
  • 8
  • 54
  • 74
Tomkay
  • 5,120
  • 21
  • 60
  • 92
  • When writing in English, you should use the period as the decimal separator. – Nova Mar 22 '13 at 09:22
  • Thank you Erik. Changed to periods as seperator. – Tomkay Mar 22 '13 at 09:26
  • This might be interresting, using XSLT/XML tag inside your table to define custom tags. I wonder if it complies with the W3C html validation tool tho; http://stackoverflow.com/questions/3387127/set-html5-doctype-with-xslt and http://www.w3.org/TR/xslt. I've tested custom tags in HTML5 doctype and it seems (in Safari on OS X) they just turn into span-type tags. –  Mar 22 '13 at 09:28
  • 2
    First things first. Use `th` elements for the table headings rather than `td`: `Brain weight`. – steveax Mar 22 '13 at 15:08

4 Answers4

3

I like very much your third approach of using an abbr tag for adding contextual information and improving accessibility. It's a great idea.

However, neither of your markups is fully compliant with the rules of the International System of Units. See http://en.wikipedia.org/wiki/International_System_of_Units

You must separate the value and the unit by one space character.

 <td>3.8&nbsp;<abbr title="Grams">g</abbr></td>
PA.
  • 28,486
  • 9
  • 71
  • 95
3

Using em for the unit/value would be incorrect (typically; of course there are some cases where it might be appropriate, but not in general). The em element "represents stress emphasis of its contents" ("The placement of stress emphasis changes the meaning of the sentence.").

Using the abbr element for the unit would be correct (might be useful for various use cases).

In your examples you've used table with td as childs. This is not valid markup. If you'd only have such name-value pairs, you could use a dl:

<dl>
  <dt>Brain weight</dt>
  <dd>3.8&nbsp;<abbr title="grams">g</abbr></dd>
</dl>

There is a draft for a measure microformat.


In the WHATWG version of HTML ("Living Standard") you can find a data element. For some time it was part of the W3C HTML5 draft, too, but it has been removed.

unor
  • 92,415
  • 26
  • 211
  • 360
2

There is no markup for units of measurements in HTML, or for numbers, so if you need some markup for them (e.g., in order to style them uniformly or to process them with a client-side script), use a span element with a class attribute for numbers or units or both, e.g.

<td><span class=number>3.8</span> <span class=unit>g</span></td>

(Note that by international standards, number and unit shall be separated by a space, which can be a nonbreaking space, &nbsp;, if needed).

Normally, no markup is needed for units. Or, rather, there is no markup we could use for a useful purpose, and writing span markup just for the fun of it makes the HTML code less readable.

In some interpretations, however, symbols of units are abbreviations, so abbr markup could be used. Note that this by default causes a dotted line under (bottom border) in most browsers, a mostly irritating feature; to remove it, set abbr { border: none } in CSS. By essence, symbols of units are conventional notations rather than abbreviations.

Using a title attribute, on span, abbr, or other element, makes some assistive software show the attribute value when requested by the user. It also tends to make it shown in a tooltip in common browsers. It is questionable whether such “hints” are useful rather than just disturbing for commonly known symbols.

Using em would mean emphasis in principle, which is hardly appropriated, and would cause italic to be used in practice. By international standards, symbols of units shall never be italicized. Although you can use CSS to remove italic, it would be odd to use markup that tends to cause it.

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390
  • 2
    > Or, rather, there is no markup we could use for a useful purpose. Disagree. I think HTML urgently needs a way to mark units of measure and their value, so we can finally get automatic conversions. We would no longer need to see units we don't understand, like imperial units. Pages where the imperial units and metric units are specified for completeness would be so much easier to read. The advantages would be many. – Marc Diethelm Nov 06 '13 at 16:11
  • @MarcDiethelm, we don’t need special markup for units in order to carry out conversions; it’s a programming issue. If you mean that browsers would do conversions natively, you would need markup for *quantities*, and the whole idea is very unrealistic. BTW, people can just copy and paste an expression and ask Google to convert it to metric units (or, as the case may be, to ancient units). – Jukka K. Korpela Nov 06 '13 at 16:50
  • I find that disagree on every point you're making except "you would need markup for quantities", which goes without saying. The necessary tag would probably enclose the value and unit, possibly specifying the specifics with attributes. Can you recommend the best place to take a discussion on this subject? The W3C mailing list, maybe? Or I could take it to Mozilla and try to get their support. – Marc Diethelm Nov 11 '13 at 16:19
0
<abbr title="Grams">g</abbr>

Apology for miss-understanding the issue previously...right answer is above before html5 i use a meaningful id/class. No advantage of defining own tags for above problem.

thanks all for correcting me.

Aamir Shahzad
  • 6,683
  • 8
  • 47
  • 70
  • 3
    Defining your own tags will do nothing in regard to accessibility if the document is still viewed/interpreted as HTML5. – CBroe Mar 22 '13 at 10:55
  • 3.8 g ok. got it. But just with class name as unit is there any benefit of that? i thought the man who asked the question want a tag for unit...so i have told him how to add custom tag... – Aamir Shahzad Mar 25 '13 at 04:15
  • @aash1010 The solution to my question should enhance the accesibility. Accesibility uses convention. Creating own elements would not help a screenreader or a search engine bot. – Tomkay Mar 26 '13 at 07:16