One way to incorporate UI text into your design is by using the CSS content
property. This type of generated text doesn't get picked up in searches since it's considered part of the style rather than the actual content.
For instance:
If you have a button element like
<button id="dosomething"></button>
, you can insert non-searchable text within it using CSS, like so:
#dosomething:before {
content: "Click Me";
}
I've put together a demonstration on JSFiddle to show how this technique functions: JS Fiddle Example. It's worth noting that this method also works with <a>
tags.
I suggest utilizing the :before
selector instead of :after
because the former is compatible with IE8, whereas the latter isn't.
If you're dealing with a more intricate UI component, another approach is to nest an additional element inside it to contain the text content. For example:
<div id="complexcontrol"><div class="text"></div></div>
And then apply the following CSS:
#complexcontrol .text:before {
content: "Click Me";
}
Keep in mind that screen readers may not interpret these styles correctly, leading to accessibility issues similar to those encountered with images. However, this method offers easier maintenance and facilitates responsive web design.