[HTML5] How Visible vs. Hidden Elements Affect Keyboard/Screen Reader Users (ARIA)

There are many techniques for hiding content in user interfaces, and not all are created equal! Learn how different hiding techniques in HTML, CSS and ARIA impact keyboard and screen reader users in addition to visual display. As a bonus, we'll also take a look using a screen reader on a mobile device.

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Visible vs. Hidden</title>
    <meta name="viewport" content="initial-scale=1">
    <link rel="stylesheet" type="text/css" href="css/demo.css">
</head>
<body>
     <!-- no space reserved, hidden from aria-->
    <div style="display: none;">
        <h1>Heading</h1>
        <a href="#link1">Link 1</a>
    </div>
    <!-- no space reservced, hidden from aria-->
    <div hidden>
        <h1>Heading</h1>
        <a href="#link2">Link 2</a>
    </div>
    <!-- reserve the space, not hidden from aria-->
    <div style="opacity: 0;">
        <h1>Heading</h1>
        <a href="#link3">Link 3</a><!-- can add tabindex="-1" to hide from tab focus -->
    </div>
    <!-- reserve the space, link is not reachable, similar to display:none; -->
    <div style="visibility: hidden;">
        <h1>Heading</h1>
        <a href="#link4">Link 4</a>
    </div>
   <!-- content is still be renderered to the screen, and link is also reachable -->
    <div class="visuallyhidden">
        <h1>Heading</h1>
        <a href="#link5">Link 5</a>
    </div>
   <!-- render to screen and hidden from aria-->
    <div aria-hidden="true">
        <h1>Heading</h1>
        <a href="#link6">Link 6</a>
    </div>
</body>
</html>
复制代码

 

 

 

posted @   Zhentiw  阅读(169)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2017-04-18 [Typescript] Generics using TypeScript
2017-04-18 [Linux] Use find to search for filename patterns
2017-04-18 [Git] How to rename your remote branch
2017-04-18 [Django] ModelViewSet from rest_framework and Router
2017-04-18 [Node.js] Take Screenshots of Multiple Dimensions for Responsive Sites using Nightmare
2017-04-18 [Webpack] Access Webpack Dev Server from Mobile Safari on an iPhone
2016-04-18 [Angular 2] Router basic and Router Params
点击右上角即可分享
微信分享提示