HTML attribute

Last updated • 12 min readFrom Wikipedia, The Free Encyclopedia

HTML attributes are special words used inside the opening tag to control the element's behaviour. It is a piece of markup language used to adjust the behavior or display of an HTML element.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 .

Contents

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. [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:

<elementattribute="value">elementcontent</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:

<abbrid="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).

<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 attributes lang and dir.

Common attributes

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

Varieties

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

Required and optional

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.

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

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

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.

ElementAtAtAtAtAtAtAtAtAtAtAtAtAtAtAtAtAt
<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

Related Research Articles

A document type definition (DTD) is a specification file that contains set of markup declarations that define a document type for an SGML-family markup language. The DTD specification file can be used to validate documents.

<span class="mw-page-title-main">HTML</span> HyperText Markup Language

Hypertext Markup Language (HTML) is the standard markup language for documents designed to be displayed in a web browser. It defines the content and structure of web content. It is often assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaScript, a programming language.

<span class="mw-page-title-main">Markup language</span> Modern system for annotating a document

A markuplanguage is a text-encoding system which specifies the structure and formatting of a document and potentially the relationships among its parts. Markup can control the display of a document or enrich its content to facilitate automated processing.

Meta elements are tags used in HTML and XHTML documents to provide structured metadata about a Web page. They are part of a web page's head section. Multiple Meta elements with different attributes can be used on the same page. Meta elements can be used to specify page description, keywords and any other metadata not provided through the other head elements and attributes.

An HTML element is a type of HTML document component, one of several types of HTML nodes. The first used version of HTML was written by Tim Berners-Lee in 1993 and there have since been many versions of HTML. The current de facto standard is governed by the industry group WHATWG and is known as the HTML Living Standard.

Vector Markup Language (VML) is an obsolete XML-based file format for two-dimensional vector graphics. It was specified in Part 4 of the Office Open XML standards ISO/IEC 29500 and ECMA-376. According to the specification, VML is a deprecated format included in Office Open XML for legacy reasons only.

In web development, "tag soup" is a pejorative for HTML written for a web page that is syntactically or structurally incorrect. Web browsers have historically treated structural or syntax errors in HTML leniently, so there has been little pressure for web developers to follow published standards. Therefore there is a need for all browser implementations to provide mechanisms to cope with the appearance of "tag soup", accepting and correcting for invalid syntax and structure where possible.

A query string is a part of a uniform resource locator (URL) that assigns values to specified parameters. A query string commonly includes fields added to a base URL by a Web browser or other client application, for example as part of an HTML document, choosing the appearance of a page, or jumping to positions in multimedia content.

A lightweight markup language (LML), also termed a simple or humane markup language, is a markup language with simple, unobtrusive syntax. It is designed to be easy to write using any generic text editor and easy to read in its raw form. Lightweight markup languages are used in applications where it may be necessary to read the raw document as well as the final rendered output.

A framekiller is a technique used by websites and web applications to prevent their web pages from being displayed within a frame. A frame is a subdivision of a Web browser window and can act like a smaller window. A framekiller is usually used to prevent a website from being loaded from within a frameset without permission or as an attack, as with clickjacking.

<span class="mw-page-title-main">Online rich-text editor</span> Online interface for editing rich text

An online rich-text editor is the interface for editing rich text within web browsers, which presents the user with a "what-you-see-is-what-you-get" (WYSIWYG) editing area. The aim is to reduce the effort for users trying to express their formatting directly as valid HTML markup.

In HTML, the standard markup language for documents designed to be displayed in a web browser, <div> and <span> tags are elements used to define parts of a document, so that they are identifiable when a unique classification is necessary. Where other HTML elements such as <p> (paragraph), <em> (emphasis), and so on, accurately represent the semantics of the content, the additional use of <span> and <div> tags leads to better accessibility for readers and easier maintainability for authors. Where no existing HTML element is applicable, <span> and <div> can valuably represent parts of a document so that HTML attributes such as class, id, lang, or dir can be applied.

In HTML and XHTML, the blockquote element defines "a section [within a document] that is quoted from another source". The syntax is

A webform, web form or HTML form on a web page allows a user to enter data that is sent to a server for processing. Forms can resemble paper or database forms because web users fill out the forms using checkboxes, radio buttons, or text fields. For example, forms can be used to enter shipping or credit card data to order a product, or can be used to retrieve search results from a search engine.

<span class="mw-page-title-main">Attribute (computing)</span> Metadata which defines a property

In computing, an attribute is a specification that defines a property of an object, element, or file. It may also refer to or set the specific value for a given instance of such. For clarity, attributes should more correctly be considered metadata. An attribute is frequently and generally a property of a property. However, in actual usage, the term attribute can and is often treated as equivalent to a property depending on the technology being discussed. An attribute of an object usually consists of a name and a value. For an element these can be a type and class name, while for a file these can be a name and an extension, respectively.

Lazy loading is a technique used in computer programming, especially web design and web development, to defer initialization of an object until it is needed. It can contribute to efficiency in the program's operation if properly and appropriately used. This makes it ideal in use cases where network content is accessed and initialization times are to be kept at a minimum, such as in the case of web pages. For example, deferring loading of images on a web page until they are needed for viewing can make the initial display of the web page faster. The opposite of lazy loading is eager loading.

Extensible HyperText Markup Language (XHTML) is part of the family of XML markup languages which mirrors or extends versions of the widely used HyperText Markup Language (HTML), the language in which Web pages are formulated.

<span class="mw-page-title-main">CSS</span> Style sheet language

Cascading Style Sheets (CSS) is a style sheet language used for specifying the presentation and styling of a document written in a markup language such as HTML or XML. CSS is a cornerstone technology of the World Wide Web, alongside HTML and JavaScript.

XFrames was an XML format draft for embedding HTML pages into one page which handles the layout without the problems of HTML Frames. This technique has been especially popular for navigation bars. While HTML Frames are still supported for legacy websites, today websites combine the page on the server instead.

Thymeleaf is a Java XML/XHTML/HTML5 template engine that can work both in web (servlet-based) and non-web environments. It is better suited for serving XHTML/HTML5 at the view layer of MVC-based web applications, but it can process any XML file even in offline environments. It provides full Spring Framework integration.

References

  1. "Index of the HTML 4 Attributes". W3C. Retrieved 13 February 2015.
  2. "On SGML and HTML". World Wide Web Consortium. Retrieved November 16, 2008.
  3. "XHTML 1.0 – Differences with HTML 4". World Wide Web Consortium. Retrieved November 16, 2008.
  4. Korpela, Jukka (July 6, 1998). "Why attribute values should always be quoted in HTML". Cs.tut.fi. Retrieved November 16, 2008.
  5. "Tags used in HTML". World Wide Web Consortium. November 3, 1992. Retrieved November 16, 2008.
  6. "Objects, Images, and Applets in HTML documents". World Wide Web Consortium. December 24, 1999. Retrieved November 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. Retrieved 2020-04-27.
  9. "HTML Global id Attribute". W3Schools. Retrieved 2020-04-27.
  10. "HTML Classes". W3Schools. Retrieved 2020-04-27.
  11. "HTML Global class Attribute". W3Schools. Retrieved 2020-04-27.
  12. "HTML Styles". W3Schools. Retrieved 2023-05-12.
  13. "HTML Global style Attribute". W3Schools. Retrieved 2023-05-12.
  14. "CSS Syntax". W3Schools. Retrieved 2023-05-12.
  15. "HTML Global Attributes". W3Schools.
  16. "HTML Event Attributes". W3Schools.
  17. 1 2 3 "Global attributes – HTML (HyperText Markup Language)". MDN Web Docs. Retrieved 2015-02-12.
  18. "HTML reference – HTML (HyperText Markup Language)". MDN Web Docs. Retrieved 13 February 2015.