Skip to content

Ff149 allow more chars in attributes/element names#43350

Open
hamishwillee wants to merge 1 commit intomdn:mainfrom
hamishwillee:ff149_allow_chars_attributes_elements
Open

Ff149 allow more chars in attributes/element names#43350
hamishwillee wants to merge 1 commit intomdn:mainfrom
hamishwillee:ff149_allow_chars_attributes_elements

Conversation

@hamishwillee
Copy link
Collaborator

@hamishwillee hamishwillee commented Mar 6, 2026

FF149 adds support for additional characters to be used in attribute and element names in https://bugzilla.mozilla.org/show_bug.cgi?id=1773312. Previoulsy the DOM allowed you to only create them with XML characters, now the rules are less restrictive.

This adds docs updates.

  • createAttribute()
  • setAttribute()
  • toggleAttribute()
  • createElement()
  • createElementNS()
  • createDocument()
  • createAttributeNS()
  • setAttributeNS()
  • CustomElementRegistry.whenDefined()
  • CustomElementRegistry.define()

Related docs work can be tracked in #43218

@hamishwillee hamishwillee requested a review from a team as a code owner March 6, 2026 06:05
@hamishwillee hamishwillee requested review from chrisdavidmills and removed request for a team March 6, 2026 06:05
@hamishwillee hamishwillee marked this pull request as draft March 6, 2026 06:05
@github-actions github-actions bot added Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed labels Mar 6, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

Preview URLs (10 pages)
External URLs (7)

URL: /en-US/docs/Web/API/Document/createAttribute
Title: Document: createAttribute() method


URL: /en-US/docs/Web/API/Document/createAttributeNS
Title: Document: createAttributeNS() method


URL: /en-US/docs/Web/API/Document/createElement
Title: Document: createElement() method


URL: /en-US/docs/Web/API/Document/createElementNS
Title: Document: createElementNS() method


URL: /en-US/docs/Web/API/DOMImplementation/createDocument
Title: DOMImplementation: createDocument() method


URL: /en-US/docs/Web/API/Element/setAttribute
Title: Element: setAttribute() method


URL: /en-US/docs/Web/API/Element/setAttributeNS
Title: Element: setAttributeNS() method

(comment last updated: 2026-03-10 04:01:19)


```js-nolint
createAttribute(name)
createAttribute(localName)
Copy link
Collaborator Author

@hamishwillee hamishwillee Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI Note, I have matched spec here for the name (and in other places too). It is useful to do so because these parts of the names all have meanings that map to properties.

- `InvalidCharacterError` {{domxref("DOMException")}}
- : Thrown if the [`qualifiedName`](#qualifiedname) value is not a valid [XML name](https://www.w3.org/TR/xml/#dt-name); for example, it starts with a number, hyphen, or period, or contains characters other than alphanumeric characters, underscores, hyphens, or periods.
- : Thrown if the [`qualifiedname`](#qualifiedname) value is not a valid attribute name.
A string is a valid attribute name if its length is at least 1 and it does not contain ASCII whitespace, `NULL`, `/` , `=` or `>` (U+0000, U+002F, U+003D or U+003E, respectively).
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name validation covered in https://dom.spec.whatwg.org/#namespaces


If you are working with HTML documents and you don't need to specify the requested attribute as being part of a specific namespace, use the {{domxref("Element.setAttribute()", "setAttribute()")}} method instead.

Note that `setAttributeNS()` is the only method for namespaced attributes which expects the fully qualified name, i.e., `"namespace:local-name"`.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I don't believe this to be true any more, if it ever was. The algorithm is the same for all of these NS methods: https://dom.spec.whatwg.org/#validate-and-extract

Perhaps needs testing to see that it really was required previously.

Comment on lines +52 to +57
- `is` {{Optional_Inline}}
- : A string defining the tag name for a custom element (that was previously defined using {{domxref("CustomElementRegistry/define", "customElements.define()")}}).
The new element will be given an `is` attribute whose value is the custom element's tag name.
See [Web component example](#web_component_example) for more details.
- `customElementRegistry` {{Optional_Inline}}
- : A {{domxref("CustomElementRegistry")}} that sets the [Scoped custom element registry](/en-US/docs/Web/API/Web_components/Using_custom_elements#scoped_custom_element_registries) of a custom element.
Copy link
Collaborator Author

@hamishwillee hamishwillee Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @chrisdavidmills When you get to this one, it looks like this is how a scoped custom element registry can be specifically assigned to an element. It isn't clear to me if this is another option that should be covered in the linked doc, or if this is something used "under the hood". But I plan on leaving that with you, since it is out of scope for me and I seem to recall you doing that work recently.

What I have done though is create a BCD entry for these two options mdn/browser-compat-data#29216

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hamishwillee I didn't work on this recently, sorry.

The last time I touched any custom element stuff was a long time ago.

@hamishwillee hamishwillee force-pushed the ff149_allow_chars_attributes_elements branch from febf052 to f600acb Compare March 10, 2026 02:37
@hamishwillee hamishwillee changed the title Ff149 allow chars attributes elements Ff149 allow more chars in attributes/element names Mar 10, 2026
@hamishwillee hamishwillee force-pushed the ff149_allow_chars_attributes_elements branch from f600acb to 2643011 Compare March 10, 2026 02:51
@hamishwillee hamishwillee marked this pull request as ready for review March 10, 2026 02:51
Includes:
- Document.createAttribute()/createAttributeNS()
- Document.setAttribute()/setAttributeNS()
- Document.createElement()/createElementNS()
- Element.toggleAttribute()
- DOMImplementation.createDocument()
- CustomElementRegistry.whenDefined()/define()
@hamishwillee hamishwillee force-pushed the ff149_allow_chars_attributes_elements branch from 2643011 to 2745030 Compare March 10, 2026 03:59
- `InvalidCharacterError` {{domxref("DOMException")}}
- : Thrown if the [`name`](#name) value is not a valid [XML name](https://www.w3.org/TR/xml/#dt-name); for example, it starts with a number, hyphen, or period, or contains characters other than alphanumeric characters, underscores, hyphens, or periods.
- : Thrown if the [`localName`](#localName) value is not a valid attribute name.
It must have at least 1 character, and may not contain ASCII whitespace, `NULL`, `/` , `=` or `>` (U+0000, U+002F, U+003D or U+003E, respectively).
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, all the docs follow this pattern of including the precise set of allowed chars in the exception. I think that better than specifying in the localname, in particular now that the set of chars that is allowed matches the same element/attribute in HTML.

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

Labels

Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants