Design comparison
Solution retrospective
I'm proud of the fact that I was able to complete this challenge using the BEM methodology and implementing it through SCSS, which made my styling much cleaner, more organized and easier to understand.
What challenges did you encounter, and how did you overcome them?Two main challenges:
- Since I used the CSS background-image property to add many of the images, I was unable to really add alt attributes. To get around this, I used aria-role as "img" and aria-label as the description of the image.
- Again, the use of the background-image property instead of img elements made it so when I tried to add a hover state that changed the opacity of the image, it also affected the opacity of the elemet's text. I tried to get around this by using some CSS pseudo-elements, but ultimately gave up. Next time though, I will make sure tu use the proper img elements for important stuff.
Acessibility. I feel like I'm still unable to get the whole aria label, labelledby, expanded, etc. right.
Community feedback
- @krushnasinnarkarPosted 4 months ago
Hi @alvarozama,
Congratulations on successfully completing the challenge! Your solution looks nice.
Sure, I can help clarify the use of ARIA (Accessible Rich Internet Applications) attributes to improve the accessibility of your webpage. Here are explanations and examples for the most commonly used ARIA attributes:
aria-label: The
aria-label
attribute defines a string that labels the current element. It is often used when the element itself does not have a visible label.<button aria-label="Close menu">ā</button>
aria-labelledby: The
aria-labelledby
attribute identifies the element (or elements) that label the current element. It is used to reference other elements' IDs.<h2 id="section1">Introduction</h2> <div aria-labelledby="section1"> Content labeled by the heading with id="section1" </div>
aria-expanded: The
aria-expanded
attribute indicates whether the element, or another grouping element it controls, is currently expanded or collapsed.<button aria-expanded="false" aria-controls="menu" onclick="toggleMenu()">Menu</button> <nav id="menu" hidden> Menu content </nav>
Here,
aria-expanded
should be updated dynamically using JavaScript when the menu state changes:function toggleMenu() { const menuButton = document.querySelector('button[aria-controls="menu"]'); const menu = document.getElementById('menu'); const isExpanded = menuButton.getAttribute('aria-expanded') === 'true'; menuButton.setAttribute('aria-expanded', !isExpanded); menu.hidden = isExpanded; }
role: The
role
attribute defines the role of an element in an application. Common roles includebutton
,navigation
,dialog
, andalert
.<div role="alert"> This is an important message. </div>
aria-hidden: The
aria-hidden
attribute indicates that the element and all of its descendants are not visible or perceivable to any user as part of the accessible user interface.<div aria-hidden="true"> This content will be hidden from screen readers. </div>
Explanation:
aria-label
: Used for labeling elements with a descriptive text that is not visually presented (e.g., button to open the menu).aria-labelledby
: Reference an ID of an element that labels the current element (not used in the example but useful for complex widgets).aria-expanded
: Indicates the current state (expanded or collapsed) of a collapsible element like the menu.role
: Specifies the role of elements (e.g.,role="img"
for non-decorative images).aria-hidden
: Used to hide elements from screen readers (not used in the example but useful for decorative images or elements).
By correctly using these ARIA attributes, your webpage becomes more accessible to users who rely on assistive technologies like screen readers.
I hope you find this helpful, and I would greatly appreciate it if you could mark my comment as helpful if it was.
Feel free to reach out if you have more questions or need further assistance.
Happy coding!
Marked as helpful0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord