Skip to content

Conversation

@llepere
Copy link
Contributor

@llepere llepere commented Jun 4, 2025

TLDLR; Add role article and two ARIA descriptors to MjBody

For accessibility the main landmark is important to point the user to the main content of the email and navigate easily with a screen reader. We can use the <main> tag or add a role="main" to a <div>

We don't use <main> tag here because of some limitations from email providers (Outlook, Gmail, etc.).

So update the MjBody class to add role: 'main' as parameter in htmlAttributes function.

So update the MjBody with a role: 'article and two ARIA-descriptors (see comment below here)

More on main here

@DazGreerMJ
Copy link

Hi @llepere, as per the link provided in the pull request: ARIA: main role - ARIA | MDN , only one main role should be present per document, which poses a problem for those using webmail clients which already use role=”main”.

Advice is to use the following:
https://www.goodemailcode.com/email-code/template#wrapping-element

<div role="article" aria-roledescription="email" aria-label="email name">

.. where ‘email name’ should be a useful descriptor of the email, e.g. the subject line.

@llepere
Copy link
Contributor Author

llepere commented Aug 13, 2025

Hi @llepere, as per the link provided in the pull request: ARIA: main role - ARIA | MDN , only one main role should be present per document, which poses a problem for those using webmail clients which already use role=”main”.

Advice is to use the following: https://www.goodemailcode.com/email-code/template#wrapping-element

<div role="article" aria-roledescription="email" aria-label="email name">

.. where ‘email name’ should be a useful descriptor of the email, e.g. the subject line.

Hi @DazGreerMJ

I've made the changes. Is it good for you ? :)

@llepere llepere changed the title [Accessibility] - add role main landmark [Accessibility] - add attributes for accessibility in MjBody Aug 13, 2025
@dazgreer
Copy link
Collaborator

thanks @llepere,

The attributes are all good, but where it says 'aria-label': 'email name',, the value 'email name' should be a description of the email.

Probably best to use globalData.title for this in MJML and omit the attribute completely if it's blank

- Add two aria descriptors for accessibility purpose
- Rename role main into role article
@llepere llepere force-pushed the feature/add-main-landmark-for-accessibility branch from fe15b90 to 13294b0 Compare August 13, 2025 13:38
@llepere
Copy link
Contributor Author

llepere commented Aug 13, 2025

thanks @llepere,

The attributes are all good, but where it says 'aria-label': 'email name',, the value 'email name' should be a description of the email.

Probably best to use globalData.title for this in MJML and omit the attribute completely if it's blank

Done @dazgreer

@DazGreerMJ
Copy link

Thanks @llepere, that's great!

@dazgreer
Copy link
Collaborator

dazgreer commented Sep 2, 2025

Hey @llepere, please can you update the README.md copy for mj-body from:

This is the starting point of your email.

.. to ...

This is the starting point of your email. To aid accessibility, MJML automatically adds a div tag as the child of the body, with the following ARIA attributes role="article", aria-roledescription="email" and aria-label="EMAIL NAME", where 'EMAIL NAME' is taken from the content of the mj-title tag. The lang" and dir attributes are also added here, with values taken from the mjml tag.

Thanks
Daz

@llepere
Copy link
Contributor Author

llepere commented Sep 2, 2025

Hey @llepere, please can you update the README.md copy for mj-body from:

This is the starting point of your email.

.. to ...

This is the starting point of your email. To aid accessibility, MJML automatically adds a div tag as the child of the body, with the following ARIA attributes role="article", aria-roledescription="email" and aria-label="EMAIL NAME", where 'EMAIL NAME' is taken from the content of the mj-title tag. The lang" and dir attributes are also added here, with values taken from the mjml tag.

Thanks Daz

The readme is updated 👍🏻

- Explain the change of mjml-body for accessibility in the readme.
@llepere llepere force-pushed the feature/add-main-landmark-for-accessibility branch from c51c040 to 870feea Compare September 2, 2025 11:49
@totocap totocap merged commit 7348556 into mjmlio:master Sep 2, 2025
3 checks passed
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.

4 participants