-
Notifications
You must be signed in to change notification settings - Fork 45
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
Change guidance on sections and landmarks in HTML #781
Conversation
An attempt to rewite the guidance on use of `<section>` tags to solve the problems in #617. I think the current guidance on use of `<section>` tags is unclear because: - the approach it recommends (using `aria-labelledby` to get their accessible name from the heading) creates a region landmark but the examples seem to show content that wouldn't benefit from being in one - from looking through a lot of GDS repos, I couldn't find any code following this pattern - it seems to clash with the current HTML5 spec', which includes similar content examples but doesn't use of `aria-labelledby` to set an accessible name The HTML5 spec' on `<section>`: https://html.spec.whatwg.org/multipage/sections.html#the-section-element). By 'region landmark', I mean an element with `role="region"`. I think a major cause of this confusion comes from the current guidance having been written when the HTML5 spec' still said that `<section>`s should be used with `<h1>`s to create the document outline, something never implemented in any browser: https://www.tpgi.com/html5-document-outline/) This has since been changed: whatwg/html#7829 The spec' now seems to advocate using `<section>`s to identify the scope of a heading. This arguably makes the HTML easier to read but doesn't add any new semantics so I'm wary of including guidance for it here. These changes instead intend to clear up the existing guidance on use of `<section>` tags by making it clear that this approach creates region landmarks and that using them in other ways (without assigning an accessible name) removes any semantics they add. Worth noting that these changes gratefully borrow from https://www.scottohara.me/blog/2018/03/03/landmarks.html Final note: I expect a bit of discussion on this pull request so intend to update the date of the page these changes are in if and when they are agreed to be the correct approach to the issue.
c7388a4
to
ecf6031
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with the change in principle. A few comments on some of the wording, but hopefully nothing major…
If you use more than one `<nav>` block in your page it is advisable to use | ||
`aria-labelledby` to label each one, to make clear the type of navigation | ||
contained by each. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appreciate this is just tidying up existing guidance, but would be tempted to talk about accessible names here, and reference both aria-labelledby
and aria-label
– unless we want to express a preference for one over the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be addressed in 7747132.
As suggested by comments on the pull request associated with this branch: - [rewrite advice on labelling region landmarks](#781 (comment)) - [rewrite intro to region landmarks section](#781 (comment)) - [reference both aria-label and aria-labelledby as ways to assign an accessible name](#781 (comment))
Based on comments on the pull request associated with this branch: #781 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good @tombye, and think you've addressed the points Ollie raised.
My only feedback is that you may want to bump the last_reviewed_on
date since this PR has been around a while.
An attempt to rewite the guidance on use of
<section>
tags to solve the problems in #617.Problems with the current guidance
I think the current guidance on use of
<section>
tags is unclear because:aria-labelledby
to get their accessible name from the heading) creates a region landmark1 but the examples seem to show content that wouldn't benefit from being in onearia-labelledby
to set an accessible nameCauses of the confusion the issue describes
I think a major cause of this confusion comes from the HTML5 spec's description of
<section>
tags. At the point this guidance was written, it said they should be used with<h1>
s to create the document outline, something never implemented in any browser and therefore confusing for developers:https://www.tpgi.com/html5-document-outline/
This has since been changed (see whatwg/html#7829) but, without an impact on the document outline, they are now effectively just there to mark the block of content a heading labels:
(This is from the current HTML5 spec`.)
This arguably makes the HTML easier to read, and allows those blocks to be styled, but doesn't add any new semantics (because
<section>
s without accessible names are basically<div>
s) so I'm wary of including guidance for it here.Reasoning behind these changes
These changes instead intend to clear up the existing guidance on use of
<section>
tags by making it clear that this approach creates region landmarks and that using them in other ways (without assigning an accessible name) removes any semantics they add.Other notes
These changes gratefully borrow from https://www.scottohara.me/blog/2018/03/03/landmarks.html
This is not meant as a critique of the excellent work done on the current guidance by @ChrisBAshton but rather an iteration of it, to help clear up some of the confusion in developers minds caused by how
<section>
s have been implemented and explained over the years.Final note: I expect a bit of discussion on this pull request so intend to update the date of the page these changes are in
if and when they are agreed to be the correct approach to the issue.
Footnotes
By 'region landmark', I mean an element with
role="region"
. ↩the HTML5 spec' on
<section>
. ↩