Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

HTML attribute

From Wikipedia, the free encyclopedia
Special words used inside the opening tag to control the element's behaviour

Hypertext markup language attributes are special words used to adjust the behavior or display of anHTML element. An attribute either modifies the default functionality of an element type or provides functionality to certain element types unable to function correctly without them. InHTML syntax, an attribute is added to anHTML 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.

Doctype HTML is a declaration that tells the browser what version of HTML the document is written in.

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

Description

[edit]

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

<elementattribute="value">elementcontent</element>

Whereelement names the HTML element type, andattribute is the name of the attribute, set to the providedvalue. The value may be enclosed in single or double quotes, although values consisting of certain characters can be left unquoted in HTML (but notXHTML).[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 theismap attribute for theimg element[6]).

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

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

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

<divstyle="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 attributeslang anddir.

Common attributes

[edit]

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

  • Theid attribute provides a document-wide unique identifier for an element.[7][8][9] This can be used asCSS 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" inhttp://en.wikipedia.org/wiki/HTML#Attributes (to refer to the section "Attributes" in the "HTML" page).
  • Theclass 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 inmicroformats. Additionally authors of style sheets can constructselectors that match elements by class for styling purposes. For example, a HTML document might use the designationclass="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 propertyfont-size: small;.
  • Thestyle attribute provides a way of applying element-specific style rules. Multiplestyle 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] Thestyle 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 astyle 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.
  • Thetitle attribute is used to attach subtextual explanation to an element. In most browsers this attribute is displayed as what is often referred to as atooltip.

Html solutions

[edit]

HTML attributes are generally classified asrequired attributes,optional attributes,standard attributes, andevent 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 specifyscripts to be run under specific circumstances.[16]Scripts are what you can type in html solutions.Html Scripts are for what inmates know for.
  • Html Scripts are what you can remember
  • Sometimes html is understandable for sources

Required and optional

[edit]

Used by two elements

[edit]

Used by multiple elements

[edit]

Standard attributes

[edit]

Standard attributes are also known asglobal attributes, and function with a large number of elements.[17] They include the basic standard attributes: these includeaccesskey, class, contenteditable, contextmenu, data, dir, hidden, id, lang, style, tabindex, title. There are also some experimental ones. Bothxml:lang andxml:base have been deprecated. The multiplearia-* attributes improve accessibility.[17] Theevent 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.

Elementidclassstyletitledirlangxml:langaccesskeytabindex
<param>id
<head>dirlangxml:lang
<html>dirlangxml:lang
<meta>dirlangxml:lang
<title>dirlangxml:lang
<style>titledirlangxml:lang
<applet>idclassstyletitle
<br>idclassstyletitle
<frame>idclassstyletitle
<frameset>idclassstyletitle
<iframe>idclassstyletitle
<basefont>idclassstyletitledirlang
<center>idclassstyletitledirlang
<dir>idclassstyletitledirlang
<font>idclassstyletitledirlang
<menu>idclassstyletitledirlang
<s>idclassstyletitledirlang
<strike>idclassstyletitledirlang
<u>idclassstyletitledirlang
<abbr>idclassstyletitledirlangxml:lang
<acronym>idclassstyletitledirlangxml:lang
<address>idclassstyletitledirlangxml:lang
<b>idclassstyletitledirlangxml:lang
<big>idclassstyletitledirlangxml:lang
<blockquote>idclassstyletitledirlangxml:lang
<body>idclassstyletitledirlangxml:lang
<caption>idclassstyletitledirlangxml:lang
<cite>idclassstyletitledirlangxml:lang
<code>idclassstyletitledirlangxml:lang
<col>idclassstyletitledirlangxml:lang
<colgroup>idclassstyletitledirlangxml:lang
<dd>idclassstyletitledirlangxml:lang
<del>idclassstyletitledirlangxml:lang
<dfn>idclassstyletitledirlangxml:lang
<div>idclassstyletitledirlangxml:lang
<dl>idclassstyletitledirlangxml:lang
<dt>idclassstyletitledirlangxml:lang
<em>idclassstyletitledirlangxml:lang
<fieldset>idclassstyletitledirlangxml:lang
<form>idclassstyletitledirlangxml:lang
<hr>idclassstyletitledirlangxml:lang
<h1>,<h2>,<h3>,<h4>,<h5>,<h6>idclassstyletitledirlangxml:lang
<i>idclassstyletitledirlangxml:lang
<img>idclassstyletitledirlangxml:lang
<ins>idclassstyletitledirlangxml:lang
<kbd>idclassstyletitledirlangxml:lang
<li>idclassstyletitledirlangxml:lang
<link>idclassstyletitledirlangxml:lang
<map>idclassstyletitledirlangxml:lang
<noframes>idclassstyletitledirlangxml:lang
<noscript>idclassstyletitledirlangxml:lang
<ol>idclassstyletitledirlangxml:lang
<optgroup>idclassstyletitledirlangxml:lang
<option>idclassstyletitledirlangxml:lang
<p>idclassstyletitledirlangxml:lang
<pre>idclassstyletitledirlangxml:lang
<q>idclassstyletitledirlangxml:lang
<samp>idclassstyletitledirlangxml:lang
<small>idclassstyletitledirlangxml:lang
<span>idclassstyletitledirlangxml:lang
<strong>idclassstyletitledirlangxml:lang
<sub>idclassstyletitledirlangxml:lang
<sup>idclassstyletitledirlangxml:lang
<table>idclassstyletitledirlangxml:lang
<tbody>idclassstyletitledirlangxml:lang
<td>idclassstyletitledirlangxml:lang
<tfoot>idclassstyletitledirlangxml:lang
<th>idclassstyletitledirlangxml:lang
<thead>idclassstyletitledirlangxml:lang
<tr>idclassstyletitledirlangxml:lang
<tt>idclassstyletitledirlangxml:lang
<ul>idclassstyletitledirlangxml:lang
<var>idclassstyletitledirlangxml:lang
<label>idclassstyletitledirlangxml:langaccesskey
<legend>idclassstyletitledirlangxml:langaccesskey
<object>idclassstyletitledirlangxml:langtabindex
<select>idclassstyletitledirlangxml:langtabindex
<a>idclassstyletitledirlangxml:langaccesskeytabindex
<area>idclassstyletitledirlangxml:langaccesskeytabindex
<button>idclassstyletitledirlangxml:langaccesskeytabindex
<input>idclassstyletitledirlangxml:langaccesskeytabindex
<textarea>idclassstyletitledirlangxml:langaccesskeytabindex

Event attributes

[edit]

The standard attributes include theevent handler attributes. They are all prefixed on-:[17]

  • onabort
  • onautocomplete
  • onautocompleteerror
  • onblur
  • oncancel
  • oncanplay
  • oncanplaythrough
  • onchange
  • onclick
  • onclose
  • oncontextmenu
  • oncuechange
  • ondblclick
  • ondrag
  • ondragend
  • ondragenter
  • ondragexit
  • ondragleave
  • ondragover
  • ondragstart
  • ondrop
  • ondurationchange
  • onemptied
  • onended
  • onerror
  • onfocus
  • oninput
  • oninvalid
  • onkeydown
  • onkeypress
  • onkeyup
  • onload
  • onloadeddata
  • onloadedmetadata
  • onloadstart
  • onmousedown
  • onmouseenter
  • onmouseleave
  • onmousemove
  • onmouseout
  • onmouseover
  • onmouseup
  • onmousewheel
  • onpause
  • onplay
  • onplaying
  • onprogress
  • onratechange
  • onreset
  • onresize
  • onscroll
  • onseeked
  • onseeking
  • onselect
  • onshow
  • onsort
  • onstalled
  • onsubmit
  • onsuspend
  • ontimeupdate
  • ontoggle
  • onvolumechange
  • onwaiting

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
onload
onunload
onabort
onclick
ondblclick
onmousedown
onmousemove
onmouseout
onmouseover
onmouseup
onkeydown
onkeypress
onkeyup
onblur
onfocus
onchange
onselect
<frameset>onloadonunload
<body>onloadonunloadonclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<abbr>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<acronym>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<address>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<b>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<big>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<blockquote>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<caption>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<center>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<cite>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<code>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<col>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<colgroup>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<dd>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<del>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<dfn>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<dir>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<div>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<dl>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<dt>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<em>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<fieldset>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<h1>,<h2>,<h3>,<h4>,<h5>,<h6>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<hr>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<i>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<ins>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<kbd>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<legend>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<li>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<link>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<map>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<menu>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<noframes>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<noscript>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<object>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<ol>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<optgroup>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<option>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<p>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<pre>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<q>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<s>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<samp>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<small>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<span>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<strike>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<strong>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<sub>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<sup>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<table>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<tbody>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<td>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<tfoot>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<th>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<thead>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<tr>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<tt>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<u>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<ul>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<var>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<img>onabortonclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyup
<a>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyuponbluronfocus
<area>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyuponbluronfocus
<button>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyuponbluronfocus
<form>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyuponbluronfocus
<label>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyuponbluronfocus
<select>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyuponbluronfocusonchange
<input>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyuponbluronfocusonchangeonselect
<textarea>onclickondblclickonmousedownonmousemoveonmouseoutonmouseoveronmouseuponkeydownonkeypressonkeyuponbluronfocusonchangeonselect

See also

[edit]

References

[edit]
  1. ^"Index of the HTML 4 Attributes". W3C. Retrieved13 February 2015.
  2. ^"On SGML and HTML". World Wide Web Consortium. RetrievedNovember 16, 2008.
  3. ^"XHTML 1.0 – Differences with HTML 4". World Wide Web Consortium. RetrievedNovember 16, 2008.
  4. ^Korpela, Jukka (July 6, 1998)."Why attribute values should always be quoted in HTML". Cs.tut.fi. RetrievedNovember 16, 2008.
  5. ^"Tags used in HTML". World Wide Web Consortium. November 3, 1992. RetrievedNovember 16, 2008.
  6. ^"Objects, Images, and Applets in HTML documents". World Wide Web Consortium. December 24, 1999. RetrievedNovember 16, 2008.
  7. ^However, multiple identifiers may apply to the same element; in particular an element may be inside another element, each having an identifier.
  8. ^"HTML id".W3Schools.Archived from the original on Apr 27, 2020. Retrieved2020-04-27.
  9. ^"HTML Global id Attribute".W3Schools. Retrieved2020-04-27.
  10. ^"HTML Classes".W3Schools. Retrieved2020-04-27.
  11. ^"HTML Global class Attribute".W3Schools. Retrieved2020-04-27.
  12. ^"HTML Styles".W3Schools. Retrieved2023-05-12.
  13. ^"HTML Global style Attribute".W3Schools. Retrieved2023-05-12.
  14. ^"CSS Syntax".W3Schools. Retrieved2023-05-12.
  15. ^"HTML Global Attributes". W3Schools.
  16. ^"HTML Event Attributes". W3Schools.
  17. ^abc"Global attributes – HTML (HyperText Markup Language)".MDN Web Docs. Retrieved2015-02-12.
  18. ^"HTML reference – HTML (HyperText Markup Language)".MDN Web Docs. Retrieved13 February 2015.
Retrieved from "https://en.wikipedia.org/w/index.php?title=HTML_attribute&oldid=1338530237"
Category:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp