Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visually remove <h1> element whilst preserving screen reader accessibility and avoiding penalties by search engines

I would like to visually hide the <h1> element on the page from regular site visitors; however, I am conscious that the element is important for users with screen readers. So I need to visually hide the element in a way that screen readers can still access it.

It seems there are many techniques which could be used. For example using text indenting to move the text off the screen. In other case some use styling, to set the height and width of to 1px and then hide the overflow.

While these should work from an accessibility point of view, I am concerned that these techniques could be considered as a case of "cloaking" by search engines, resulting in the site being penalized.

What would be the best way of solving this? Is this even possible?

like image 542
Benjen Avatar asked Aug 28 '15 07:08

Benjen


People also ask

How do I hide text and make it accessible by screen reader?

The conventional way is to use CSS ( display:none; and visibility:hidden; ) or the HTML 5 `hidden` attribute. These properties hide elements not only on the screen, but also for screen reader users. Thus, these elements will not be visible nor vocalized by Assistive technologies (AT).

How do I hide element from screen reader?

To hide text from a screen reader and display it visually, use the aria-hidden attribute and set it to true. To hide text from a screen reader and hide it visually use the hidden attribute. You can also use CSS to set display: none or visibility: hidden to hide an element from screen readers and visually.

Can I hide h1?

You can visually hide the <h1> in one of the following ways: Use the . wdn-text-hidden class on the <h1>. This will hide it from visual presentation, but keep it available to AT and bots.


1 Answers

Below is the standard code used in Boilerplate. Simply assign "visuallyhidden" class to your headings. They will not be visible on the screen but the screen readers will be able to read them.

.visuallyhidden {
  border: 0;
  clip: rect(0 0 0 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
}
.visuallyhidden.focusable:active,
.visuallyhidden.focusable:focus {
  clip: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  position: static;
}
like image 60
WizzyFX Avatar answered Sep 16 '22 17:09

WizzyFX