HTML attributes are special words used to adjust the behavior or display of an HTML 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. In HTML syntax, an attribute is added to an 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.
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 attribute name is used by several element types, but has slightly different functions in each.
<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).
Centered text</div>"}}'><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.
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. 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. 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;"). 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.
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.
- Event attributes, added in HTML version 4, allow an element to specify scripts to be run under specific circumstances.
Required and optional
edit
- <area> or a <link> within it. Values: default, rect, circle, poly.
<a>, <link> uses a set of terms (alternate, appendix, bookmark, chapter, contents, copyright, glossary, help, home, index, next, prev, section, start, stylesheet, subsection).
rev — Nature of the currently displayed page (relative to the linked document). Varies for <applet> and <object>)
codebase — base URL (<basefont> and <font>)
face — font family (deprecated) (<col> and <colgroup>)
deletion or <input>:
<frameset> or <textarea> (some variation)
<img> -or- URL of an image-map to use with <textarea>:
- readonly — specifies read-only text for <link> and <style>. Values: all, aural, braille, handheld, print, projection, screen, tty, TV.
<optgroup> or <th>:
- abbr — abbreviated version of a table cell or header.
- nowrap — (deprecated) prevents wrapping of a table cell or header as a logical header for other cells. Values: col, colgroup, row, rowgroup.
Used by multiple elements
edit
- align — <colgroup>, <td>, <thead>
- align also deprecated in <h1> to <iframe>, <legend>, <applet>, <input>
- bgcolor — <td>, <img>, <char>, <td>, <thead>, <colgroup>, <tfoot>, <tr>
- charset — <script>
- cite — <ins>, <menu>, <button>, <option>, <applet>, <object> . Also deprecated in <a>, <link>
- hspace — <img>
- longdesc — <img>
- name — <button>, <iframe>, <meta>, <select>, <font>, <select>
- src — <img>, <a>, <form>, <input>, <object>, <script>, <col>, <td>, <thead>, <input>, <param>
- vspace — <object>
- width — <colgroup>, <img>, <table>, <param>
| <head>
| |
|
|
|
|
|
|
|
| |
<title>
| |
|
|
|
|
|
|
|
| |
|
|
|
| |
|
|
|
|
|
|
| |
|
|
|
|
|
|
| |
|
|
|
|
|
|
| |
|
|
|
|
|
|
| |
|
|
|
|
|
|
| |
|
|
<dir>
| |
|
|
|
|
|
| |
|
|
<s>
| |
|
|
|
|
|
| |
|
|
<abbr>
| |
|
<acronym>
| |
|
<address>
| |
|
<b>
| |
|
<big>
| |
|
<blockquote>
| |
|
<body>
| |
|
<caption>
| |
|
<cite>
| |
|
<code>
| |
|
<col>
| |
|
<colgroup>
| |
|
<dd>
| |
|
<del>
| |
|
<dfn>
| |
|
<div>
| |
|
<dl>
| |
|
<dt>
| |
|
<em>
| |
|
<fieldset>
| |
|
<form>
| |
|
<hr>
| |
|
<h1>, <h4>, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
<object>
| |
|
|
|
|
|
| |
|
|
|
|
<button>
| |
|
|
|
| |
|
|
|
|
onabort
| onmousedown |
onmouseover |
onkeypress |
onfocus |
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2>, <h5>, |
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
<a>
| |
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
<form>
| |
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
- ↑ "Index of the HTML 4 Attributes". W3C. Retrieved 13 February 2015.
- ↑ Korpela, Jukka (July 6, 1998). "Why attribute values should always be quoted in HTML". Cs.tut.fi. Retrieved November 16, 2008.
- ↑ "HTML id". W3Schools. Archived from the original on Apr 27, 2020. Retrieved 2020-04-27.
- ↑ "HTML Global class Attribute". W3Schools. Retrieved 2020-04-27.
- ↑ "CSS Syntax". W3Schools. Retrieved 2023-05-12.
- ↑ "Global attributes – HTML (HyperText Markup Language)". MDN Web Docs. Retrieved 2015-02-12.
- ↑
|