Skip to content

Allow attributes on the <title> element #5198

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
romaricpascal opened this issue Jul 24, 2020 · 5 comments · May be fixed by #15983
Open

Allow attributes on the <title> element #5198

romaricpascal opened this issue Jul 24, 2020 · 5 comments · May be fixed by #15983
Labels
Milestone

Comments

@romaricpascal
Copy link

Is your feature request related to a problem? Please describe.
Looks like the <title> element is [barred from having any attributes] (https://github.com/sveltejs/svelte/blob/master/src/compiler/compile/nodes/Title.ts). According to MDN, it can host any global attribute. It was a bit of a surprise that it had special treatment.

This prevents adding to it an aria-live attribute that would allow its announcement by assistive technology (provided it's unhidden from the accessibility tree, see experiment there: https://romaricpascal.is/posts/title-element-aria-live/).

Describe the solution you'd like
At the moment, it looks like the attribute can be set through an onMount() call:

  onMount(() => {
    document.head.querySelector('title').setAttribute('aria-live', 'assertive');
  });

but it'd be great to just be able to do:

<svelte:head>
  <title aria-live="assertive">{$title}</title>
</svelte:head>

This would also make updating whether the title should be announced lighter, especially if the value comes from a store:

<svelte:head>
  <title aria-live={$live}>{$title}</title>
</svelte:head>

Describe alternatives you've considered
Using onMount provides a workable workaround. There's just a bit of logistics if attributes need to come from a store or multiple attributes need setting (but in my use-case, that would only be aria-live).

How important is this feature to you?
It's not a dealbreaker that it's not there. It just feels less idiomatic to have all that boilerplate around. It was also confusing to have that specific tag not work as a regular tag (maybe it's a matter of documentation, though).

@caroso1222
Copy link
Contributor

I've never seen such a pattern before but, as you point out, it seems to be valid HTML. That change was introduced in this PR but there's no apparent reason as to why. I can open a PR removing that but I'm afraid I'm missing something here.

@umanghome
Copy link
Contributor

It makes sense to remove the validation since the spec allows global attributes. https://html.spec.whatwg.org/#the-title-element

@caroso1222
Copy link
Contributor

I talked about this on Discord and it seems like the maintainers are not willing to remove the validation. The argument being that the article posted by op is an experiment more than good practice. I too consider the validation to be irrelevant given that it should be allowed, according to the spec.

@pngwn pngwn added compiler Changes relating to the compiler feature request temp-stale and removed feature: attributes labels Jun 27, 2021
@stale
Copy link

stale bot commented Dec 24, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale-bot label Dec 24, 2021
@Rich-Harris Rich-Harris added this to the 5.0 milestone Apr 2, 2024
@dummdidumm dummdidumm modified the milestones: 5.0, 5.x May 13, 2024
jschaf added a commit to jschaf/svelte that referenced this issue May 22, 2025
The spec states the title element supports global attributes.
https://html.spec.whatwg.org/#the-title-element

Reverts the title attribute validation introduced in sveltejs#1721.

Fixes sveltejs#5198.
jschaf added a commit to jschaf/svelte that referenced this issue May 22, 2025
The spec states the title element supports global attributes.
https://html.spec.whatwg.org/#the-title-element

Reverts the title attribute validation introduced in sveltejs#1721.

Fixes sveltejs#5198.
@jschaf jschaf linked a pull request May 22, 2025 that will close this issue
6 tasks
@jschaf
Copy link

jschaf commented May 22, 2025

Hi all, I'm interested in Svelte, so I figured I'd try my hand at some easy-ish issues to get a feel for it.

I threw up a PR to fix this issue, #15983. I'm happy to modify or close the PR if this behavior is no longer desired.

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

Successfully merging a pull request may close this issue.

8 participants