Skip to content

Are all uses of the title attribute discouraged? #10875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ddbeck opened this issue Dec 19, 2024 · 7 comments
Open

Are all uses of the title attribute discouraged? #10875

ddbeck opened this issue Dec 19, 2024 · 7 comments

Comments

@ddbeck
Copy link

ddbeck commented Dec 19, 2024

What is the issue with the HTML Standard?

The title attribute section contains this note:

Relying on the title attribute is currently discouraged as many user agents do not expose the attribute in an accessible manner as required by this specification (e.g., requiring a pointing device such as a mouse to cause a tooltip to appear, which excludes keyboard-only users and touch-only users, such as anyone with a modern phone or tablet).

(It also appears a few other places, such as the requirements for providing text alternatives section.)

Do the editors wish to discourage authors from all uses of the title attribute?

As someone working on documentation for the web platform, I don't know how to describe the condition of this feature. Unlike other features in this and other web platform specifications, it's unclear if the title attribute is under the umbrella of things that the spec wishes for authors to not use in new web content.

There's an additional layer of uncertainty here, given by "currently." I took this to mean the note was anticipating changes, except it's 12 years old (commit). I couldn't find any open issues discussing the title attribute.

It'd be helpful if the spec could be rather more specific in this note, both with respect to when the note applies and to whom. I don't have an opinion about what the actual position of the editors ought to be, but I'd like to know what it is.

To resolve this, I'd expect the note to say something along the lines of "Authors should not use the title attribute because…. Authors should instead…" or "Authors should not use the title attribute unless…" depending on what y'all think the answer is. Or if it's really serious, to list title amongst the obsolete features.

For background, this came came up while trying to summarize feature information for developers in the web-features project: web-platform-dx/web-features#2461.

This is my first time filing an issue with WHATWG, so please let me know if I've missed anything. And thank you for considering this issue.

@annevk
Copy link
Member

annevk commented Dec 19, 2024

I think the note is accurate? As in, it seems fine to use it if the information is otherwise available or not that important, but you cannot rely on the end user having access to it. The most commonly used device to access the web does generally not expose title attributes on arbitrary elements, for instance.

@valtlai
Copy link

valtlai commented Dec 20, 2024

I think there are some valid use cases for the title attribute:

  • A label for an RSS/Atom/JSON feed, especially if there are several of them:

    <link
      rel="alternate"
      href="/blog.rss"
      type="application/rss+xml"
      title="Blog RSS feed"
    >

    This one also applies to alternative style sheets.

  • An accessible name for an <iframe> element:

    <iframe
      src="demo.html"
      title="Demo: HTML popover"
    >
  • A custom validation message for a form element:

    <input
      pattern="[0-9a-z]{40}"
      title="Use full SHA-1 commit hash"
    >

@captainbrosset
Copy link

What about adding this then:

"Relying on the title attribute to provide additional information about an element via a user-agent tooltip is currently discouraged as many user agents do not expose the attribute in an accessible manner as required by this specification".

This would make the note clearer to me. Reading this, I know when the title attribute is discouraged, and when it isn't.

@annevk
Copy link
Member

annevk commented Jan 16, 2025

I think for the elements where the title attribute has special semantics that is already called out in the section of the relevant element.

@ddbeck
Copy link
Author

ddbeck commented Feb 20, 2025

Thanks for your patience—it took me a while to return to this.

Thanks for the clarifications. The narrow question of 'is title, in general, discouraged?' is answered. I have two follow up questions:

  • Are you willing to consider a revision, along the lines that @captainbrosset suggests above? I'm satisfied with the discussion here, but it'd be nice if I did not have to cite non-spec text to justify the decision to not call out title as generally discouraged, in Is the title attribute discouraged? web-platform-dx/web-features#2461 (and upstream in browser-compat-data).

  • What's meant by "currently"? I'm still unclear on that point. I interpreted it as anticipating changes, but it's still a bit of a mystery to me.

@annevk
Copy link
Member

annevk commented Feb 20, 2025

I think the specification is already pretty clear about why it is not encouraged, in particular due to parenthetical. I think the suggestion would make the parenthetical confusing, but some revision might be okay.

"Currently" just refers to the situation as it is today and that it indeed could change if user agents were to implement something to handle this.

@r12a
Copy link

r12a commented Mar 7, 2025

Btw, this is really a side issue, but note that the W3C discourages use of (any) attributes for natural language text, because it is not possible to label the language or direction of the title attribute differently from the element content. (For instance, see this example that needs a workaround.) It is also not possible to label a part of the title text for language or direction. The situation worsens if there is a plausible reason to want to style or annotate parts of the text (probably not the case for the title element).

Fwiw, XHTML 2.0 would have replaced the title attribute with a sub-element, but that markup language didn't get adoption. It was felt that HTML5's title attribute was too ingrained in the Web to be changed in the early days. I'm not expecting that to change, but did want to mention this additional consideration which needs to be borne in mind when talking about attributes that contain natural language text.

I hope that we bear that in mind as we develop new markup in the future. hth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants