Английская Википедия:HTML attribute

Материал из Онлайн справочника
Версия от 11:01, 18 марта 2024; EducationBot (обсуждение | вклад) (Новая страница: «{{Английская Википедия/Панель перехода}} {{short description|Special words used inside the opening tag to control the element's behaviour}} {{Html series}} '''HTML attributes''' are special words used inside the opening tag to control the element's behaviour. HTML attributes are a modifier of a ''HTML element type''. An attribute either modifies the default functionality of an element type or provides functionality to ce...»)
(разн.) ← Предыдущая версия | Текущая версия (разн.) | Следующая версия → (разн.)
Перейти к навигацииПерейти к поиску

Шаблон:Short description Шаблон:Html series

HTML attributes are special words used inside the opening tag to control the element's behaviour. HTML attributes are a modifier of a HTML element type. An attribute either modifies the default functionality of an element type or provides functionality to certain element types unable to function correctly without them. In HTML syntax, an attribute is added to a HTML start tag.

Several basic attributes types have been recognized, including: (1) required attributes, needed by a particular element type for that element type to function correctly; (2) optional attributes, used to modify the default functionality of an element type; (3) standard attributes, supported by many element types; and (4) event attributes, used to cause element types to specify scripts to be run under specific circumstances.

Some attribute types function differently when used to modify different element types. For example, the attribute name is used by several element types, but has slightly different functions in each.[1]

Description

HTML attributes generally appear as name–value pairs, separated by =, and are written within the start tag of an element, after the element's name:

<element attribute="value">element content</element>

Where element names the HTML element type, and attribute is the name of the attribute, set to the provided value. The value may be enclosed in single or double quotes, although values consisting of certain characters can be left unquoted in HTML (but not XHTML).[2][3] Leaving attribute values unquoted is considered unsafe.[4]

Although most attributes are provided as paired names and values, some affect the element simply by their presence in the start tag of the element[5] (like the ismap attribute for the img element[6]).

The abbreviation element, abbr, can be used to demonstrate these various attributes:

<abbr id="anId" class="aClass" style="color:blue;" title="Hypertext Markup Language">HTML</abbr>

This example displays as HTML in blue without being a link, and in most browsers, pointing the cursor at the abbreviation should display the title text "Hypertext Markup Language" within a floating yellow background (tooltip).

<div style="text-align: center;">Centered text</div>

In this other example, your text will look like this:

Centered text

Most elements also take the language-related attributes lang and dir.

Common attributes

Usually, HTML elements can take any of several most common standard attributes (See the complete list):

  • The id attribute provides a document-wide unique identifier for an element.[7][8][9] This can be used as CSS selector to provide presentational properties, by browsers to focus attention on the specific element, or by scripts to alter the contents or presentation of an element. Appended to the URL of the page, the URL directly targets the specific element within the document, typically a sub-section of the page. For example, the ID "Attributes" in http://en.wikipedia.org/wiki/HTML#Attributes (to refer to the section "Attributes" in the "HTML" page).
  • The class attribute provides a way of classifying similar elements. Multiple class names can be added by separating them with spaces.[10][11] Semantically, for example, classes are used in microformats. Additionally authors of style sheets can construct selectors that match elements by class for styling purposes. For example, a HTML document might use the designation class="notation" to indicate that all elements with this class value are subordinate to the main text of the document. Such elements might be gathered together as footnotes on a page—instead of appearing in the place suggested by their position within the HTML source. The style sheet author might also define a rule with the .notation selector and define the property font-size: small;.
  • The style attribute provides a way of applying element-specific style rules. Multiple style declarations can be added by separating them with semicolons and an optional space, where each declaration includes a CSS property name and a value separated by a colon and an optional space (Example: style="color: red; text-align: center;").[12][13][14] The style attribute can be used on any HTML element (it will validate on any HTML element; however, it is not necessarily useful). It is considered better practice to add the style information to a style sheet, often accomplished with selectors that match the element class or ID. Sometimes, however, inline styles are favored where style sheets are considered too cumbersome for a simple and specific or ad hoc style specification.
  • The title attribute is used to attach subtextual explanation to an element. In most browsers this attribute is displayed as what is often referred to as a tooltip.

Varieties

HTML attributes are generally classified as required attributes, optional attributes, standard attributes, and event attributes:

  • Usually the required and optional attributes modify specific HTML elements
  • While the standard attributes can be applied to most HTML elements.[15]
  • Event attributes, added in HTML version 4, allow an element to specify scripts to be run under specific circumstances.[16]

Required and optional

Used by one element

Used by two elements

Used by multiple elements

Standard attributes

Standard attributes are also known as global attributes, and function with a large number of elements.[17] They include the basic standard attributes: these include accesskey, class, contenteditable, contextmenu, data, dir, hidden, id, lang, style, tabindex, title. There are also some experimental ones. Both xml:lang and xml:base have been deprecated. The multiple aria-* attributes improve accessibility.[17] The event handler attributes are listed later on.

Technically all standard attributes must be accepted by all elements, though they will not function with some elements.[18] The table below lists some common standard attributes, and some elements they can function with.

Element id class style title dir lang xml:lang accesskey tabindex
Шаблон:MDNHTMLRef id
Шаблон:MDNHTMLRef dir lang xml:lang
Шаблон:MDNHTMLRef dir lang xml:lang
Шаблон:MDNHTMLRef dir lang xml:lang
Шаблон:MDNHTMLRef dir lang xml:lang
Шаблон:MDNHTMLRef title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title
Шаблон:MDNHTMLRef id class style title
Шаблон:MDNHTMLRef id class style title
Шаблон:MDNHTMLRef id class style title
Шаблон:MDNHTMLRef id class style title
Шаблон:MDNHTMLRef id class style title dir lang
Шаблон:MDNHTMLRef id class style title dir lang
Шаблон:MDNHTMLRef id class style title dir lang
Шаблон:MDNHTMLRef id class style title dir lang
Шаблон:MDNHTMLRef id class style title dir lang
Шаблон:MDNHTMLRef id class style title dir lang
Шаблон:MDNHTMLRef id class style title dir lang
Шаблон:MDNHTMLRef id class style title dir lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef, Шаблон:MDNHTMLRef, Шаблон:MDNHTMLRef, Шаблон:MDNHTMLRef, Шаблон:MDNHTMLRef, Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang
Шаблон:MDNHTMLRef id class style title dir lang xml:lang accesskey
Шаблон:MDNHTMLRef id class style title dir lang xml:lang accesskey
Шаблон:MDNHTMLRef id class style title dir lang xml:lang tabindex
Шаблон:MDNHTMLRef id class style title dir lang xml:lang tabindex
Шаблон:MDNHTMLRef id class style title dir lang xml:lang accesskey tabindex
Шаблон:MDNHTMLRef id class style title dir lang xml:lang accesskey tabindex
Шаблон:MDNHTMLRef id class style title dir lang xml:lang accesskey tabindex
Шаблон:MDNHTMLRef id class style title dir lang xml:lang accesskey tabindex
Шаблон:MDNHTMLRef id class style title dir lang xml:lang accesskey tabindex

Event attributes

The standard attributes include the event handler attributes. They are all prefixed on-:[17] Шаблон:Columns-list

Event attributes, added in HTML version 4, allow an element to specify scripts to be run under specific circumstances. The table below lists some common event handler attributes, and some elements they can function with.

Element At At At At At At At At At At At At At At At At At
Шаблон:MDNHTMLRef onload onunload
Шаблон:MDNHTMLRef onload onunload onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef, Шаблон:MDNHTMLRef, Шаблон:MDNHTMLRef, Шаблон:MDNHTMLRef, Шаблон:MDNHTMLRef, Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onabort onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus onchange
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus onchange onselect
Шаблон:MDNHTMLRef onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus onchange onselect

See also

References

[19] [20]