You first have to understand that elements can have an "accessible name" and an "accessible description". The "accessible name" is often just referred to as the "name" and is what assistive technologies use to refer to the element. For example, the name is what is announced by a screen reader when you navigate to the element and the name is what a speech interface user would say to select the element ("click <name>").
In your example, which refers to Approach 2 from W3, aria-describedby
is setting the "accessible description" of the table. The <caption>
is what sets the accessible name. Note that the W3 example sets both and not just aria-describedby
.
So, if you only use aria-describedby
and not also a <caption>
, then you are only setting the description of the table. The table won't have a name for the screen reader to announce but it will still announce the description.
So the answer to your question is, "not exactly". You can use an <h1>
and aria-describedby
but it does not replace <caption>
because the caption is the accessible name of the table. But you can tweak it a bit and use <h1>
and aria-labelledby
instead of a caption to set the accessible name.
Note that you can have a <caption>
that is not visible so that the accessible name is set (and the screen reader announces it) in case you are worried about the aesthetics of the page and don't want a visible caption. Visible captions are a best practice but you can certainly hide it if needed. But don't hide the caption with CSS display:none
. Instead, hide it with CSS that essentially sets the size to 1 pixel using something like an "sr-only" class.