Frames and iframes are structural HTML elements used to embed web pages, web applications and HTML documents into parent web pages.
They’re essentially used to divide web pages into subsections each with their own unique content and functionality. Which allows for better functionality and organization when developing web applications.
However, they can present challenges for users with disabilities if not implemented with accessibility in mind. In this blog, we will cover practical and actionable solutions to make frames and iframes accessible, such as adding descriptive titles, providing alternative content, making iframes resizeable and using ARIA attributes effectively.
Table of Contents
Iframe or Frame, Which Is Better For Web Accessibility?
Frames and framesets were used to create scrollable static layouts, until they got deprecated and replaced by iframes in 2014 when HTML5 became the standard on the Web. Iframes are more flexible and allow more complex web applications and dynamic content to be embedded into web pages.
Frames are often more complex since they require a predefined layout structure called a frameset to be defined on the web page in order to be used. Iframes on the other hand don’t require setting a base layout. They also offer a more responsive design which can dynamically adapt to different screen sizes.
Frames are still used on legacy pre HTML5 web applications, and can often cause accessibility issues due to their complexity. They can break the flow of content on web pages, make navigation confusing and break the logical structure of a web page if not designed for web accessibility. This can be a major issue for screen readers who process content on web pages sequentially to convey information to the user.
There are no clear guidelines on which is better for web accessibility, nevertheless iframes reduce complexity of web pages which allows better accessibility management. Making them a better choice when building accessible web pages and web applications.
How Accessible Iframes And Frames Enhance User Experience
Labeling iframes and frames properly helps screen reader users understand information on-screen. Giving them context and helps them navigate content, especially when it is dynamically generated.
This reduces cognitive load for users with impairments by presenting information in a structured and predictable way.
Accessibility Challenges with Iframes and Frames
Iframes and Frames can pose significant accessibility issues for users relying on assistive technologies and keyboard navigation. Common issues include:
- Ambiguity for Screen Readers: Screen readers rely on the title attribute of frames to identify content within them. Without titles, the purpose of frames remains unclear to the user, and they’re left confused and unsure of what the content is about.
- Keyboard Navigation Issues: Poorly labeled frames complicates navigation for assistive technology users, making it unclear what each section of the web page is about.
- Lack of Alternative Content: If a frame fails to load, alternative content should be presented as fallback, such as a link or a short description. Otherwise users may miss critical information if no alternative content is set.
- Dynamic Content Distractions: Rapidly changing iframe content or too many unnecessary updates can overwhelm users with processing or attention disorders.
How to Make Iframes and Frames Accessible?
Let’s have a look at a few ways we can make iframes and frames accessible.
Define Clear and Descriptive Iframe and Frame Titles
Iframe titles should enable users to clearly differentiate between iframes, especially when multiple iframes are present on a web page. Using clear, descriptive and logical naming conventions helps users quickly understand the structure and navigate between iframes, without having to guess each iframe’s function. This reduces user confusion and time spent on web pages with multiple iframes.
Here’s a simple example demonstrating how to use the title attribute with <iframe> elements:
<html>
<body>
<iframe src="https://api.example.com/v1" title="External API embedded in iframe."></iframe>
<iframe srcdoc="<p>HTML Document directly embedded in iframe." title="HTML Document embedded in iframe."></iframe>
</body>
</html>
Similarly with <frame> elements, we can use the title attribute:
<html>
<frameset cols="50%,50%">
<frame src="search.html" title="Search menu">
<frame src="product.html" title="Product page">
</frameset>
</html>
Display Alternative Content in Iframes and Frames
Displaying alternative content is often ignored when creating iframes, they’re a crucial fallback option if an iframe fails to render. This can either be a link to another domain to access the missing information, the reason why the information is not available or any other crucial information the user needs to know.
Since there’s no special element used to display alternative content within iframes, we can do this by simply using the paragraph tag <p> for text, and an anchor tag <a> for hyperlinks. And directly adding them within an <iframe>.
In this example, the alternative content within the <p> and <a> tags is inside the <iframe>. If the iframe fails to load, the content within the <p> and <a> tag will be displayed automatically as a fallback:
<html>
<body>
<iframe src="products.html" title="Products">
<p>Your browser could not properly display the products:
<a href="products_alternative_link.html">Click here to view the products</a>.
</p>
</iframe>
</body>
</html>
With frames this can be done by first adding a <noframes> element within a frame, and adding the alternative content within the <noframes> element:
<html>
<frameset cols="50%,50%">
<frame src="search.html" title="Search menu">
<frame src="product.html" title="Product page">
<noframes>
<p>Your browser does not support frames.</p>
<a href="menu.html">View the menu here</a>
</noframes>
</frameset>
</html>
Allow Iframe and Frame Resizing
Iframes can easily be resized manually which can benefit users with visual disabilities who need a bigger display to see content.
Here’s an example where three <iframe> elements are resizeable:
<html>
<body>
<iframe srcdoc="Iframe 1" title="This is iframe one." style="resize: both;">
</iframe>
<iframe srcdoc="Iframe 2" title="This is iframe two." style="resize: both;">
</iframe>
<iframe srcdoc="Iframe 3" title="This is iframe three." style="resize: both;">
</iframe>
</body>
</html>
In the case of frames, this can be done with the resize attribute inside the <frame> element:
<frameset cols="50%,50%">
<frame src="menu.html" title="Navigation menu" resize="yes">
<frame src="content.html" title="Main content area" resize="yes">
</frameset>
When to Use ARIA Attributes?
ARIA attributes improve accessibility of dynamic or interactive frames and iframes, especially when native HTML elements are insufficient.
They can be useful with more complicated iframe setups such as charts, feeds, or other complex web applications that would require custom accessibility features.
ARIA Attributes Usage Case
- Complex Relationships: Use ARIA when iframes and frames are part of dynamic content or interactive widgets, such as a dashboard containing an embedded financial report iframe. For instance, applying aria-labelledby can link the iframe to a dashboard heading, making its relationship clear to assistive technologies and give more context to the user.
- Supplementing Context: When native HTML attributes can’t provide enough information, ARIA can add clarity. For example, an iframe displaying live stock market updates might use aria-live to alert users to changes in the data without overwhelming them.
In this example, we’ll create a relationship between the chart’s <H2> header text and our <SVG> chart, both inside an <iframe>. Using aria-labelledby pointing to the ID attribute of the chart header text.
This will allow screen readers to announce the chart title when it comes upon it within the iframe:
<iframe srcdoc='<h2 id="chart-title">Monthly Sales</h2>
<!-- SVG used as an example -->
<svg role="img" aria-labelledby="chart-title" width="200" height="100">
<rect x="10" y="20" width="30" height="60" fill="steelblue"><title>January</title></rect>
<rect x="60" y="40" width="30" height="40" fill="orange"><title>February</title></rect>
<rect x="110" y="40" width="30" height="40" fill="green"><title>March</title></rect>
</svg>' width="240" height="170" style="border:1;">
</iframe>
Best Practices with ARIA Attributes
- Prioritize Native HTML: HTML attributes like title are simpler and more widely supported. For example, <iframe title=”Video Content”> conveys purpose without needing additional ARIA roles.
- Use ARIA Sparingly: Avoid overusing ARIA to prevent unnecessary complexity. For example, instead of adding aria-hidden to a decorative iframe, simply ensure it is omitted from the focus order by using tabindex=”-1″.
- Enhance Clarity: Use ARIA for scenarios where it provides meaningful enhancements. For instance, if an iframe embeds an interactive calendar, aria-describedby can link to a description that explains how to use it with keyboard navigation.
Conclusion
Creating accessible frames and iframes ensures that users of all abilities can navigate and engage with content on your website and web application. Complex iframe setups can often make your website inaccessible to users with disabilities, which can greatly affect your website’s UX and violate WCAG or ADA accessibility guidelines.
By adding descriptive titles, naming related iframes logically, providing fallback content when iframes fail to load, and leveraging ARIA attributes where necessary. These steps not only comply with web accessibility standards but also reflect a commitment to inclusive and friendly web design.