E-mail List Archives
Thread: Always adding a dir attribute to <html>
Number of posts in this thread: 4 (In chronological order)
From: Ridz Apps
Date: Fri, Sep 08 2023 1:08PM
Subject: Always adding a dir attribute to <html>
No previous message | Next message →
Just Iike it is considered to be best practice to always add a lang
attribute, what about dir?
From: Patrick H. Lauke
Date: Fri, Sep 08 2023 1:15PM
Subject: Re: Always adding a dir attribute to <html>
← Previous message | Next message →
On 08/09/2023 20:08, Ridz Apps wrote:
> Just Iike it is considered to be best practice to always add a lang
> attribute
It's not a best practice, it's an actual WCAG requirement to explicitly
indicate a document's natural language.
> what about dir?
That is optional. The spec actually explicitly defines that in the
absence of the dir attribute on the topmost element (when the element
has "no parent element"), "ltr" is used/assumed
https://html.spec.whatwg.org/multipage/dom.html#the-dir-attribute
https://html.spec.whatwg.org/multipage/dom.html#parent-directionality
P
--
Patrick H. Lauke
https://www.splintered.co.uk/ | https://github.com/patrickhlauke
https://flickr.com/photos/redux/ | https://www.deviantart.com/redux
https://mastodon.social/@patrick_h_lauke | skype: patrick_h_lauke
From: H S
Date: Fri, Sep 08 2023 4:43PM
Subject: Re: Always adding a dir attribute to <html>
← Previous message | Next message →
Then how come document.dir is not ltr if html element has no dir attribute?
From: Patrick H. Lauke
Date: Fri, Sep 08 2023 5:04PM
Subject: Re: Always adding a dir attribute to <html>
← Previous message | No next message
On 08/09/2023 23:43, H S wrote:
> Then how come document.dir is not ltr if html element has no dir attribute?
Because document.dir "Returns the html element's dir attribute's value,
if any". If the dir attribute is missing, it is not automagically
backfilled/created. The actual computed directionality (e.g. what it is
actually evaluated as when the attribute is missing/empty/contains an
unrecognised value) can't be queried from JS, I believe.
P
--
Patrick H. Lauke
https://www.splintered.co.uk/ | https://github.com/patrickhlauke
https://flickr.com/photos/redux/ | https://www.deviantart.com/redux
https://mastodon.social/@patrick_h_lauke | skype: patrick_h_lauke