HTML markup consists of several key components, including those called tags (and their attributes), character-based data types, character references and entity references. HTML tags most commonly come in pairs like <h1>
and </h1>
, although some represent empty elements and so are unpaired, for example <img>
. The first tag in such a pair is the start tag, and the second is the end tag (they are also called opening tags and closing tags).
Another important component is the HTML document type declaration, which triggers standards moderendering.
HTML documents imply a structure of nested HTML elements. These are indicated in the document by HTML tags, enclosed in angle brackets thus: <p>
.
In the simple, general case, the extent of an element is indicated by a pair of tags: a "start tag" <p>
and "end tag" <p>
. The text content of the element, if any, is placed between these tags.
Tags may also enclose further tag markup between the start and end, including a mixture of tags and text. This indicates further (nested) elements, as children of the parent element.
The start tag may also include the element's attributes within the tag. These indicate other information, such as identifiers for sections within the document, identifiers used to bind style information to the presentation of the document, and for some tags such as the <img>
used to embed images, the reference to the image resource in the format like this: <img src="example.com/example.jpg">
Some elements, such as the line break <br />
do not permit any embedded content, either text or further tags. These require only a single empty tag (akin to a start tag) and do not use an end tag.
There are several types of markup elements used in HTML:
-
Structural markup indicates the purpose of text. For example,
<h2>Golf</h2>
establishes "Golf" as a second-level heading. Structural markup does not denote any specific rendering, but most web browsers have default styles for element formatting. Content may be further styled using Cascading Style Sheets (CSS). -
Presentational markup indicates the appearance of the text, regardless of its purpose. For example,
<b>boldface</b>
indicates that visual output devices should render "boldface" in bold text, but gives a little indication what devices that are unable to do this (such as aural devices that read the text aloud) should do. Most presentational markup elements have become deprecated under the HTML 4.0 specification in favor of using CSS for styling. -
Hypertext markup makes parts of a document into links to other documents. An anchor element creates a hyperlink in the document and its href attribute sets the link's target URL. For example, the HTML markup
<a href="https://en.wikipedia.org/"> Wikipedia </a>
, will render the word "Wikipedia" as a hyperlink. To render an image as a hyperlink, an img element is inserted as content into the a element.
Most of the attributes of an element are name-value pairs, separated by = and written within the start tag of an element after the element's name. 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). Leaving attribute values unquoted is considered unsafe. In contrast with name-value pair attributes, there are some attributes that affect the element simply by their presence in the start tag of the element, like the ismap attribute for the img element.
There are several common attributes that may appear in many elements :
-
The
id
attribute provides a document-wide unique identifier for an element. This is used to identify the element so that stylesheets can alter its presentational properties, and scripts may alter, animate or delete its contents or presentation. Appended to the URL of the page, it provides a globally unique identifier for the element, typically a sub-section of the page. For example, the ID "Attributes" in https://en.wikipedia.org/wiki/HTML#Attributes. -
The
class
attribute provides a way of classifying similar elements. This can be used for semantic or presentation purposes. Multiple class values may be specified; for example<class="notation important">;
puts the element into both the notation and the important classes. -
An author may use the
style
attribute to assign presentational properties to a particular element. It is considered better practice to use an element's id or class attributes to select the element from within a stylesheet, though sometimes this can be too cumbersome for a simple, specific, or ad hoc styling. -
The
title
attribute is used to attach a subtextual explanation to an element. In most browsers this attribute is displayed as a tooltip. - The
lang
attribute identifies the natural language of the element's contents, which may be different from that of the rest of the document. For example, in an English-language document:
As of version 4.0, HTML defines a set of 252 character entity references and a set of 1,114,050 numeric character references, both of which allow individual characters to be written via simple markup, rather than literally. A literal character and its markup counterpart are considered equivalent and are rendered identically.
The ability to "escape" characters in this way allows for the characters <
and &
(when written as < and &, respectively) to be interpreted as character data, rather than markup. For example, a literal <
normally indicates the start of a tag, and &
normally indicates the start of a character entity reference or numeric character reference; writing it as &
or &
or &
allows &
to be included in the content of an element or in the value of an attribute.
Escaping also allows for characters that are not easily typed, or that are not available in the document's character encoding, to be represented within the element and attribute content.
HTML defines several data types for element content, such as script data and stylesheet data, and a plethora of types for attribute values, including IDs, names, URIs, numbers, units of length, languages, media descriptors, colors, character encodings, dates and times, and so on. All of these data types are specializations of character data.
HTML documents are required to start with a Document Type Declaration (informally, a "doctype"). In browsers, the doctype helps to define the rendering mode—particularly whether to use quirks mode.
The original purpose of the doctype was to enable the parsing and validation of HTML documents by SGML tools based on the Document Type Definition (DTD). The DTD to which the DOCTYPE refers contains a machine-readable grammar specifying the permitted and prohibited content for a document conforming to such a DTD. Browsers, on the other hand, do not implement HTML as an application of SGML and as consequence do not read the DTD.
HTML5 does not define a DTD; therefore, in HTML5 the doctype declaration is simpler and shorter
This documentation has been taken from Wikipedia. To learn more head to the HTML Wikipedia article.