Label input name html

HTML Form Elements

This chapter describes all the different HTML form elements.

The HTML Elements

The HTML element can contain one or more of the following form elements:

The Element

One of the most used form element is the element.

The element can be displayed in several ways, depending on the type attribute.

Example

All the different values of the type attribute are covered in the next chapter: HTML Input Types.

The Element

The element defines a label for several form elements.

The element is useful for screen-reader users, because the screen-reader will read out loud the label when the user focus on the input element.

The element also help users who have difficulty clicking on very small regions (such as radio buttons or checkboxes) — because when the user clicks the text within the element, it toggles the radio button/checkbox.

The for attribute of the tag should be equal to the id attribute of the element to bind them together.

The Element

The element defines a drop-down list:

Example

The elements defines an option that can be selected.

By default, the first item in the drop-down list is selected.

To define a pre-selected option, add the selected attribute to the option:

Example

Visible Values:

Use the size attribute to specify the number of visible values:

Example

Allow Multiple Selections:

Use the multiple attribute to allow the user to select more than one value:

Example

The Element

The element defines a multi-line input field (a text area):

Example

The rows attribute specifies the visible number of lines in a text area.

The cols attribute specifies the visible width of a text area.

This is how the HTML code above will be displayed in a browser:

You can also define the size of the text area by using CSS:

Example

The Element

The element defines a clickable button:

Example

This is how the HTML code above will be displayed in a browser:

Note: Always specify the type attribute for the button element. Different browsers may use different default types for the button element.

The and Elements

The element is used to group related data in a form.

Читайте также:  Package is not accessible java

The element defines a caption for the element.

Example

This is how the HTML code above will be displayed in a browser:

The Element

The element specifies a list of pre-defined options for an element.

Users will see a drop-down list of the pre-defined options as they input data.

The list attribute of the element, must refer to the id attribute of the element.

Example

The Element

The element represents the result of a calculation (like one performed by a script).

Example

Perform a calculation and show the result in an element:

HTML Exercises

HTML Form Elements

Tag Description
Defines an HTML form for user input
Defines an input control
Defines a multiline input control (text area)
Defines a label for an element
Groups related elements in a form
Defines a caption for a element
Defines a drop-down list
Defines a group of related options in a drop-down list
Defines an option in a drop-down list
Defines a clickable button
Specifies a list of pre-defined options for input controls
Defines the result of a calculation

For a complete list of all available HTML tags, visit our HTML Tag Reference.

Источник

Label input name html

Подписывает поля ввода и другие элементы формы.

Время чтения: меньше 5 мин

Обновлено 8 сентября 2022

Кратко

Скопировать ссылку «Кратко» Скопировано

Элемент используется для создания подписи к элементу формы:

Пример

Скопировать ссылку «Пример» Скопировано

     div class="form-row"> label for="bread">Купить хлебlabel> input type="checkbox" name="bread" id="bread"> div>      

Как пишется

Скопировать ссылку «Как пишется» Скопировано

 ) -->  ) --> label>Click me input type="text">label> label for="username">Click melabel> input type="text" id="username">      

Как понять

Скопировать ссылку "Как понять" Скопировано

На многих веб-страницах есть формы — группы интерактивных элементов (полей ввода, выпадающих списков, чекбоксов и т.п.), связанных общим функциональным назначением. Яркие примеры форм — форма регистрации, форма входа, фильтры в каталогах. Формами удобно пользоваться, когда мы понимаем назначение каждого элемента. Для этого необходимо подписывать каждый элемент. И вот как раз для этих целей служит элемент .

Помимо текстовой подписи создаётся программная связь между подписью и элементом формы. Это сильно облегчает взаимодействие с формами незрячим или слабовидящим пользователям, использующим скринридеры. Когда фокус попадает на элемент формы, с которым связан , скринридер автоматически зачитывает текст подписи, и пользователь понимает, какие данные необходимо ввести или какие данные представлены в текущем элементе формы.

Чтобы связать с элементом формы можно пойти двумя путями:

  1. Задаём элементу формы атрибут id . Такое же значение задаём атрибуту for тега .
  2. Оборачиваем элемент формы в тег . В этом случае связь создаётся автоматически и нет необходимости в атрибутах id и for .
      Согласен на обработку данных   form action=""> label for="phone">Ваш телефон:label> input type="tel" name="phone" id="phone"> label> input type="checkbox" name="agree">Согласен на обработку данных label> form>      

Атрибуты

Скопировать ссылку "Атрибуты" Скопировано

for — значение этого атрибута должно соответствовать значению атрибута id связываемого элемента. Первый же элемент в документе, чей id будет совпадать со значением атрибута for , становится связанным с нашим . Единственное условие — элемент должен принадлежать к группе связываемых элементов: , , , , , и .

Если элемент с нужным id не является связываемым, то связь не создаётся, и даже если дальше по документу найдётся связываемый элемент с таким же id , то он уже не будет учитываться.

Подсказки

Скопировать ссылку "Подсказки" Скопировано

💡 Один элемент формы может быть связан с несколькими , но один может быть связан ровно с одним элементом формы.

💡 При клике на событие клика вызывается также и на связанном элементе формы.

💡 По умолчанию является строчным элементом и стилизуется аналогично или .

На практике

Скопировать ссылку "На практике" Скопировано

Денис Ежков советует

Скопировать ссылку "Денис Ежков советует" Скопировано

🛠 Обязательно связывайте с чекбоксами и радиокнопками. Это небольшие элементы интерфейса, в которые довольно сложно попасть курсором мыши или пальцем на мобильных устройствах. Если у них есть связанный , то пользователь может кликать по тексту подписи, а не целиться в сам чекбокс. Любите своих пользователей! 😉

Алёна Батицкая советует

Скопировать ссылку "Алёна Батицкая советует" Скопировано

🛠 Даже если дизайнер нарисовал форму, в которой не предусмотрены явные лейблы для элементов, то вам нужно всё равно прописать их в разметке и скрыть через стили. В этом случае их будет не видно, но скринридер их прочитает.

🛠 При нажатии на лейбл, связанный с полем ввода или другим элементом формы, фокус будет перемещён на этот элемент.

На собеседовании

Скопировать ссылку "На собеседовании" Скопировано

Какая разница между legend , caption и label с точки зрения доступности? Что между ними общего?

Скопировать ссылку "Какая разница между legend, caption и label с точки зрения доступности? Что между ними общего?" Скопировано

Это вопрос без ответа. Вы можете помочь! Почитайте о том, как контрибьютить в Доку.

Источник

HTML Tag

The tag is also used to define keyboard shortcuts and jump to the active element like links.

An input can be associated with several labels. If you click or tap a which is associated with a form control, the resulting click event will arise for the associated control.

Associating a with an element has some advantages:

  • The label text is both visually and pragmatically associated with the text input.
  • You can click on the associated label for focusing or activating the input, as well as on the input itself.

Syntax

The

There are two ways to associate a text label and the form to which it belongs:

Example of the HTML tag:

html> html> head> title>Title of the document title> head> body> form> label for="lfname">First name: label> input id="lfname" name="fname" type="text" /> form> body> html>

Result

simple label exmample

Example of the HTML tag with an element inside:

html> html> head> title>Title of the document title> head> body> form> label>Name input id="User" name="Name" type="text" /> label> form> body> html>

Example of HTML with a tag used with radio type of an tag:

html> html> head> title>Title of the document title> head> body> form> label for="barca">Barcelona label> input type="radio" name="team" id="barca" value="Barcelona"> br /> label for="real">Real Madrid label> input type="radio" name="team" id="real" value="Real Madrid"> br /> form> body> html>

Example of the HTML tag with CSS font properties:

html> html> head> title>Title of the document title> style> body < padding: 20px; > label < font-size: 20px; font-weight: 700; color: #1c87c9; > input < width: 50%; height: 28px; padding: 4px 10px; border: 1px solid #666; background: #cce6ff; color: #1c87c9; font-size: 16px; > style> head> body> form> label>Your Name: label> input id="User" name="Name" type="text"/> form> body> html>

Attributes

Attribute Value Description
accesskey accesskey Defines a hot key with which you can go to the attached to the label (through a for attribute) form element.
for element_id Sets the ID of the element to which the label should be bound.
form form_id Specifies the form (s) with which the label will be associated. This attribute allows you to place tags in an arbitrary location in the document, and not just as a descendant of the element. Obsolete.

How to style tag?

Common properties to alter the visual weight/emphasis/size of text in tag:

  • CSS font-style property sets the style of the font. normal | italic | oblique | initial | inherit.
  • CSS font-family property specifies a prioritized list of one or more font family names and/or generic family names for the selected element.
  • CSS font-size property sets the size of the font.
  • CSS font-weight property defines whether the font should be bold or thick.
  • CSS text-transform property controls text case and capitalization.
  • CSS text-decoration property specifies the decoration added to text, and is a shorthand property for text-decoration-line, text-decoration-color, text-decoration-style.

Coloring text in tag:

  • CSS color property describes the color of the text content and text decorations.
  • CSS background-color property sets the background color of an element.

Text layout styles for tag:

  • CSS text-indent property specifies the indentation of the first line in a text block.
  • CSS text-overflow property specifies how overflowed content that is not displayed should be signalled to the user.
  • CSS white-space property specifies how white-space inside an element is handled.
  • CSS word-break property specifies where the lines should be broken.

Other properties worth looking at for tag:

  • CSS text-shadow property adds shadow to text.
  • CSS text-align-last property sets the alignment of the last line of the text.
  • CSS line-height property specifies the height of a line.
  • CSS letter-spacing property defines the spaces between letters/characters in a text.
  • CSS word-spacing property sets the spacing between words.

Источник

Оцените статью