HTML5 Doctor » acronym http://html5doctor.com helping you implement HTML5 today Tue, 17 Mar 2015 16:12:06 +0000 en-US hourly 1 http://wordpress.org/?v=3.9.1 The abbr element https://stevefaulkner.github.io/html5doctored/the-abbr-element/ https://stevefaulkner.github.io/html5doctored/the-abbr-element/#comments Tue, 30 Nov 2010 16:00:33 +0000 http://html5doctor.com/?p=2527 The <abbr> element is not new to HTML5, nor has it been redefined. The HTML5 spec has, however, removed the <acronym> element, which was (and is) common in HTML 4 web pages. Simply put, instead of using <acronym>, use <abbr>.

]]>
The <abbr> element is not new to HTML5, nor has it been redefined. The HTML5 spec has, however, removed the <acronym> element, which was (and is) common in HTML 4 web pages. Simply put, instead of using <acronym>, use <abbr>.

What the spec says

The abbr element represents an abbreviation or acronym…

Straightforward enough, right?

How to use it

<abbr> is an inline element, so we can use it like this:

<p><abbr title="HyperText Markup Language">HTML</abbr> is the best thing since sliced web.</p>

Since it’s an inline element itself, <abbr> can be used inside other inline elements, like <strong> or <a>:

<p>The <a href="http://w3.org"><abbr title="World Wide Web Consortium">W3C</abbr></a> should hire the <abbr>HTML</abbr>5 doctors.</p>

Keep in mind that abbreviations aren’t always a series of uppercase letters. You can also use <abbr> to mark up a shortened word. For example:

<h1><abbr title="HyperText Markup Language">HTML</abbr>5 Doctors <abbr title="Incorporated">Inc.</abbr></h1>

The title attribute creates a tooltip for the user when they hover their cursor over the element:

abbr element tooltip example
Tooltip displayed to the user when hovering over an <abbr> element

The dotted border/underline is shown by default in Firefox and Opera, but IE8, Safari, and Chrome need a line of CSS:

<style>
abbr {border-bottom: 1px dotted black;}
</style>

The spec gives an example of how to use <abbr title="..."> if the abbreviation is pluralised. If the plural is inside the <abbr> element, then it should also be included in the title attribute. (This presumably applies to possessives as well.)

<p>What am I supposed to do with all these Beatles <abbr title="compact discs">CDs</abbr> now that I've repurchased them on iTunes?</p>
<p>I've packed in my job to become an astronaut on <abbr title="National Aeronautics and Space Administration's">NASA's</abbr> new space rocket!</p>

Acronyms and abbreviations: what’s the difference?

Although very similar, there is a slight difference between an acronym and an abbreviation. An acronym is a set of letters that forms a new word, such as NATO, while an abbreviation, such as BBC, does not, since you say each letter separately.

So why one over the other?

While there are subtle, pedantic differences between acronyms and abbreviations, the real reason HTML 4 defines two separate elements is simple: browser wars! Over a decade ago, Netscape created the <abbr> element while Microsoft created the <acronym> element. The W3C couldn’t (or wouldn’t) favour one over the other, so both have been in use ever since (until HTML5).

There’s always been a lot of confusion over these two elements and their usage. Witness it in this archive letter from 1997.

We also have browser compatibility issues with the <abbr> element. IE6 and IE7 do not support <abbr>, so many web developers have always used <acronym>. I know I certainly did when I worked for a big public-sector organisation — it seemed like every page had a dozen acronyms!

To get <abbr> working in IE6 and IE7, you need to create the element with JavaScript:

<!--[if lte IE 7]>
<script type="text/javascript">document.createElement('abbr');</script>
<![endif]-->

Conclusion

Thanks to confusion about their definitions and inconsistent browser support, <acronym> was dropped from both XHTML2 (now defunct) and HTML5. It’s been merged with <abbr>, which explicitly states “The abbr element represents an abbreviation or acronym”.

Hopefully you will find using <abbr> relatively straightforward. If you’re ever tempted to use an <acronym>, just use <abbr> instead!

The abbr element originally appeared on HTML5 Doctor on November 30, 2010.

]]>
https://stevefaulkner.github.io/html5doctored/the-abbr-element/feed/ 29