Skip to content
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

Merged
merged 4 commits into from
May 3, 2023

Conversation

tombye
Copy link
Contributor

@tombye tombye commented Jan 5, 2023

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:

  • the approach it recommends (using 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 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'2, which includes similar content examples but doesn't use of aria-labelledby to set an accessible name

Causes 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:

<header>
 <hgroup>
  <h1>My Book</h1>
  <p>A sample with not much content</p>
 </hgroup>
 <p><small>Published by Dummy Publicorp Ltd.</small></p>
</header>
<section class="chapter">
 <h2>My First Chapter</h2>
 <p>This is the first of my chapters. It doesn't say much.</p>
 <p>But it has two paragraphs!</p>
</section>
<section class="chapter">
 <h2>It Continues: The Second Chapter</h2>
 <p>Bla dee bla, dee bla dee bla. Boom.</p>
</section>

(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

  1. By 'region landmark', I mean an element with role="region".

  2. the HTML5 spec' on <section>.

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.
@tombye tombye force-pushed the update-guidance-on-sections branch from c7388a4 to ecf6031 Compare January 5, 2023 23:44
Copy link
Contributor

@36degrees 36degrees left a 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…

source/manuals/programming-languages/html.html.md.erb Outdated Show resolved Hide resolved
source/manuals/programming-languages/html.html.md.erb Outdated Show resolved Hide resolved
source/manuals/programming-languages/html.html.md.erb Outdated Show resolved Hide resolved
Comment on lines 55 to 57
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.
Copy link
Contributor

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.

Copy link
Contributor Author

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)
DavidBiddle
DavidBiddle previously approved these changes Apr 27, 2023
Copy link
Contributor

@DavidBiddle DavidBiddle left a 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.

@tombye tombye merged commit 90f63dc into main May 3, 2023
@tombye tombye deleted the update-guidance-on-sections branch May 3, 2023 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update HTML guidance
3 participants