What are the different ways to visually hide content (and make it available only for screen readers)?
What are the different ways to visually hide content (and make it available only for screen readers)?
To visually hide content while making it available only for screen readers, several CSS techniques can be employed. These methods ensure that the content is not visible on the screen but remains accessible to screen readers, which are used by individuals with visual impairments. Here are the primary techniques:
Using the clip or clip-path Property:
This method involves using the CSS clip or clip-path property to create a small, invisible clipping region into which the content is placed. The content is technically on the page but is clipped to a tiny, invisible area. For example:
.visually-hidden {
position: absolute;
clip: rect(0 0 0 0);
clip-path: inset(50%);
height: 1px;
width: 1px;
overflow: hidden;
white-space: nowrap;
}
This method is effective for hiding content visually but keeping it accessible to screen readers.
Absolute Positioning Off-Screen: This technique involves positioning the content far off the visible area of the screen. Typically, this is done by using negative text-indent or positioning the content outside the visible viewport:
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.