Is it important to use <label> in HTML?

本小妞迷上赌 提交于 2019-12-03 05:26:11
GSto

It's important for a number of reasons:

  • Clicking the label focuses on the
    text field, which is something a lot of users expect.
  • It's helpful for the accessibility reasons.
  • How else is the user going to know which field is which? You could use just text or a span or something, but why would you?
  • It leads to a more semantic markup.

It helps for accessibility, e.g. screen-readers.

Also for things like checkboxes it allows the user to click on the label and not just the checkbox itself (Try it!).

It's important for accessibility, so blind people using screen readers can easily tell which text box is meant for which thing, since possibly otherwise their software cannot tell the purpose of the active text box from the page structure. Also, clicking on the label will focus the appropriate input control, which is convenient.

Future use:

In a case where the input html form is directly linked with database ( happens in frameworks)

so the input form variables directly represent database columns.

So, instead of showing database column names to the user in the form, we can show simplified names to the user using Labels.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!