HTML abbr Tag: How Abbreviations Work with Examples

html abbr tag

The abbr tag refers to an abbreviation in HTML. It helps you save space and improve accessibility. The screen readers can say the full meaning.

Understand the <abbr> Tag in HTML

The <abbr> tag marks a short form of a longer phrase. Browsers show a tooltip when users hover over it.

Here is the tag:

<abbr title="Full Phrase">Short</abbr>

The element holds the short form. The “title” attribute stores the full phrase. The browser reads the short form. On hover, it shows the title value.

The title attribute explains the meaning. It gives more context. It also supports screen readers. This helps users understand the short form.

Here is an example:

<abbr title="Hypertext Markup Language">HTML</abbr>

This shows “HTML” with a tooltip. The tooltip displays the full phrase.

Use it for short forms of technical terms. Use it for names of systems or standards. Do not use it for every word. Use it only when the full phrase adds clarity.

How to Style the <abbr> Tag in HTML

You can style it like any other HTML tag. Use CSS rules to change how it looks. You can underline it andchange the color. You can add a dotted border.

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

This adds a dotted line under the abbreviation. The mouse shows a help icon.

<style>
  abbr:hover {
    color: red;
  }
</style>

This changes the text color when the user hovers over the abbreviation.

In the first style rule, the abbreviation gets a visual cue. It looks different from normal text. In the second, the hover style gives feedback to the user.

Browser Support for <abbr>

All modern browsers support the tag. It works in both desktop and mobile versions. Older browsers also support it.

  • Chrome: 1 and above
  • Firefox: 1 and above
  • Safari: 1 and above
  • Edge: 12 and above
  • Opera: 7 and above
  • Internet Explorer: 6 and above

Examples of the <abbr> Tag in HTML

Abbreviation with Tooltip:

<abbr title="World Health Organization">WHO</abbr>

This shows the short form “WHO”. The user hovers to see “World Health Organization”.

Styled Abbreviation:

<style>
  abbr {
    text-decoration: underline dotted;
    color: blue;
  }
</style>
<abbr title="Central Processing Unit">CPU</abbr>

This uses underline and color to highlight the abbreviation. The title gives the full meaning.

Abbreviation with JavaScript Interaction:

<abbr id="term" title="Application Programming Interface">API</abbr>
<script>
  document.getElementById("term").addEventListener("click", function() {
    alert(this.title);
  });
</script>

This adds a click event to the abbreviation. The script shows the full form in an alert.

Abbreviation in a Table:

<table>
  <tr><th>Term</th><th>Meaning</th></tr>
  <tr><td><abbr title="Cascading Style Sheets">CSS</abbr></td><td>Design rules for HTML</td></tr>
</table>

This places the abbreviation inside a table. The user hovers to see the full phrase.

Wrapping Up

In this article, you learned what the tag does and how it works in practice. You also saw how to style it and check browser support. Here is a quick recap:

  • The tag marks abbreviations.
  • The title attribute holds the full form.
  • Browsers show the full form as a tooltip.
  • You can style it with CSS.
  • It works in all major browsers.

FAQs

What does do in HTML?

The <abbr> element shows a short form. The browser shows the full form in a tooltip using the title attribute.

How do I use with the title attribute?

Wrap the short form in <abbr>. Add a title attribute with the full meaning.
<abbr title="United Nations Educational, Scientific and Cultural Organization">UNESCO</abbr>

Does work on all browsers?

Yes. All browsers since early versions support it.

Can I style the tag with CSS?

Yes. Use CSS rules to change the color, border, or hover behavior.
abbr {
  color: green;
  border-bottom: 1px dashed gray;
}

Similar Reads

HTML dialog Tag: How to Create Dialog Boxes

The <dialog> tag is used to build modal popups in HTML. It shows alerts and messages without third-party scripts. Understand…

HTML a Tag: How to Add Links to Web Page with Examples

The HTML a tag allows you to create links that move users from one page or resource to another. Understand…

HTML Section Tag: How It Works with Examples

The HTML section tag groups parts of a web page that share one theme. It gives clear meaning to content.…

HTML iframe Tag: How to Embed Content with Examples

The iframe tag embeds another HTML page inside the current page. It loads content from a separate source. Understand the…

HTML kbd Tag: How to Show Keyboard Input with examples

The HTML<kbd> tag shows the keys that a user must press. This helps you to give instructions for commands or…

HTML dir Attribute: How to Set Text Direction

The dir attribute tells the browser which way text should go in HTML. You use it when a page or…

HTML Table Tag: How to Build Tables with Its Elements

You use the HTML <table> tag to display structured data in rows and columns, using table elements such as <tr>…

HTML Mark Tag: How to Highlight Text

The mark tag highlights text in HTML and shows that the text has relevance in the content. It adds a…

HTML var Tag: Variables in Text

The HTML <var> tag marks a word or phrase as a variable in a document. Web authors use it to…

HTML time Tag: Representing Dates and Times

The HTML time Tag marks time values in a document. Use it to show dates or times that machines and…

Previous Article

HTML b Tag: How to Bold Text

Next Article

HTML address Tag: Contact Information

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *


Subscribe to Get Updates

Get the latest updates on Coding, Database, and Algorithms straight to your inbox.
No spam. Unsubscribe anytime.