| |||||||||
In computing, an HTML element (instance) in terms of SGML is the complete sequence of a start tag (with attributes and their values), any embedded HTML content, and the end tag. A special case is empty elements that don't have contents and end tags. Due to the constraints of the DTDs, various parts, including start and end tag, may be omitted in HTML, but not XHTML. In XHTML the minimized tag syntax for an empty element (abbreviated form of the combination of opening and closing tag) is e.g. <br />.
Informally, HTML elements or their attributes are often simply called "tags" (an example of synecdoche), though many prefer the term tag strictly in reference to the semantic structures delimiting the start and end of an element.
Most but not all HTML elements can be "nested": <p><em>You</em>rock!</p> has an em element nested inside a p element. This can become more complex, for example <h1>Children that <em>do <font color="red">not</font> clean up</em> their rooms</h1>. Nesting may be arbitrarily deep.
Tags must be closed in the reverse order that they've been opened. A so-called 'block-level' element cannot be nested inside an inline element.
<p><font face="Tahoma">Lucy kissed <em>Jimmy</p></font></em>
<p><font face="Tahoma">Lucy kissed <em>Jimmy</em></font></p>
<html>...</html>
<head>...</head>
<body>...</body>
<title>...</title>
<title>My <b>first</b> webpage</title> will render as "My <b>first</b> webpage", and not "My first webpage".
<meta>...</meta>
<meta http-equiv="foo">, used to specify commands which should be sent as HTTP headers.
<link>
<link rel="stylesheet" type="text/css" href="url ">
<base> (XHTML: <base />)
<style>...</style>
/*<![CDATA[*/ @import "url "; @import "url "; /*]]>*/
All body tags are block-level elements, and cannot be contained within an inline element.
<h1></h1> through <h6></h6>
h1 for the highest-level heading (for example the document title), h2 for a lower-level heading (a major section), h3 for a level below that (for example a subsection), etc. The lowest level heading is h6. Most web browsers will show h1 as large text in a different font, and h6 as small boldfaced text, but this can be overridden with CSS. The heading elements are not intended merely for creating large or bold text.
<p>...</p>
<blockquote>...</blockquote>
cite attribute may give the source, and must be a fully qualified URL.
<pre>...</pre>
{white-space: pre}
<address>...<address>
<dl>...</dl></code>
<dt>...</dt>
<dd>...</dd>
<ol>...</ol>; <ul>...</ul>
ol, the type attribute can be used to specify the kind of ordering, but CSS gives more control: {list-style-type: foo}. The default is Arabic numbering. For ul, CSS can be used to specify the list marker: {list-style-type: foo}. The default marker is a disc.
<li>...</li>
<dir>...</dir> (deprecated)
<ul>.
<menu>...</menu> (deprecated)
<ul> list, but badly supported. Deprecated in favor of <ul>.
<table>...</table>
<tr>...</tr>
<th>...</th>
<td>...</td>
<colgroup>...</colgroup>
<col> (<col /> in XHTML)
<caption>...</caption>
<thead>...</thead>
<tbody>...</tbody>
<tfoot>...</tfoot>
<thead>, this section may be repeated by the user agent if the table is split across pages (in printing or other paged media)
HTML can only specify the form appearance; processing of the user's input must be done with a server-side script.
<form>...</form>
<select name="foo">...</select>
<option>...</option>
<input type="checkbox">
<input type="radio">
<input type="submit" value="NAME">
<input type="image" border=0 name="NAME" src="name.gif">
<input type="reset">
<input type="text">
<textarea>...</textarea>
cols and rows attributes. Text in between the tags appears in the text area when the page is loaded.
<span>...</span>
<div>...</div>
<center>...</center> (deprecated)
div with centering defined using CSS.
<hr> (<hr /> in XHTML)
<object>...</object>
type attribute. This may be any MIME Type the webbrowser understands, such as an embedded page (see <iframe>), a plug-in such as Flash, or a soundfile.
<param> (<param /> in XHTML)
object element, and sets parameters for the object, for example its width, height, or the URL of the content.
<embed>...</embed> (unofficial)
type attribute. Used for embedding Flash files, soundfiles etc. Not official; <object> is preferred.
<noembed>...</noembed> (unofficial)
<applet>...</applet> (unofficial)
<object> is preferred.
Most elements intended for altering the meaning of text within its normal flow are inline elements, and can be nested in other inline elements, or in block-level elements. The following are all inline elements.
<em>...</em>; <strong>, </strong>
<q>...</q>
cite attribute gives the source, and must be a fully qualified URL.
<code>...</code>
A code snippet. Conventionally rendering in a monospace font.
<del>...</del>
Deleted text. Typically rendered as a strikethrough.
<ins>...</ins>
Inserted text. Often used to markup replacement text for <del>'d text. Typically rendered underlined.
<dfn>...</dfn>; <samp>...</samp>; <kbd>...</kbd>; <var>...</var>
Definition, Sample Text, Keyboard Input, Variable: these are similar to <code>, but carry more specific meaning.
All presentational tags are deprecated in favor of Cascading Style Sheets (CSS). Both are shown below, although CSS is recommended by many web authorities.
<font>...</font>
size attribute from 1 to 7. Can also be used to set the text color using the color attribute, and to change the font used by the </code>face</code> attribute. Preferred usage is through CSS:
<font size="N"> corresponds to {font-size: Ypx} (there is no set mapping of N to Y values)
<font color="foo"> corresponds to {color: foo}
<font face="foobar"> corresponds to {font-family: foobar}
<b>...</b>
{font-weight: bold}
<i>...</i>
{font-style: italic}
<tt>...</tt>
{font-family: monospace}
<s>, </s>; <strike>, </strike>
{text-decoration: line-through}
<big>...</big>; <small>...</small>
{font-size: foo}
<sub>...</sub>; <sup>...</sup>
{vertical-align: sub} or {vertical-align: super}
<a>...</a>
href attribute set to a URL; additionally the attribute title may be set to a hover box text, some informative text about the link:
<a href="URL" title="hover box text">link label</a>
name attribute set, which preceded by a number sign '#' acts as a link target. Any element can be made into an anchor by using the id attribute, so using <a name="foo"> is not necessary.
<img...> (<img... /> in XHTML)
src attribute, the required alt provides alternative text in case the image cannot be displayed. Alt is intended as alternative text, although many browsers render it as a tooltip; the title attribute is intended for specifying tooltip text. See #links and anchors above.
Example:
<img src="http://en.BambooWeb.org/upload/b/bc/Wiki.png" title="example of an image" alt="BambooWeb logo">
gives the image with the same tooltip (hover box), but not with the link, while
<a href="http://en.BambooWeb.org/wiki/Image:Wiki.png" title="BambooWeb logo"><img src="http://en.BambooWeb.org/upload/b/bc/Wiki.png" alt= "BambooWeb logo" /></a>
also produces the link. Note that the name of the link target in this example is somewhat confusing: it is not an image but a webpage.
The example demonstrates that the image becomes a link, if the element "img" is put at the position of a link label, see #links and anchors above.
<br> (<br /> in XHTML)
<map>...</map>
<area> (<area /> in XHTML)
<blink>...</blink> (unofficial)
{text-decoration: blink}
<marquee>...</marquee> (unofficial)
<!--...-->
</html>. Its contents and any tags inside it should not be rendered and will remain invisible. Don't forget to close your comments, or a large part of your page may disappear. For historic reasons (compatibility with some pre-1995 browsers) SGML comments are sometimes used inside <style> or <script> tags, but this is not necessary and may in fact cause undesired effects.
An HTML document may contain a header and a body or a header and a frameset, but not both. For frames the Frames DTD must be used.
<frameset>...</frameset>
Delimit the frameset. The frames layout is giving by comma separated lists in the rows and cols attributes.
<frame>...</frame>
src attribute appears inside.
<noframes>...</noframes>
<body> element with children what will appear in web browsers that don't support frames.
See also Framing#Websites.