简体   繁体   English

辅助功能的占位符文本最佳做法

[英]Placeholder text best practices for accessibility

Given following markup as an example: 以以下标记为例:

 <label for="email">Email</label> <input type="email" placeholder="foo@bar.baz" id="email" /> <label for="cc">Credit card</label> <input type="input" placeholder="XXXX XXXX XXXX XXXX" id="cc" /> 

Will screen reader read something like "Email field, foo at bar dot com", "Credit card XXXX space XXXX space ..."? 屏幕阅读器会读取诸如“电子邮件字段,条点com上的foo”,“信用卡XXXX空间XXXX空间...”之类的内容吗? If yes, I guess that is not the best user experience and it is better to avoid using placeholders this way. 如果是,我想那不是最佳的用户体验,最好避免以这种方式使用占位符。 Are there guidelines or examples of how to give user a short hint intended to aid the user with data entry in an easy to understand format that works for all users? 是否有一些准则或示例可以为用户提供简短提示,以帮助用户以一种易于理解的格式输入数据,从而适用于所有用户?

Screen readers such as JAWS and NVDA do not read placeholder text, it's a visual addition only. 诸如JAWS和NVDA之类的屏幕阅读器不会读取占位符文本,这只是视觉上的添加。

However, if you're providing important information visually (such as format for data entry) there is no reason you shouldn't be conveying this information to screen reader users as well. 但是,如果您以可视方式提供重要信息(例如数据输入格式),则没有理由也不应将此类信息传达给屏幕阅读器用户。 A good way to do this is with a screen reader only bit of text. 一个很好的方法是使用屏幕阅读器仅显示少量文本。 Create a class using CSS which hides the text visually (off screen), and pop it into a span where you'd like it to be read out. 使用CSS创建一个类,该类以可视方式(在屏幕外)隐藏文本,然后将其弹出到您希望读出的范围内。

I've used the example of a Date of Birth below, as the format for entering a date can widely vary. 我以下面的“出生日期”为例,因为输入日期的格式可能会大不相同。 Things like credit card numbers and email addresses are pretty standard and probably don't require hints. 信用卡号和电子邮件地址之类的东西是非常标准的,可能不需要提示。

 .sr-only { position: absolute; left: -99999px; height: 1px; width: 1px; overflow: hidden; } 
 <label for="DOB"> DOB <span class="sr-only">Enter date in the format DD/MM/YYYY</span> </label> <input type="text" placeholder="DD/MM/YYYY" id="DOB"> 

The placeholder text has to be seen as a purely decorative element. 占位符文本必须被视为纯粹的装饰元素。 It may not be read by screenreaders. 屏幕阅读器可能无法读取该内容。

In your examples, that's perfectly ok. 在您的示例中,这完全可以。 Screenreader users perfectly know the format of an e-mail address, and do not want to ear "ex ex ex ex. ex ex ex ex. ex ex ex ex. ex ex ex ex." 屏幕阅读器用户完全了解电子邮件地址的格式,并且不希望听到“ ex ex ex。ex ex ex ex。ex ex ex ex。ex ex ex。”的消息。 instead of "enter your credit card number" (note that grouping four by four is impossible when your card number has 13 digits.) 而不是“输入您的信用卡号” (请注意,如果您的卡号有13位数字,则不能四乘四进行分组。)

If you really have to give a hint, you have to insert it in the label: 如果确实需要提示,则必须将其插入标签中:

More information on the W3C Webpage: 在W3C网页上的更多信息:

Formatting hints are good for all users, whether visually impaired or not. 格式化提示对所有用户均有益,无论是否有视觉障碍。 Having an example below the field and associated with the field using aria-describedby is how I usually do it. 我通常在该字段下有一个示例,并使用aria-describedby与该字段相关联。

<label for="email">Email</label>
<input type="email" id="email" aria-describedby="format"/>
<span id='format'>Format: foo@bar.baz</span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使网站易于访问的最佳做法是什么? - What are the best-practices for making a website accessibility-friendly? 有关 aria-describedby 和表单字段最佳实践的可访问性问题 - Accessibility Questions on best practices for aria-describedby and form fields 有什么方法可以禁用 UITextField 中占位符文本的可访问性画外音吗? - Is there any way to disable accessibility voice-over of placeholder text in UITextField? 禁用所有可访问性 API(屏幕阅读器)读取的占位符文本 - Disable placeholder text to be read by all accessibility API(screen reader) 图像替代文字的Facebook无障碍最佳做法 - Facebook accessibility best practice for image alt text web forms 帮助文本的辅助功能最佳实践 - Accessibility Best Practice for Help Text on web forms 在不失去网站可访问性和SEO的情况下使用JavaScript的最佳实践和技巧是什么? - What are best practices and tips to use JavaScript without losing the site's Accessibility and SEO? 实施文本大小可访问性功能的最佳方法是什么? - What would be the best way to implement a text size accessibility feature? 产品列表图像替代文本可访问性的最佳做法(和法律)是什么? - What is best practice (and legal) for product listing image alt text for accessibility? SVG文本可访问性 - SVG text accessibility
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM