HTMLCSSJSCombined
HTMLCSSJSCombined
To access HTML, CSS or JavaScript examples please go to the webpage on www.nematrian.com that
covers the specific feature you are seeking help with. More detailed examples (such as how to draw
spinning3d shapes) are provided here.
Disclaimer: Whilst we have made efforts to check the accuracy of the material in these pages, you should
note that HTML, CSS and JavaScript are evolving languages. Information contained in this document may
therefore be inaccurate or out-of-date. You should not rely on the accuracy or fitness for purpose of any
material that you obtain from the Nematrian website (or from its associated web services). If you need
these results to be accurate or fit for purpose then you should seek independent corroboration of
whatever you extract from the Nematrian website.
Whilst using the site, users may be directed to the websites of other organisations, over which Nematrian
may have no control and for which it takes no responsibility. A copy of the current Nematrian Web
Services License Agreement can be viewed here.
1
HTML Tutorial
Introduction
[HTMLTutorialIntroduction]
Hypertext Markup Language (HTML) is one of the three main components of modern webpages, along
with Cascading Style Sheets (CSS) and JavaScript. HTML indicates to the browser what elements should be
included in the webpage (and in what order). CSS indicates how each element should be styled. JavaScript
provides a means for webpage authors to manipulate these elements programmatically and in response
to actions by the end user. Tutorials and reference material covering all three components are available
here.
In these pages, we describe HTML further. Text used within HTML, CSS or JavaScript files is generally
shown in courier new (i.e. a fixed space) font. The pages contain links to an extensive body of reference
material explaining HTML, CSS and JavaScript in detail. We also provide a wide range of examples, which
can help you understand better how HTML, CSS and JavaScript work. See below for further details on how
to access these examples.
The concept of a markup language is explained further here. A document written in a markup language
like HTML has parts that get rendered in the eventual output, but also parts that inform the rendering
software how to interpret the remaining text. ‘Rendering’ here refers to the process of transforming the
text document containing the HTML text into e.g. its visual representation on a screen.
The markup used by HTML includes tags, like <p>…</p>, to demarcate different HTML elements within
the same webpage. In this case the <p> tag opens the relevant element and the </p> closes it. <p>
elements are typically used to delimit paragraphs in HTML. HTML elements can be nested within other
elements. Most elements can also be qualified by a range of attributes. For example, if we want to make
the text within a <p> element appear red we can ascribe it a CSS style, along the lines of <p
style="color:red;">.
Over time HTML has been refined. At the time of writing the latest version is HTML 5. Some aspects of
earlier versions of HTML are no longer recognised in HTML 5 and some of these are noted where
relevant.
Tutorial contents:
2
document may therefore be inaccurate or out-of-date. You should not rely on the accuracy or fitness for
purpose of any material that you obtain from the Nematrian website (or from its associated web
services). If you need these results to be accurate or fit for purpose then you should seek independent
corroboration of whatever you extract from the Nematrian website. Whilst using the site, users may be
directed to the websites of other organisations, over which Nematrian may have no control and for which
it takes no responsibility. A copy of the current Nematrian Web Services License Agreement can be
viewed here.
As explained in HTML and other markup languages, there are various ‘dialects’ of HTML. This means that
some examples of HTML may be understood by some browsers but rejected by others. The following
text, when put into a text editor and saved with a .htm file extension, will usually successfully render a
web page that says “Hello World (using HTML)” if the file is viewed in Microsoft Edge. Note that HTML
largely ignores page breaks; if you want to include a page break in the text shown to the user then you
need to add a <br> element (or a <br /> element if you are using XHTML, which is a modern variant of
HTML that involves a cross between classic HTML and XML).
<html>
<body>
Hello World (using HTML)
</body>
</html>
However, strictly speaking an HTML document is supposed to start with a document type declaration,
along the lines of e.g. <!DOCTYPE html> and a header along the lines of e.g.
<head><title>Document title</title></head>. So, a better way to create the page shown
above is as follows. We’ve added a comment into the document, using HTML comment tags.
Comments are not displayed by the browser but can help to document the HTML source text.
<!DOCTYPE html>
<html>
<head>
<title>My Document</title>
</head>
<!-- Only the text in the body will appear in the browser -->
<body>
Hello World (Using HTML)
</body>
</html>
Often, the <html> element also includes a lang attribute, as this can be important for accessibility
applications (such as screen readers) and for search engines. With the lang attribute, the first two letters
specify the language. If the language comes in various dialects then two more letters specify the dialect,
e.g.:
3
<html lang="en-US">
HTML markup largely ignores carriage returns (i.e. line breaks) within marked up files. Instead, if you
want to insert a carriage return you need to insert a <br> tag.
By ‘largely ignores’ we mean that browsers do not render carriage returns as line breaks as such (except if
certain styles apply to the element within which they appear, see e.g. the default formatting of the <pre>
element). However, carriage returns do affect how HTML handles spaces at the end of the line and at the
start of the following line. Leading spaces (i.e. ones on a line before any non-space characters) are
typically ignored, as are trailing spaces (i.e. ones on a line after the last non-space character). However,
browsers typically insert a 'breaking space' at the end of each line, which often then shows up as a single
space. Multiple spaces one after the other are interpreted as a single space. To include more than one
space in such instances you need to include a ‘non-breaking space’ as a special character, see here.
Commenting
[HTMLTutorialCommenting]
It can be helpful to include comments in HTML documents that are not displayed but help readers of the
underlying markup text you to understand what the HTML is trying to do. Comments in HTML take the
form <!-- comment --> and ignore line breaks within the opening and closing tags of the comment
element.
4
works-->
Special characters
[HTMLTutorialSpecialCharacters]
The underlying markup of a webpage typically contains many more ampersand characters (i.e. &) than
appear in the rendered output. This is because the & character is part of the way in which HTML marks up
'special' characters, i.e. ones that would otherwise be understood by HTML to relate to markup. In HTML,
each special character is preceded by an ampersand, followed by the HTML markup name for that
character followed by a semicolon. Perhaps the most common special characters are:
Hyperlinks
[HTMLTutorialHyperlinks]
Many people associate web pages with hyperlinks, i.e. the ability to navigate from one page to another
page. In HTML, hyperlinks (also called ‘anchors’) typically have the following sort of structure:
<a href="Pages/AboutNematrian.pdf";>text</a>
The text is what the user sees, the value of href is where the link points to. Points to note include:
The ‘text’ material seen by the user can contain HTML, so can include e.g. images and formatted text
The href value used here, i.e. “Pages/AboutNematrian.pdf” means that the link points to a webpage (or
other resource) called “AboutNematrian.pdf” in the directory “Pages” (strictly speaking a subdirectory of
the directory in which the source webpage
resides, unless it e.g. starts with http:// or https:// or unless the document’s <base> element, if any,
defines a different base address to be used by relative uniform resource locators, i.e. ‘URLs’).
5
text
Groups of hyperlinks can be included in a <nav> element. For example, markup as follows:
<nav>
<a href="Introduction.aspx">Introduction</a> |
<a href="IntroductionSoftware.aspx">Software</a>
</nav>
Many other elements are also by default differentiated from the text around them or exist primarily to
facilitate this sort of differentiation. Examples include:
6
Header 1
Header 2
Header 3
Header 4
Header 5
<h1>, <h2>, <h3>,
<h4>, <h5>, <h6> HTML headings Header 6
7
Some HTML elements are no longer supported in HTML5. Although they often work in browsers you
should ideally use CSS instead. These include:
8
Browser feature detection
[HTMLTutorialFeatureDetection]
Hypertext Markup Language (HTML), Cascading Style Sheets (CSS) and JavaScript form the main elements
of modern webpages. However, different browsers do not always interpret these webpage components
in entirely consistent ways.
Nowadays, the trend is to use ‘feature detection’. In this approach, the developer includes elements or
other components in the webpage that identify if the browser and device being used to access the
webpage supports a specific feature. The output is then optimised bearing in mind whether the feature is
available.
Sometimes this type of functionality is explicitly built into HTML. For example, the media file formats
recognised by HTML <audio> and <video> elements vary by browser. These HTML elements specifically
allow developers to refer to more than one media source, depending on the format involved. The
browser being used can then select whichever source it recognises. If it doesn’t recognise any (or if it is
not new enough to recognise <audio> or <video> elements), fallback text will be displayed. The CSS
@media rule can also be used in a way that allows the developer to alter the style used by an element to
reflect the media in which the page is being viewed (e.g. the width or height of the device).
At other times, feature detection needs to be coded using JavaScript. The typical approach is to identify
whether a feature is supported by the browser and then to adjust output formatting accordingly.
However, it is not always easy to identify whether a specific feature is supported by the browser. Possible
methods include:
Use the hasFeature method to determine whether the JavaScript Document Object Model (DOM)
implementation supports the relevant feature
Search for DOM objects, properties or methods associated with the feature
9
Attempt to create an object that should have the feature and if creation is successful then test whether it
does support the feature
Unfortunately, the hasFeature method is not well supported by several browsers and its use is often not
recommended. The Nematrian website includes functions for many JavaScript features that can assist in
checking whether the feature is being supported by the browser being used at the time. See pages on
individual features for further details.
10
CSS Tutorial
Introduction
[CSSTutorialIntroduction]
Cascading Style Sheets (CSS) is one of the three main components of modern webpages, along with
Hypertext Markup Language (HTML) and JavaScript. HTML indicates to the browser what elements should
be included on the page (and in what order). CSS indicates how each should be styled.
JavaScript provides a means for webpage authors to manipulate these elements programmatically and in
response to actions by the end user. Tutorials and reference material covering all three components are
available here.
In these pages, we describe CSS further. Text used within HTML, CSS or JavaScript files is generally shown
in courier new (i.e. a fixed space) font. The pages contain links to an extensive body of reference material
explaining HTML, CSS and JavaScript in detail. We also provide a wide range of examples, which can help
you understand better how HTML, CSS and JavaScript work. See below for further details on how to
access these examples.
CSS instructions can be:
included within an individual HTML element (as part of the mark-up relating to that element), i.e. as ‘in-
line’ CSS
included in the HTML file where the relevant element(s) are located, but not directly within
the elements concerned, i.e. as ‘in-file’ CSS
included in external CSS files, i.e. as ‘external’ CSS, with a HTML <link> element used to indicate where
any such CSS files applicable to a given HTML file are located.
The style attributes of an HTML element can also be altered by JavaScript ‘on the fly’, e.g. after the page
has initially loaded or in response to specific user actions such as clicking a button.
CSS styles typically operate according to a hierarchy, with any JavaScript overrides taking precedence
over any CSS styles present when the page is initially loaded but otherwise in-line CSS taking precedence
over in-file CSS and in-file CSS taking precedence over external CSS (unless the
‘important’ characteristic is included in the style statement). In-file CSS is contained in a <style> element.
If there is more than one such element then later ones take precedence over earlier ones.
Older versions of HTML (e.g. HTML 4) require <style> elements to be in the <head> of the HTML file,
although most browsers currently seem to accept them even if they appear in the <body>. In theory, the
latest HTML version at the time of writing (HTML 5) has the concept of a ‘scoped’ attribute (e.g. <style
scoped>) which should allow you to apply different <style> elements to different parts of the webpage
(which could then legitimately appear in the <body> element), but not all browsers currently seem to
cater for this aspect of HTML 5.
External style sheets are referenced using a <link> element, which goes inside the <head> section. This
type of link element has a form such as:
11
In-file and external CSS are typically set out in the form of ‘rule-sets’. A rule set involves a selector and a
declaration block. The selector points to the type of HTML element to which the style applies, whilst the
declaration block contains one or more style declarations separated by semicolons. Each declaration
involves a CSS property name, followed by a colon, followed by the value assigned to the property.
For example, the style rule
has a selector which is h3 and a declaration block which is {color: blue; text-align: center;}. It tells the
browser that any <h3> element (to which the rule applies) should be centre- aligned and appear in blue.
As with HTML, line breaks and multiple spaces are ignored.
Other types of selectors are introduced here and covered in more detail here.
In-line CSS rule-sets involve the style attribute (and do not include a selector or the curly brackets /
braces included in in-file or external CSS), e.g. they involve setting the element’s style attribute along the
lines of: style = "color: red";.
Comments in CSS start with /* and end with */ and can span multiple lines.
Over time CSS has been refined. At the time of writing the latest version is CSS3. Features in CSS1 and
CSS2 can typically still be used in CSS3.
Tutorial content
Disclaimer: Whilst we have made efforts to check the accuracy of the material in these pages, you should
note that HTML, CSS and JavaScript are evolving languages. Information contained in this document may
therefore be inaccurate or out-of-date. You should not rely on the accuracy or fitness for purpose of any
material that you obtain from the Nematrian website (or from its associated web services). If you need
these results to be accurate or fit for purpose then you should seek independent corroboration of
whatever you extract from the Nematrian website.
Whilst using the site, users may be directed to the websites of other organisations, over which Nematrian
may have no control and for which it takes no responsibility. A copy of the current Nematrian Web
Services License Agreement can be viewed here.
Selectors
[CSSTutorialSelectors]
CSS is typically set out in the form of ‘rule-sets’, which involve a selector and a declaration block. Usually
CSS is applied to types of elements. For example, the style rule
12
h3 {color: blue; text-align: center;}
has a selector which is h3 and a declaration block which is {color: blue; text-align: center;}. It tells the
browser that any <h3> element (to which the rule applies) should be centre- aligned and appear in blue.
As with HTML, line breaks and multiple spaces are ignored.
However, within HTML you can also define classes of elements with common formatting styles using
the element’s class attribute. For example, the style rule
would indicate that any element with a class attribute equal to center should be centre-aligned and
appear in red.
You can also apply CSS to elements of a specific type and class. For example, the style rule
would indicate that <h3> elements that have their class attribute equal to center should be green.
In-file CSS can also be applied to individual elements, if the id attribute of the HTML element has been set
(the id attribute should be unique within any given page). If you want to use this type of CSS then precede
the id value by a hash (#) character.
would be applied to the HTML element with id equal to para1 (provided there is such an element) and it
would appear yellow (unless overridden by a later style rule).
You can also group together rules for elements with the same style definitions, separating each selector
with a comma. For example,
h1 {color: red;} h2 {color: red;} h3 {color: red;}
can be grouped together as follows to minimise code and make it easier to follow:
More general ways of identifying CSS selectors are set out here.
13
In CSS, if you are using values that have units, e.g. applying values that are to be interpreted as CSS
lengths (e.g. setting the size of an element’s left margin using e.g. margin-left: 20px) then you should not
include a space between the value (here 20) and the unit (here px) as otherwise the style may be ignored.
There are several ways of defining lengths in CSS. There are also specific conventions used when defining
CSS times, CSS angles and CSS colours.
If you have two or more style rules that would otherwise apply to a specific attribute of a specific element
then the hierarchy rules are that:
More specific rules override more general ones. Specificity is defined based on how many IDs, classes and
element names are involved as well as by whether there is an !important declaration.
When even these do not differentiate between styles then whichever one appears last is the one that is
applied.
For example, without the !important flag, <h3> elements using the following styles would appear green
(as the green style rule is after the red one), but with the !important flag it is the red one that applies in
this instance:
h3 {color: red !important} h3 {color: green}
Some CSS properties take several values. For example, many HTML elements are deemed to have 4 sides
(top, right, bottom and left) and there are conventions on how to define properties that encompass all
four sides simultaneously, see here.
More generally, some CSS properties are shorthand properties that set several other more granular
properties at the same time.
CSS has developed over the years and it is now possible to create relatively sophisticated animation
effects using the CSS @keyframes rule, without needing to implement these animations using JavaScript.
It is also possible to apply different styles depending on the device being used to render the material,
using the CSS @media rule. Material can be automatically added before or after HTML elements using
CSS ‘pseudo-properties’, such as the content pseudo-property.
Styling of hyperlinks
14
Link state Description
a:link Normal, unvisited link
a:visited Link that user has visited
a:hover Link when the user moves a mouse over it
a:active Link at the moment it is clicked
To make a table responsive (i.e. to display a horizontal scroll bar if the screen is too small to display in full)
you can add a container element with overflow-x:auto, e.g.:
15
JavaScript Tutorial
Introduction
[JavaScriptTutorialIntroduction]
JavaScript is one of the three main components of modern webpages, along with Hypertext Markup
Language (HTML) and Cascading Style Sheets (CSS). HTML indicates to the browser what elements should
be included on the page (and in what order). CSS indicates how each should be styled.
JavaScript provides a means for webpage authors to manipulate these elements programmatically and in
response to actions by the end user. Tutorials and reference material covering all three components are
available here.
In these pages, we describe JavaScript further. Text used within HTML, CSS or JavaScript files is generally
shown in courier new (i.e. a fixed space) font. The pages contain links to an extensive body of reference
material explaining HTML, CSS and JavaScript in detail. We also provide a wide range of examples, which
can help you understand better how HTML, CSS and JavaScript work. See below for further details on how
to access these examples.
JavaScript can be added to a webpage in one of three ways (somewhat akin to how CSS can be added to a
webpage):
By including it within an individual HTML event attribute. This typically involves only very small JavaScript
statements.
Within separate <script> elements in the HTML
In external script files (these involve including in the HTML a <script> element with its src attribute set to
the relevant script file name).
A simple example of JavaScript involves the use of the document.write method. For example, the
following HTML text would return a web page the first line of which says “Hello World (using HTML)”
followed by a line break and a second line saying “Hello World (using HTML)”. Script elements are
typically executed in the order in which they appear when the page is first loaded. In this case the script
cause the browser to add some more text to the web page.
<html>
<body>
Hello World (using HTML)<br>
<script>
<!--
document.write("<br>Hello World (using Javascript)")
//-->
</script>
</body>
</html>
More sophisticated approaches can alter individual HTML elements rather than merely adding to the end
of the document or can react to events such as the clicking of a button. For example, the following HTML
text returns a web page with two lines, the first being “Hello World (using HTML)” and the second line
being “and using JavaScript”.
<!DOCTYPE html>
16
<html>
<head></head>
<body>
Hello World (using HTML)<br>
<em id="Added"></em>
<script>
document.getElementById("Added").innerHTML="and using JavaScript"
// Adds text to the element with id="Added"
</script>
</body>
</html>
Note: we are here taking advantage of the execution of script commands when the page first loads. A
more complicated (but more general way) of achieving the same result would be to add an ‘event
listener’ that is triggered when the page loads and to have a function associated with this event listener
that alters (here adds) the text in the desired manner when the event happens. By attaching the function
to a different event, e.g. one triggered when the user clicks on an element then the a more responsive
webpage can be created.
JavaScript comments
When writing computer software, it often helps to add explanatory comments. In JavaScript, a single line
comment is indicated by “code // text” where the code is still executed, but the text is ignored by the
Browser.
Any text between “/*” and “*/” (not in quotes) including line breaks is also ignored, allowing authors to
create multi-line comments. These tend to be used for formal documentation, e.g. material at the start of
each function that describes what the function does.
Tutorial contents:
Disclaimer: Whilst we have made efforts to check the accuracy of the material in these pages, you should
note that HTML, CSS and JavaScript are evolving languages. Information contained in this document may
therefore be inaccurate or out-of-date. You should not rely on the accuracy or fitness for purpose of any
material that you obtain from the Nematrian website (or from its associated web services). If you need
these results to be accurate or fit for purpose then you should seek independent corroboration of
whatever you extract from the Nematrian website.
Whilst using the site, users may be directed to the websites of other organisations, over which
17
Nematrian may have no control and for which it takes no responsibility. A copy of the current Nematrian
Web Services License Agreement can be viewed here.
Variables
[JavaScriptTutorialVariables]
If you want to set a variable to a value when it is first defined then you generally use the assignment
operator within this definition, e.g.:
var x = 10;
Variables can also be objects and arrays (and for some string manipulation purposes, regular
expressions). In JavaScript, an array is a special type of object that is indexed along the lines of a[0], a[1]
…. Arrays can consist of other objects, including other arrays.
Several variables can be defined in the same statement, with each one separated by a comma, e.g.:
Variables that have not yet been defined a value have their value as undefined.
If you redefine a variable, it retains its previous value. For example, after the statements
var x = 10; var x;
Variables are manipulated using operators and functions. For example, numbers can be added together
using the addition operator or functions can be applied to them, e.g.:
var x = 0.1 + 0.2; function sinsquared(x) {
var a;
a = Math.pow(Math.sin(x),2); return a;
}
var y = sinsquared(0.3);
18
They can contain only letters, digits, underscores and dollar signs
They must typically begin with a letter (in some cases they can also begin with a $ or an _ character)
The names are case sensitive (i.e. a and A are different names)
They cannot be reserved words, such as those used in JavaScript statement construction)
An important concept in programming is the scope of a variable (or more precisely of its name). This is
the part of the code within which the relevant variable is accessible via its name. If code is segmented
into blocks then it is often desirable to use a similar variable name in different blocks but for the names to
then be associated with different variables depending on the block in question. The scope of a JavaScript
can be local or global. Variables defined inside functions are local to that function, whilst those defined
outside functions are global in scope. Local variables are deleted when the function completes, while
global variables remain available until the user closes the browser window or tab within which the page
has been loaded. This means that they are available to new pages loaded into the same browser window.
Function arguments work in the same manner as local variables inside a function.
String variables
var x = "Cat";
A string technically consists of a series (an ‘array’, except that a JavaScript array is a specific type of
variable) of characters, which is zero-indexed. So, if we assigned x the value of "Cat" then x[0] would be
"C", x[1] would be "a", etc.
Further details on the methods and properties supported by string variables are set out in JavaScript
Tutorial: Strings.
Regular expressions
Some string methods and properties involve ‘regular expressions’. These take the form:
/pattern/modifiers
e.g.:
var x = /nematrian/i;
Further details on the methods and properties supported by regular expressions variables are set out in
JavaScript Tutorial: Regular Expressions.
JavaScript has only one type of number (in contrast to, e.g. Visual Basic, which differentiates between e.g.
integers, floating point numbers and double precision numbers). Numbers can be written with or without
decimal points and/or with or without (scientific) exponents), e.g.
var x = 4.1; // With a decimal point var y = 4; // Without a decimal point
19
var p = 135e6 // Means 135000000 var q = 13.5e-3 // Means 0.0135
Further details on the methods and properties supported by numbers and by the Math object (which can
be used to carry out mathematical manipulations) are set out in JavaScript Tutorial: Number variables and
mathematical functions.
Dates
Date variables are objects and contain dates and times. They can be instantiated in 4 ways:
var d1 = new Date(); // An as yet undefined date var d2 = new Date(milliseconds); // See below
var d3 = new Date(dateString); // See below
var d4 = new Date(year, month, day, hours, minutes, seconds, milliseconds);
Here milliseconds refers to the number of milliseconds since 1 January 1970 00:00:00. A dateString is a
piece of text that the browser can recognise as representing a date.
Further details on the methods and properties supported by numbers and by the Math object (which can
be used to carry out mathematical manipulations) are set out in JavaScript Tutorial: Dates.
Booleans
Boolean variables take one of two values, true or false. They are instantiated by a statement such as:
var b = true;
You can use the Boolean() function to identify whether an expression is true or false, although it is
simpler just to use operators that return Boolean outputs, e.g. Boolean(2 > 1), (2 > 1) or even 2 > 1 all
return true.
Further details on the methods and properties supported by Boolean variables are shown in JavaScript
Tutorial: Booleans.
Arrays
Arrays contain multiple (indexed) values in a single variable. Array indices are zero-based, i.e. the first
element of the array has as its index 0, the second 1 etc. They are instantiated by statements such as:
It is worth noting that elements of arrays can themselves be arrays since technically an array is a specific
type of object.
Further details on the methods and properties supported by arrays (and some of the subtleties that arise
if you want to copy them) are set out in JavaScript Tutorial: Arrays.
Objects
20
JavaScript objects are containers that contain properties and methods. For example, a statement such as:
var person = {title:"Mr", surname:"Smith", age:30}
creates an object that has three properties, i.e. name-value, pairs that in this instance characterise (some
of the features of) a person.
Object properties can be accessed in two ways, either here e.g. person.title or person["title"] (both of
which in this instance would return a value of "Mr"). An array is a specific type of object with the property
names indexed from 0 up to the length of the array less 1 (and hence elements of arrays can themselves
be arrays or other sorts of objects).
Object methods are functions that can be applied to objects. They are technically also property-like in
nature, i.e. again come in name-value pairs, but with the ‘name’ being a function name (with
parameter definitions if necessary) and the ‘value’ being the JavaScript function script associated with
that function, see JavaScript Tutorial: Objects.
A special type of object is the Error object, which is used for error handling.
Statements
[JavaScriptTutorialStatements]
JavaScript statements identify instructions that are executed by the web browser. For example, the
following statement tells the browser to write “Hello World” inside an HTML statement with the id
attribute = "element":
document.getElementById("element").innerHTML = "Hello World"
The same result can be achieved using several separate statements, e.g.:
Statements are separated by semicolons and multiple statements are allowed on one line. JavaScript
ignores multiple spaces (except in strings, i.e. within quotation marks). A common good practice is to put
spaces around operators (e.g. =, + , …). Very long lines of code are also often frowned upon, and are
usually broken after an operator.
Statements can (and often are) grouped together in code blocks, inside curly brackets, i.e. { … }. A
particularly important example of the use of code blocks involves functions, which provide a means of
executing on demand one or more statements, e.g.:
function func() {
document.getElementById("element").innerHTML = "Hello";
}
21
Statements often start with a statement identifier. These are reserved words which cannot be used as
variable names or for other purposes. A list of statement reserved words recognised by JavaScript is
shown here. They include: break, continue, do, for, if, return, switch, throw, try, catch, var and while.
Most JavaScript programs contain many statements, which are executed one by one in the order in which
they are written except when statement flow control is adjusted using statements such as for, if or while.
Functions
[JavaScriptTutorialFunctions]
A JavaScript function is a block of JavaScript code that can be executed as a discrete unit. It involves a
function statement along the lines of e.g.:
function func() {
document.getElementById("element").innerHTML = "Hello";
}
Function definitions can include parameters (separated by a comma if more than one parameter),
e.g. the following (if passed a string variable) would allow any text to be inserted in the relevant
element’s innerHTML.
function func2(x) { document.getElementById("element").innerHTML = x;
}
Functions are much like procedures or subroutines in other programming languages. The code inside the
curly brackets executes when the function is invoked. This can happen when an event occurs, when the
function is called from JavaScript code or sometimes when it is self-invoked. If a function includes a
return statement then the function will stop executing and will return the value identified by the
function’s return statement. The function (technically, a special type of object) can be distinguished from
the act of invoking it. The () operator invokes the function, e.g. in the above func refers to the function
object, but func() will invoke the function itself.
The function parameters are the names listed in the function definition (i.e. the x in the definition of
func2). Function arguments are the values received by the function (i.e. assigned to the function
parameters) when it is invoked.
Function names can contain letters, digits, underscores and dollar signs (the same rules as apply to
variable naming applies to function naming). Wherever a variable can be used, a valid function call
evaluating to the same value can also be used.
Event handling
[JavaScriptTutorialEventHandling]
22
A responsive website needs to respond to users when the users act in specific ways, e.g. loading a page,
clicking on a button, moving a mouse around a document window etc. JavaScript, like many other
modern more sophisticated general-purpose programming languages, includes the concept of events.
These assign specific functions to specific events, with the functions being invoked if/when the event
occurs.
Event handling linked to individual elements, such as what happens when someone clicks on an element,
is often implemented by assigning a specific function to the event attribute of that element, see here.
Global events (not linked to specific HTML elements), such as those triggered by loading the page, are
typically implemented by using e.g. the document.addEventListener method, e.g.:
document.addEventListener('load', addtext());
The browser creates a DOM (i.e. a document object) for a page when the page is first loaded. This has a
tree structure, with the root element (or ‘node’) being the page’s <html> element. The root element then
has two sub-elements (or ‘nodes’), i.e. the <head> element and the <body> element.
The <head> element will in turn often include as one of its ‘child’ nodes a <title> element. The
<body> element contains the main body of the webpage and will typically contain many different
elements, some nested within others. JavaScript can change all the elements (including all their
attributes), can add new elements or remove existing ones, can react to all existing events and create
new ones.
Formally, the DOM is a W3C (World Wide Web Consortium) standard. It has the following aim, according
to W3C: “The W3C Document Object Model (DOM) is a platform and language-neutral interface that
allows programs and scripts to dynamically access and update the content, structure and style of a
document.” It is formally subdivided into three parts: (a) the Core DOM for all document types, (b) the
XML DOM for XML documents, and (c) the HTML DOM for HTML documents. It adopts an object-
orientated programming approach, with the HTML elements being objects which have properties and to
which can be applied methods. The elements can also trigger events.
A common way of accessing an element is to assign it an id (i.e. set its id attribute object to a prespecified
value). The element can then be identified in Javascript by applying the getElementById method to the
document object, returning an object corresponding to the element. Its properties (e.g. its innerHTML
property, which is the text within an element) can be set by assigning values to the relevant property of
the element object. For example, the following example returns a web page that says “hello”.
<html>
<body>
23
<div id="example"></div>
<script>document.getElementById("example").innerHTML = "hello"</script>
</body>
</html>
The DOM uses the idea of nodes and a node tree. This involves a tree structure where each branching
point is a separate node. So, nodes belong to (are children of) just one other node (their parent) back to
the root node (which in the DOM is the document object)
HTML elements are ‘element’ nodes, the attributes of these elements are ‘attribute’ nodes, the text
within HTML elements are ‘text’ nodes and comments are ‘comment’ nodes
A NodeList object represents a set of nodes, e.g. an HTML element’s collection of child nodes. These will
be indexed and each node within the NodeList can then be associated with another NodeList (its children)
The HTML document, once it has been loaded into the web browser, is formally part of the corresponding
Window object and can therefore be accessed via window.document
The DOM supports a range of (own) methods and properties, see here.
HTML elements (‘nodes’) within the DOM also support a range of more generic methods and properties,
see here. These also apply to the document object itself but do not always make much sense when
applied in this manner.
24
HTML element attributes are represented by an Attr object. These are always children of a specific HTML
element. The properties and methods that apply to Attr objects are shown here.
A NamedNodeMap object represents an unordered collection of nodes, e.g. the set of attributes assigned
to a given HTML element. Properties and methods that apply to NamedNodeMap objects are shown
here.
The DOM object and its components can be thought of as an example of an XML document. XML
documents have several methods and properties not otherwise covered in the above (such as
XMLHTTPRequest, which can be used to send, request and receive data from the server once a webpage
has loaded), see here.
Further details are set out in the following pages and in links within them:
Miscellaneous
[JavaScriptTutorialMiscellaneous]
We set out below some further comments on JavaScript that may help developers.
JavaScript syntax:
25
An expression is a combination of values, variables and operators
String concatenation is achieved by +, e.g. "a" + " " + "b" evaluates to "a b"
Comments are noted by text after double slashes “//” or between /* and */
Identifiers are used to name variables. The first character must be a letter, an underscore
character (“_”) or a dollar sign (“$”)
JavaScript is case sensitive, e.g. firstName, FirstName and firstname will be three different variables
JavaScript typically uses ‘lower camel case’ when joining multiple words together, i.e. first letter of first
word is lower case, first letter of each subsequent word is upper case, e.g. “firstName”. Some methods
and properties specifically use this convention, and because JavaScript is case sensitive it means that
using a different convention will result in an incorrect (or failed) evaluation. Developers often adopt the
same convention when naming variables.
JavaScript uses the Unicode character set
Text and values can be inserted into an HTML element, using e.g. the innerHTML property
We can write to the browser output stream, using e.g. document.write() (this is useful for testing
purposes)
We can write to an alert box, using e.g. window.alert()
We can write into the browser console, using e.g. console.log()
JavaScript has some global properties and functions that can be used with all built-in JavaScript objects.
These include:
Global properties:
Global methods:
These are perhaps best referred to as global ‘functions’ since they are called globally.
26
escape() Depreciated. Use encodeURI() or Here
encodeURIComponent() instead
eval() Evaluates a string as if it were script code Here
isFinite() Returns true if finite, otherwise false Here
isNaN() Returns true if NaN, otherwise false Here
Number() Converts an object’s value to a number Here
parseFloat() Parses a string and returns a floating-point number Here
parseInt() Parses a string and returns an integer Here
String() Converts an object’s value to a string Here
unescape() Depreciated. Use decodeURI() or Here
decodeURIComponent() instead
JavaScript includes some properties that can be applied to any object and can allow the user to alter the
methods and properties applicable to the object. These include:
27
["ten"] "ten" NaN True
["five","ten"] "five","ten" NaN True
function(){} "function(){}" NaN True
{} "[object NaN True
Object]"
null "null" 0 False
undefined "undefined" NaN False
It is worth noting that some of the global type conversion functions are mimicked by type conversion
functions attached to specific object types. The behaviours of the two apparently similar functions are not
always identical, as the ones attached to specific object types will include a conversion into the relevant
type before there is an attempt to convert the variable into its eventual output type.
Recent developments:
In recent years, the capabilities and therefore sophistication of the JavaScript language has grown
considerably. Browser developers have put a considerable amount of effort into arranging for JavaScript
code to run as quickly as possible within browsers. For example, they have developed ‘just in time’
compilation techniques to supplant older purely interpreted ways of executing the JavaScript statements.
JavaScript as a language has been standardised and object-orientated programming tools such as error
trapping have been added. Event handling (which is particularly important for browser based programs)
has been further refined. Its DOM has continued to evolve and become more sophisticated as website
usage has expanded and evolved.
28
Appendix A: HTML Elements
[HTMLElements]
Conventionally in HTML, everything between the start of a start tag and the end of its corresponding end
tag is called an element. The element content is the material between the start and end tag. In HTML,
some tags are automatically empty, such as <br> and hence don’t have any element content or end tag.
For example:
The following is a list of HTML elements / tags. HTML 5 is the latest available version of HTML as at the
time of writing. Some elements allowable in previous HTML versions have been discontinued in it and it is
advisable not to use these elements anymore. Conventions used to open and close elements in XHTML
are not quite the same as those used in HTML.
29
<canvas> Used to draw graphics via scripting Here New in HTML 5
(usually via JavaScript)
<caption> Table caption Here
<center> Centred text Here Not supported in HTML 5
(instead use CSS)
<cite> Title of a work Here
<code> A piece of computer code Here
<col> Indicates column properties assigned to Here
each column within a <colgroup>
element
<colgroup> Specifies a group of one or more Here
columns in a table
<data> Links content with a machine-readable Here New in HTML 5
translation
<datalist> A list of pre-defined options for an Here New in HTML 5
<input> control
<dd> Description or value of an entry in a Here
description list
<del> Indicates text deleted from a Here
document
<details> Additional details that a user can view Here New in HTML 5
or hide
<dfn> Defining instance of a term Here
<dialog> Dialog box or window Here
<dir> Directory list Here Not supported in HTML 5
(instead use <ul>)
<div> Section in a document Here Usually assigned its own
style
<dl> Description list Here
<dt> Term or name in a description list Here
<em> Emphasised text Here Often used to italicise text,
but ideally this
should be done using CSS
<embed> A container for an external (non- Here New in HTML 5
HTML) application
<fieldset> Groups related elements in a form Here
<figcaption> A caption for a <figure> element Here New in HTML 5
<figure> Self-contained content Here New in HTML 5
<font> Font, colour and size of text Here Not supported in HTML 5
(instead use CSS)
<footer> Footer for a document or section Here New in HTML 5
<form> An HTML form for user input Here
<frame> A window (frame) within a frameset Here Not supported in HTML 5
<frameset> A set of <frame> elements Here Not supported in HTML 5
<h1>, <h2>, HTML headings Here Provides a hierarchy of
<h3>, <h4>, headings
<h5>, <h6>
<head> Provides information about the Here
document
<header> Header for a document or section Here New in HTML 5
30
<hr> Indicates a thematic change in the Here Often rendered as a line
content across the window
<html> Is the root node of an HTML document Here Only <!DOCTYPE>
elements should appear
outside the <html> element
31
<rt> Explanation / pronunciation of Here New in HTML 5. For East
32
Basic elements (and tags that don’t contain anything)
Audio / video
33
Formatting
Forms and inputs
Frames
Images
Links
Lists
Metadata
Programming (i.e. scripting)
Tables
Styles (and other miscellaneous elements)
Some of the formatting elements are called phrase elements, as they are typically used primarily to
delineate specific types of text.
The following is a list of HTML basic elements that every HTML page is supposed to contain (although if a
<!DOCTYPE> element is not present then essentially all modern browsers will assume that the page is an
HTML page, and, as explained in HTML Getting Started, you can often also dispense with the <title>
element (and potentially also the <html>, <head> and <body> elements).
The <head> element can also be deemed a metadata element, as it forms part of the way in which
metadata is included in such a document.
Three other elements are also typically considered ‘basic’, either because they don’t contain
anything or because they comment out other material:
34
Audio / video elements
[HTMLElementsAudioVideo]
Formatting elements
[HTMLElementsFormatting]
35
mood
<ins> Indicates text added to a document Here
<kbd> Keyboard input Here
<mark> Marked/highlighted text Here New in HTML 5
<meter> A scalar measurement within Here New in HTML 5
a
specific range (a gauge)
<p> Paragraph Here
<pre> Preformatted text Here
<progress> Represents the progress of a task Here New in HTML 5
<q> Short quotation Here
<rp> Indicates what to show in browsers Here New in HTML 5
that do not support ruby annotations
<rt> Explanation / pronunciation Here New in HTML 5. For East
of Asian typography
characters
<ruby> Ruby annotation Here New in HTML 5. For East
Asian typography
<s> Text that is no longer correct Here
<samp> Sample output from a computer Here
program
<small> Smaller text Here
<strike> Strikethrough text Here Not supported in HTML 5
(instead use <del> or <s>)
<strong> Defines more important text Here Commonly
used as another
way of
highlighting text or
making it bold
<sub> Subscripted text Here
<sup> Superscripted text Here
<time> Date / time Here New in HTML 5
<tt> Teletype text Here Not supported in HTML 5
(instead use CSS)
<u> Text that should be Here Commonly used for
stylistically underlining
different from normal text
<var> Variable Here
<wbr> Posible line-break Here New in HTML 5
The default styles applicable to these elements are shown here. The behaviour of most formatting
elements can be replicated using CSS.
36
<fieldset> Groups related elements in a form Here
Frame elements
[HTMLElementsFrames]
The following is a list of HTML frame elements:
Image elements
[HTMLElementsImages]
The following is a list of HTML image elements:
Link elements
37
[HTMLElementsLinks]
List elements
[HTMLElementsLists]
Metadata elements
[HTMLElementsMetadata]
38
Programming elements
[HTMLElementsProgramming]
Table elements
[HTMLElementsTables]
39
translation
<details> Additional details that a user can view Here New in HTML 5
or hide
<dialog> Dialog box or window Here
<div> Section in a document Here Usually assigned its own
style
<footer> Footer for a document or section Here New in HTML 5
<header> Header for a document or section Here New in HTML 5
<main> Main content of a document Here New in HTML 5
<section> Section in a document Here New in HTML 5
<span> Section in a document Here Usually defined its own
style
<style> Style information for a document Here
<summary> Heading for a <details> element Here New in HTML 5
Phrase elements
[HTMLPhraseElements]
Some HTML formatting elements are typically used to delineate text of specific types. These HTML
elements are called ‘phrase’ elements:
XHTML
[HTMLTutorialXHTML]
XHTML stands for eXtensible Hypertext Markup Langauge. It is designed to be very like HTML but
structured in a fashion that also adheres to the rules of XML.
40
Typically, most browsers accept some types of ‘badly formed’ HTML, e.g. HTML in which a document’s
<head> element is not properly closed before its <body> element is opened. This is despite such markup
text failing to adhere to the rules that HTML is supposed to follow. However, such pages may not work
well or consistently on some devices. A processing overhead is incurred when a browser tries to interpret
badly-formed HTML, which may not be practical for some smaller devices. There may also be several
possible ways of interpreting badly-formed HTML. XML is more rigidly structured than HTML (and it is
easier to test that its rules are being adhered to), making it an easier vehicle through which to introduce
disciplines that aim to ensure all markup text is ‘well- formed’.
The XHTML DOCTYPE element (which takes the form <!DOCTYPE attributes>) must be present at the start
of the document.
<html>, <head>, <title> and <body> elements must also be present, and the xmlns
attribute of the <html> element must be defined appropriately.
All XHTML elements must be properly closed (and properly nested), e.g. using </p> to close a paragraph
(<p>) element and not just starting a new one with a new <p>. Note, usually browsers would interpret
<p> text1 <p> text2 </p> as two consecutive paragraphs even though this involves badly-formed HTML.
A corollary of 3. is that HTML empty elements such as the <br>, <hr> and <img> element must also be
properly closed in XHTML, i.e. they should be written as <br />, <hr /> and
<img src="filename" /> respectively.
XHTML element and attribute names must use lower case, e.g. the XHTML <p> element must be written
as <p> text </p> rather than <P> text </P>.
All XHTML attribute values must be included in quotes. So, HTML such as <p width=100px> is wrong in
XHTML and should be replaced by <p width="100px">.
Attribute minimisation is forbidden. Attribute minimisation in HTML involves including just the attribute
name rather than both the name and its value if its value is the same as its name. For example, HTML of
the form <input type="checkbox" name="fruit" value="apple" checked /> should be replaced in HTML by
<input type="checkbox" name="fruit" value="apple" checked="checked"
/>.
In practice, it is usually quite easy (if possibly laborious) to convert HTML to XHTML by:
Adding a suitable XHTML <!DOCTYPE> statement to the first line of the page and adding an xmlns
attribute to the html element of the page
Changing all element names and attribute names to lower case
Closing all empty elements
Putting all attribute values in quotes (and eliminating any attribute minimisation that is present)
41
<title>Title</title>
</head>
<body>
Content
</body>
</html>
The HTML <a> or anchor element represents a hyperlink. It typically takes the form:
<a href="url">text</a>
or
Here:
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above (except perhaps the media
attribute). It also has a text property which sets or returns the text content of the object. It also supports
the hash, host, hostname, origin, password, pathname, port, protocol, search and username variants of
the href attribute, see here for more details.
42
By default, an unvisited link is underlined and is usually blue, a visited link is underlined and purple and an
active link is underlined and is usually purple, see here. However, it is possible to change these defaults
by setting relevant CSS attributes.
<abbr>
[HTMLElementAbbr]
The HTML <abbr> element indicates an abbreviation or acronym. The full text which is being
abbreviated can be included in the element’s title attribute and it will then typically appear as tooltip text
if the mouse is moved over the element.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<acronym>
[HTMLElementAcronym]
The HTML <acronym> element was used to indicate an acronym. It is not supported in HTML 5. Instead,
use the <del> or <s> element.
<address>
[HTMLElementAddress]
The HTML <address> element is usually used to define contact information for the author or owner of a
document or file. If it is inside an <article> element then it typically represents contact information for
that article. If it is outside an article element but inside a <body> element then it typically represents
contact information for the document or page.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<applet>
[HTMLElementApplet]
The HTML <applet> element was used to indicate an embedded applet. It is not supported in HTML 5.
Instead, use the <embed> or <object> element.
<area>
43
[HTMLElementArea]
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above (except the download,
hreflang, media, rel and type attribute). The corresponding HTML DOM object also typically supports the
hash, host, hostname, origin, password, pathname, port, protocol, search and username variants of the
href attribute, see here for more details. The default style applicable to this element is shown here.
<article>
[HTMLElementArticle]
The HTML <article> element indicates a self-contained piece of content, such as a blog or forum post, a
specific news story or some self-contained comment on a specific piece of text. It is new in HTML 5.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<aside>
[HTMLElementAside]
The HTML <aside> element indicates some content separate from but related to surrounding context. It is
new in HTML 5.
44
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<audio>
[HTMLElementAudio]
The HTML <audio> element is used to define and play sound, such as music or other audio streams.
Supported file formats include MP3 (nearly all browsers), Wav (not Internet Explorer) and Ogg (some
browsers). It is new in HTML 5.
If the browser does not support <audio> elements then any text between the <audio> and
</audio> tags will be displayed.
The attributes it can take (in addition to HTML global attributes and HTML event attributes) include:
Additional methods:
<b>
[HTMLElementB]
45
The HTML <b> element indicates bold text. According to the HTML 5 specification it should be used as a
last resort when no other elements such as <strong>, <h1>, <h2>, <h3>, <h4>, <h5> or <h6> are
appropriate.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<base>
[HTMLElementBase]
The HTML <base> element specifies the base URL for all relative URLs in a document. There can be at
most one <base> element in any specific document (and it should be inside the relevant <head>
element).
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above. It also typically supports
the hash, host, hostname, origin, password, pathname, port, protocol, search and username variants of
the href attribute, see here for more details. The default style applicable to this element is shown here.
<basefont>
[HTMLElementBasefont]
The HTML <basefont> element was used to indicate the default font, colour and size of all text in a
document. It is not supported in HTML 5. Instead, use CSS.
<bdi>
[HTMLElementBdi]
The HTML <bdi> element indicates material that might be formatted in a different direction from
other material surrounding the element. ‘bdi’ stands for ‘bi-directional isolation’. It is new in HTML
5. A similar effect can usually be achieved using the unicode-bidi style applied to e.g. a span element, but
the semantic meaning is only conveyed by the <bdi> element and in some cases browsers may ignore
CSS, but not a <bdi> element.
46
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<bdo>
[HTMLElementBdo]
The HTML <bdo> element makes it possible to override the current text direction.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above. The default style applicable
to this element is shown here.
<big>
[HTMLElementBig]
The HTML <big> element was used to indicate big text. It is not supported in HTML 5. Instead, use CSS.
<blockquote>
[HTMLElementBlockquote]
The HTML <blockquote> element indicates a section that is quoted from another source. Browsers often
indent text in such elements (typically a <q> element is used for an in-line quotation and isn’t indented).
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
<body>
[HTMLElementBody]
47
The HTML <body> element identifies the body of the document and contains all the visible contents of
the document, such as text, hyperlinks, tables and images etc.
The attributes it can take are HTML global attributes and HTML event attributes.
It used to support the alink, background, bgcolor, link, text and vlink attributes, but these are no longer
supported in HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<br>
[HTMLElementBr]
The HTML <br> element indicates a single line break (c.f. a carriage return). In XHTML, it needs to
be ‘properly’ closed as per <br />.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<button>
[HTMLElementButton]
The HTML <button> element indicates a clickable button. Inside a <button> element (unlike an
<input> element) you can put content such as text or images. You should typically specify the type
attribute for <button> element as different browsers do not necessarily default to the same type. Within
a <form> element you should also bear in mind that different browsers may submit different values.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above. However, the DOM
versions of formaction, formenctype, formmethod, formnovalidate and formtarget need to adopt the
JavaScript name capitalisation convention, i.e. need to be: formAction, formEnctype, formMethod,
formNoValidate and formTarget respectively. The default style applicable to this element is shown here.
<canvas>
[HTMLElementCanvas]
The HTML <canvas> element is used to draw graphics via scripting (usually via JavaScript). It is new in
HTML 5. Such an element isn’t directly endowed with its own drawing abilities. Instead it is necessary to
apply the getContext() method to the corresponding DOM object to return another object that does have
drawing abilities.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, as well as the following additional methods:
Older versions of getContext focus on getContext("2d") which allows drawing of many types of two-
dimensional material (e.g. text, lines, boxes, circles etc.). Newer versions support drawing of hardware-
supported three-dimensional objects via getContext("WebGL") or getContext("WebGL2").
The object returned by the getContext("2d") method provides the following properties and methods:
49
Property Description More
Styles etc.
fillStyle Sets / returns style (colour, gradient, pattern Here
etc.) used to fill element
strokeStyle Sets / returns style used for strokes Here
shadowBlur Sets / returns shadow blur level, see CSS text- Here
shadow property
shadowColor Sets / returns shadow colour, see CSS text- Here
shadow property
shadowOffsetX Sets / returns shadow horizontal offset, see Here
CSS text-shadow property
shadowOffsetY Sets / returns shadow vertical offset, see CSS Here
text-shadow property
Line styles
lineCap Sets / returns style used for line ends Here
lineJoin Sets / returns type of corner between two Here
lines where they join
lineWidth Sets / returns line width Here
miterLimit Sets / returns maximum mitre limit Here
Text
font Sets / returns CSS font property for current Here
text
textAlign Sets / returns CSS text-align property for Here
current text
textBaseline Sets / returns text baseline for current text Here
Sizing and manipulation of
individual pixels
data Returns object containing image data for Here
specific ImageData object
height Returns height of an ImageData object Here
width Returns width of an ImageData object Here
Other
globalAlpha Sets / returns current alpha, i.e. transparency Here
value, of drawing
globalCompositeOperation Sets / returns how new images are drawn onto Here
existing images
50
rect() Creates a rectangle Here
strokeRect() Draws a rectangle that is not ‘filled’ Here
Paths
arc() Creates a circular arc Here
arcTo() Creates a circular arc between two tangents Here
beginPath() Begins / resets a path Here
bezierCurveTo() Creates cubic Bézier curve Here
clip() Clips region from canvas Here
closePath() Completes path back to its original starting point Here
fill() Fills current path Here
isPointInPath() Returns true if point is in current path, otherwise Here
false
lineTo() Moves path to a specified point in the canvas, Here
creating a line from the previous point
moveTo() Moves path to a specified point in the canvas Here
without creating a line
quadraticCurveTo() Creates quadratic Bézier curve Here
stroke() Draws path in the canvas Here
Transformations
rotate() Rotates current drawing Here
scale() Scales current drawing Here
setTransform() Defines a transform matrix and then applies Here
transform() method
transform() Applies a transformation to current drawing Here
translate() Applies a translation to current drawing (i.e. Here
adjusts the position of its origin)
Text
fillText() Draws ‘filled’ text Here
measureText() Returns object indicating width of specified text Here
strokeText() Draws text that is not ‘filled’ Here
Drawing images
drawImage() Draws an image, canvas or video onto canvas Here
Sizing and manipulation of
individual pixels
createImageData() Creates a new blank ImageData object Here
getImageData() Returns ImageData object characterised by pixel Here
data for specific rectangle in canvas
putImageData() Puts image data included in an ImageData object Here
onto canvas
The objects returned by the getContext("WebGL") and the getContext("WebGL2") methods provide
equivalent 3D and other more sophisticated graphical capabilities. They are not currently explored
further in these pages.
<caption>
[HTMLElementCaption]
51
52
The HTML <caption> element indicates a table caption. It should be inserted immediately after opening
<table> tag of the <table> element.
The attributes it can take are HTML global attributes and HTML event attributes. It used to support the
align attribute, but this is no longer supported in HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<center>
[HTMLElementCenter]
The HTML <center> element was used to indicate centred text. It is not supported in HTML 5. Instead, use
CSS.
<cite>
[HTMLElementCite]
The HTML <cite> element indicates the title of a work (e.g. a book or movie). It is not typically used for
the author of the work.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<code>
[HTMLElementCode]
The HTML <code> element is a phrase element indicating a piece of computer code. It is not depreciated,
but typically a richer effect can be achieved using CSS.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<col>
[HTMLElementCol]
The HTML <col> element indicates the column properties assigned to each column within a
<colgroup> element. It can be used to apply styles to entire columns in a table.
53
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
<colgroup>
[HTMLElementColgroup]
The HTML <colgroup> element specifies a group of one or more columns in a table. It can be used to
apply styles to entire columns in a table. It must be a child of a <table> element, positioned after any
<caption> elements and before any <tbody>, <tfoot>, <thead> and <tr> elements. If you want to define
different styles to column within the column group then use the <col> element.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
comment
[HTMLElementComment]
<!-- … -->
<data>
[HTMLElementData]
The HTML <data> element links content with a machine-readable translation. It is new in HTML 5. If the
content is date or time based then an alternative is to use a <time> element.
54
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
<datalist>
[HTMLElementDatalist]
The HTML <datalist> element identifies a list of pre-defined options for an <input> element. It is new in
HTML 5. The <input> element’s list attribute should be set to the id of the <datalist> in order to bind the
two together and within the <datalist> should be some <option> elements.
Users will then see a dropdown list of choices (defined by the <option> elements) that they can select for
the <input> element, e.g.:
<input list="fruit">
<datalist id="fruit">
<option value="apple">
<option value="banana">
<option value="orange">
</datalist>
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. It also supports the following additional property:
<dd>
[HTMLElementDd]
The HTML <dd> element indicates a description or value of an entry in a description list, i.e. a <dl>
element, typically with each <dd> element linked to an associated <dt> element, that defines the term
which the <dd> element describes, e.g.:
<dl>
<dt>UK</dt><dd>United Kingdom</dd>
<dt>USA</dt><dd>United States of America</dd>
</dl>
55
Text, paragraphs, images etc. can be placed inside <dd> and <dt> elements.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<del>
[HTMLElementDel]
The HTML <del> element indicates text deleted from a document. It is often used in association with the
<ins> element to highlight modifications to text.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above (with the datetime property
of the underlying element corresponding to the dateTime property of the DOM object). The default style
applicable to this element is shown here.
<details>
[HTMLElementDetails]
The HTML <details> element indicates additional details that a user can view or hide. It is new in HTML 5.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above. The default style applicable
to this element is shown here.
<dfn>
[HTMLElementDfn]
56
The HTML <dfn> element indicates the defining instance of a term, usually its first use. In research
papers, books and other documents such instances may be italicised. The nearest parent of a <dfn>
element should typically contain a short definition or explanation for the term included in the
<dfn> element.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<dialog>
[HTMLElementDialog]
The HTML <dialog> element indicates a dialog box or window. It simplifies the creation of popup dialogs,
but is not currently supported by all major browsers.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
<dir>
[HTMLElementDir]
The HTML <dir> element was used to indicate a directory list. It is not supported in HTML 5. Instead, use
the <ul> element or CSS style lists.
<div>
[HTMLElementDiv]
The HTML <div> element indicates a section (i.e. division) in a document. It is usually assigned its own
style, differentiating it from other elements next to it in the document.
The attributes it can take are HTML global attributes and HTML event attributes. It used to support the
align attribute but this is no longer supported in HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<dl>
57
[HTMLElementDl]
The HTML <dl> element indicates a description list. It is used in conjunction with <dd> and <dt> elements.
A <dt> element identifies a term and the associated <dd> element provides the description for that term,
e.g.:
<dl>
<dt>UK</dt><dd>United Kingdom</dd>
<dt>USA</dt><dd>United States of America</dd>
</dl>
Text, paragraphs, images etc. can be placed inside <dd> and <dt> elements.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
document type
[HTMLElementDocumentType]
Or:
<!DOCTYPE attributes>
Declaration Meaning
<!DOCTYPE html> HTML 5
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" HTML 4.01 Strict (excludes
"http://www.w3.org/TR/html4/strict.dtd"> depreciated elements)
58
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" XHTML 1.1, as XHTML 1.0
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> but allows additional modules,
e.g. to provide ruby support for
East Asian languages
<dt>
[HTMLElementDt]
The HTML <dt> element indicates a term or name in a description list, i.e. a <dl> element, typically with
each <dd> element linked to an associated <dt> element, that defines the term which the
<dd> element describes, e.g.:
<dl>
<dt>UK</dt><dd>United Kingdom</dd>
<dt>USA</dt><dd>United States of America</dd>
</dl>
Text, paragraphs, images etc. can be placed inside <dd> and <dt> elements.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<em>
[HTMLElementEm]
The HTML <em> element is a phrase element indicating emphasised text. Often it is used to italicise text,
but ideally this should be done using CSS.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<embed>
[HTMLElementEmbed]
The HTML <embed> element indicates a container for an external (non-HTML) application, e.g. a plug-in.
It is new in HTML 5.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
59
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above. The default style applicable
to this element is shown here.
<fieldset>
[HTMLElementFieldset]
The HTML <fieldset> element groups related elements in a form, and typically draws a box around them.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above.
It also supports the following additional property:
<figcaption>
[HTMLElementFigcaption]
The HTML <figcaption> element indicates a caption for a <figure> element. It is new in HTML 5. It can be
the first or the last child element of the <figure> element.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<figure>
[HTMLElementFigure]
60
The HTML <figure> element indicates a piece of self-contained content, like an illustration, diagram or
piece of computer code. It is new in HTML 5. Ideally, the content of a <figure> element should not
specifically link to its exact position within the text (e.g. in a research paper figures will be referred to in
the text, but can be positioned in a variety of places without altering the meaning of the text). A
<figcaption> element is used to add a caption to a <figure> element
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<font>
[HTMLElementFont]
The HTML <font> element was used to indicate the font, colour and size of text. It is not supported in
HTML 5. Instead, use CSS.
<footer>
[HTMLElementFooter]
The HTML <footer> element indicates a footer for a document or section. It is new in HTML 5. Typically, a
<footer> element might contain authorship or copyright information. A document can contain several
<footer> elements.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<form>
[HTMLElementForm]
The HTML <form> element indicates an HTML form for user input. Typically, a <form> element will
contain one or more of the following form elements:
<button>
<fieldset>
<input>
<label>
<optgroup>
<option>
<select>
<textarea>
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
61
Attribute Description More
accept-charset Specifies character encodings used for form submission Here
action Where to send form-data when form submitted Here
autocomplete Specifies whether element has autocomplete enabled Here
enctype How form-data to be encoded when submitted to server Here. Only
for method
= post
method Specifies HTTP method used when sending form-data Here
name Name of element Here
novalidate Form should not be validated when submitted Here
target Specifies where / how to open the linked document (or Here
where to submit the form)
It also used to take the accept attribute, but this is no longer supported in HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above (with the novalidate
property of the underlying element corresponding to the noValidate property of the DOM object). It also
supports the following additional properties and methods:
Additional properties:
<frame>
[HTMLElementFrame]
The HTML <frame> element was used to indicate a window (frame) within a frameset. It is not supported
in HTML 5.
<frameset>
[HTMLElementFrameset]
The HTML <frameset> element was used to indicate a set of <frame> elements. It is not supported in
HTML 5.
62
<h1>
[HTMLElementH1]
The attributes it can take are HTML global attributes and HTML event attributes.
It used to support the align attribute, but this is no longer supported in HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<h2>
[HTMLElementH2]
The attributes it can take are HTML global attributes and HTML event attributes.
It used to support the align attribute, but this is no longer supported in HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<h3>
[HTMLElementH3]
The attributes it can take are HTML global attributes and HTML event attributes.
It used to support the align attribute, but this is no longer supported in HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<h4>
[HTMLElementH4]
The attributes it can take are HTML global attributes and HTML event attributes.
It used to support the align attribute, but this is no longer supported in HTML 5.
63
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<h5>
[HTMLElementH5]
The HTML <h5> element indicates a level 5 HTML heading.
The attributes it can take are HTML global attributes and HTML event attributes.
It used to support the align attribute, but this is no longer supported in HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<h6>
[HTMLElementH6]
The HTML <h6> element indicates a level 6 HTML heading.
The attributes it can take are HTML global attributes and HTML event attributes.
It used to support the align attribute, but this is no longer supported in HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<head>
[HTMLElementHead]
The HTML <head> element provides information about the document. The <head> element can contain
the following sorts of elements (it is always supposed to include a <title> element, but HTML that does
not do so may not be rejected by browsers):
<base>
<link>
<meta>
<noscript>
<script>
<style>
<title>
The attributes it can take are HTML global attributes and HTML event attributes.
64
It used to support the profile attribute, but this is no longer supported in HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<header>
[HTMLElementHeader]
The HTML <header> element indicates a header for a document or section. It is new in HTML 5. Typically,
a <header> element might contain introductory content, navigational links, one or more heading
elements (i.e. <h1>, <h2>, <h3>, <h4>, <h5> or <h6>), a logo and perhaps also some authorship
information. A document can contain several <header> elements.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
headings
[HTMLElementHeadings]
The HTML <h1>, <h2>, <h3>, <h4>, <h5> and <h6> elements provide a hierarchy of headings (with the
<h1> element by default having the largest size and the <h6> element the smallest size).
<hr>
[HTMLElementHr]
The HTML <hr> element indicates a thematic change in the content. Often it is rendered as a line across
the window.
The attributes it can take are HTML global attributes and HTML event attributes.
It used to support the align, noshade, size and width attributes, but these are no longer supported in
HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<html>
[HTMLElementHtml]
The HTML <html> element is the root node of an HTML document. Only <!DOCTYPE> elements should
appear outside it. It tells the browser that the document is an HTML document.
65
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<i>
[HTMLElementI]
The HTML <i> element indicates a part of text in an alternate voice or mood. Typically it is rendered as
italicised text. Convention recommends using the <i> element only when there isn’t a more appropriate
element, such as <cite>, <dfn>, <em>, <mark> or <strong>.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<iframe>
[HTMLElementIframe]
The HTML <iframe> element indicates an inline frame. It can also be used to embed another document
within the current HTML document.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
66
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above. It also supports the
following additional properties:
<img>
[HTMLElementImg]
The HTML <img> element indicates an image. It technically has two required attributes, namely src (the
source of the image) and alt (the alternative text displayed if the image cannot be found or cannot be
displayed by the browser), although the alt attribute can typically be dispensed with. Images are not
technically inserted into an HTML page but instead are linked to the page. The
<img> element therefore creates a placeholder that will include the image once the page is rendered (and
the image retrieved by the rendering process from its source location).
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
It used to support the align, border, hspace, longDesc and vspace attributes, but these are no longer
supported in HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above (with the crossorigin, ismap
and usemap properties of the underlying element corresponding to the crossOrigin, isMap and useMap
properties of the DOM object). It also supports the following additional properties:
<input>
67
[HTMLElementInput]
The HTML <input> element indicates a (single-line) input control into which the user can enter data. It is
used within a <form> element. There are many different types of <input> element that vary depending on
the type attribute of the element, including:
- button, checkbox, color, date, datetime, datetime-local, email, file, hidden, image, month,
number, password, radio, range, reset, search, submit, tel, text, time, url, week
In HTML markup <input> elements are empty (they only involve attributes). Labels for input elements can
be defined using the <label> element.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
68
element
min Minimum value Here
multiple Indicates that a user can enter more than one Here
value
name Name of element Here
pattern Regular expression that value of element is Here
checked against
placeholder Short hint describing expected value of element Here
readonly Whether element is read-only Here
required Whether the element must be filled out before Here
submitting form
size Specifies width in characters of element Here
src URL of resource Here
step Accepted number intervals Here
type Type of element Here
value Value of element Here
width Width of element Here
Some of these attributes are valid for only some <input> element types:
formTarget
text autocomplete, list, maxlength, pattern, placeholder,
readonly, required, size
69
time autocomplete, list, max, min, readonly, required, step
url autocomplete, list, maxlength, pattern, placeholder,
readonly, required, size
week autocomplete, list, max, min, readonly, required, step
It used to accept the align attribute, but this is no longer supported in HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above (with the formaction,
formenctype, formmethod, formnovalidate, formtarget, maxlength and readonly properties of the
underlying element corresponding to the formAction, formEnctype, formMethod, formNoValidate,
formTarget, maxLength and readOnly properties of the DOM object). It also supports the following
additional properties and methods:
Additional properties:
Additional methods:
<ins>
[HTMLElementIns]
The HTML <ins> element indicates text added to a document. It is often used in association with the
<del> element to highlight modifications to text.
70
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above (with the datetime property
of the underlying element corresponding to the dateTime property of the DOM object). The default style
applicable to this element is shown here.
<kbd>
[HTMLElementKbd]
The HTML <kbd> element is a phrase element indicating keyboard input. It is not depreciated, but
typically a richer effect can be achieved using CSS.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<keygen>
[HTMLElementKeygen]
The HTML <keygen> element indicates a key-pair generator field (for forms). It is positioned within a form
element. When the form is submitted, the private key is stored locally and the public key (of the key-pair)
is sent to the server.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
Note: it appears likely that <keygen> elements will be dropped from future versions of HTML so it may be
desirable not to use <keygen> elements.
71
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above. It also supports the
following additional properties:
<label>
[HTMLElementLabel]
The HTML <label> element indicates a label for an <input> element. It does not appear special as far as
the user is concerned, but does improve the usability of the <input> element, as it means that if the user
clicks on the text within <label> element then it toggles the control.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
<legend>
[HTMLElementLegend]
The HTML <legend> element indicates a caption for a <fieldset> element.
The attributes it can take are HTML global attributes and HTML event attributes.
It used to accept the align attribute, but this is no longer supported in HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. It also supports the following additional properties:
72
Property Description More
form Returns form that contains element Here
<li>
[HTMLElementLi]
The HTML <li> element indicates a list item. It is used in <ol> elements (ordered lists), <ul> elements
(unordered lists) and <menu> elements (menu lists).
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above. The default style applicable
to this element is shown here.
<link>
[HTMLElementLink]
The HTML <link> element defines the relationship between a document and an external resource. It is
most commonly used to link to CSS style sheets. It is an empty element (i.e. it only contains attributes)
and should only appear in the <head> element of an HTML document (but can appear any number of
times there).
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
73
It used to support the charset, rev and target attributes, but these are no longer supported in HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above (with the crossorigin
property of the underlying element corresponding to the crossOrigin property of the DOM object). The
default style applicable to this element is shown here.
<main>
[HTMLElementMain]
The HTML <main> element indicates the main content of a document. It is new in HTML 5. Content within
the element should ideally be unique to the document and hence should not include material such as
sidebars, copyright information, logos and search forms.
There shouldn’t be more than one <main> element in a document and it shouldn’t be a descendent
of an <article>, <aside>, <footer>, <header> or <nav> element.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<map>
[HTMLElementMap]
The HTML <map> element indicates a client-side image-map (i.e. an image with clickable areas). It needs
a name attribute, which creates a relationship between the image and the map. It typically contains one
or more <area> elements that indicate which parts of the image map are clickable. In HTML 5, if the id
attribute of the <map> element is specified then it needs to have the same value as the name attribute.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
<mark>
[HTMLElementMark]
74
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<menu>
[HTMLElementMenu]
The HTML <menu> element indicates a menu or list of commands. In theory, it can be used for toolbars,
context menus, listing form controls and commands. However, at the time of writing it was not supported
by many browsers.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above. The default style applicable
to this element is shown here.
<menuitem>
[HTMLElementMenuitem]
The HTML <menuitem> element indicates a menu item/command that a user can invoke from a popup
menu. It is new in HTML 5. In theory, it can be used for toolbars, context menus, listing form controls and
commands. However, at the time of writing it was not supported by many browsers.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above. It also supports the
following additional properties:
75
The default style applicable to this element is shown here.
<meta>
[HTMLElementMeta]
The HTML <meta> element indicates metadata about an HTML document. Metadata is not displayed on
the page but is machine readable. The <meta> element always goes within the <head> element.
Metadata within a <meta> element are always passed in pairs, one part describing what type of metadata
is involved, the other indicating the value to ascribe to the metadata.
In HTML 5 a viewport metadata component was introduced (see above), allowing webpage designers
greater control over the user’s viewing experience, i.e. how the browser handles the browser window
within which the page is viewed.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
76
The element used to support the scheme attribute, but this is no longer supported in HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above (with the http- equiv
property of the underlying element corresponding to the httpEquiv property of the DOM object). The
default style applicable to this element is shown here.
<meter>
[HTMLElementMeter]
The HTML <meter> element indicates a scalar measurement within a specific range (otherwise called a
gauge). It can also take fractional values. It is new in HTML 5. It is not designed to be used to show task
progress, for which the preferred element is the <progress> element.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
The high, low, max and min attributes should satisfy: 𝑚𝑖𝑛 < 𝑙𝑜𝑤 < ℎ𝑖𝑔ℎ < 𝑚𝑎𝑥. Not all major browsers
currently support the high and low attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. It also supports the following additional properties and
methods:
<nav>
[HTMLElementNav]
The HTML <nav> element indicates navigation links. It is new in HTML 5. It is usual not to put all
navigation links inside a <nav> element. Instead this element is intended only for major blocks of such
links (so that browsers such as for disabled users can use this element to determine when to omit initial
rendering of content).
The attributes it can take are HTML global attributes and HTML event attributes.
77
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<noframes>
[HTMLElementNoframes]
The HTML <noframes> element was used to indicate alternate content for users whose browsers do not
support frames. It is not supported in HTML 5.
<noscript>
[HTMLElementNoscript]
The HTML <noscript> element indicates the alternate content to be used for users whose browsers do
not support client-side scripts (either because the browser doesn’t support them, which is rare these
days, or because users have disabled their use). It can be used inside both <head> and
<body> elements. With the former, it can only contain <link>, <style> and <meta> elements.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<object>
[HTMLElementObject]
The HTML <object> element indicates an embedded object, such as a Java applet, ActiveX or Flash plugin.
It can also be used to embed another webpage into the HTML document. <param> elements can be used
to pass parameters to plugins embedded within <object> elements.
<object> elements must appear inside the <body> element of the webpage. Text between the opening
<object> and the closing </object> tags is interpreted as alternative text that is displayed for browsers
that do not support the <object> element. At least one of element’s data or type attributes needs to be
defined.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
78
It used to support the align, archive, border, classid, codebase, codetype, declare, hspace, standby and
vspace attributes, but these are no longer supported by HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above (with the usemap property
of the underlying element corresponding to the useMap property of the DOM object).
<ol>
[HTMLElementOl]
The HTML <ol> element indicates an ordered list. The list can be numerical or alphabetical. Individual
items within the list are identified using <li> elements. Lists can be styled using CSS.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
It used to support the compact attribute, but this is no longer supported by HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above. The default style applicable
to this element is shown here.
<optgroup>
[HTMLElementOptgroup]
The HTML <optgroup> element indicates a group of related options in a drop-down list.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above). The default style
applicable to this element is shown here.
79
<option>
[HTMLElementOption]
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above. It also supports the
following additional properties:
<output>
[HTMLElementOutput]
The HTML <output> element indicates the result of a calculation (e.g. one performed by a script). It is
new in HTML 5.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above (with the for property
80
of the underlying element corresponding to the htmlFor property of the DOM object). It also supports the
following additional properties:
<p>
[HTMLElementP]
The HTML <p> element indicates a paragraph.
The attributes it can take are HTML global attributes and HTML event attributes.
It used to support the align attribute, but this is no longer supported in HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<param>
[HTMLElementParam]
The HTML <param> element indicates a parameter for an object.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above). The default style
applicable to this element is shown here.
<picture>
[HTMLElementPicture]
81
The HTML <picture> element indicates a container for multiple image resources. A <picture> element
contains zero or more <source> elements followed by one <img> element. The source element(s) will be
differentiated by different srcset attributes (required, defines the URL of the image to be shown by the
<picture> element) and by the media attribute (optional, a CSS media query that identifies which media
relates to that URL). The browser uses the first matching <source> element, and if none match then it
defaults to the <img> element.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<pre>
[HTMLElementPre]
The HTML <pre> element indicates a piece of preformatted text. Typically the text is displayed in a fixed-
width font (usually Courier), preserving both spaces and line breaks.
The attributes it can take are HTML global attributes and HTML event attributes. It used to support the
width attribute, but this is no longer supported by HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<progress>
[HTMLElementProgress]
The HTML <progress> element is most commonly used to show the progress of some task. It is new in
HTML 5. It is not very suitable for representing a gauge (like a fuel tank), for which better usually is to use
a <meter> element.
creates output that involves a progress bar showing that 40% of the task has been completed:
If you want the bar to be narrower than it is by default then you need to use the width attribute within
the style of the element, e.g. markup as follows:
Usually a progress bar will be updated as time progresses, often using JavaScript.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
82
Attribute Description More
max Maximum value Here
value Value of element Here
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above. It also supports the
following additional properties:
<q>
[HTMLElementQ]
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
<rp>
[HTMLElementRp]
The HTML <rp> element indicates what to show in browsers that do not support ruby annotations (for
East Asian typography). It is new in HTML 5.
It is used in conjunction with <rt> and <ruby> elements (the <ruby> element includes one or more
characters that need an explanation / pronunciation, the <rt> element gives that information and the
optional <rp> element indicates what to show for browsers that do not support such characters.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
83
<rt>
[HTMLElementRt]
The HTML <rt> element indicates an explanation / pronunciation of characters (typically for East Asian
typography). It is new in HTML 5.
It is used in conjunction with <rp> and <ruby> elements (the <ruby> element includes one or more
characters that need an explanation / pronunciation, the <rt> element gives that information and the
optional <rp> element indicates what to show for browsers that do not support such characters.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<ruby>
[HTMLElementRuby]
The HTML <ruby> element indicates ruby annotation (for East Asian typography). It is new in HTML 5.
It is used in conjunction with <rp> and <rt> elements (the <ruby> element includes one or more
characters that need an explanation / pronunciation, the <rt> element gives that information and the
optional <rp> element indicates what to show for browsers that do not support such characters.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<s>
[HTMLElementStrikeThrough]
The HTML <s> element indicates text that is no longer correct. Conventionally, the <s> element should
not be used for replaced or deleted text (instead use a <del> element).
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<samp>
[HTMLElementSamp]
84
The HTML <samp> element is a phrase element indicating sample output from a computer program. It is
not depreciated, but typically a richer effect can be achieved using CSS.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<script>
[HTMLElementScript]
The HTML <script> element indicates client-side script / programming code. Usually this is written in
JavaScript. The <script> element either contains this code or points to an external file via its src attribute
(if the src attribute is present then the <script> element must be empty). The contents of an noscript
element indicates what happens for users who have disabled scripts in their browser or whose browser
does not support client-side scripting.
The way in which a script executes is driven by the async and defer attributes. If neither are present then
the script is fetched and executed immediately the browser reaches the element (before the browser
continues parsing the page).
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above. It also supports the
following additional properties:
85
<section>
[HTMLElementSection]
The HTML <section> element indicates a section in a document (e.g. a discrete chapter / heading
/ footer etc>. It is new in HTML 5.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<select>
[HTMLElementSelect]
The HTML <select> element indicates a drop-down list. The option elements within the
<select> element identify the available options within the drop-down list
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above. It also supports the
following additional properties and methods:
Additional properties:
86
Method Description More
add() Adds an option to drop-down list Here
remove() Removes an option from drop-down list Here
<small>
[HTMLElementSmall]
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<source>
[HTMLElementSource]
The HTML <source> element allows multiple media resources for media elements. It links together
associated <video> and <audio>. It is new in HTML 5. The srcset attribute is required if the
<source> element is used in a picture element, whilst the src attribute is required when the
<source> element is used in an <audio> or <video> element.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above). The default style
applicable to this element is shown here.
<span>
[HTMLElementSpan]
The HTML <span> element indicates a section in a document. It is usually defined with its own style.
The attributes it can take are HTML global attributes and HTML event attributes.
87
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<strike>
[HTMLElementStrike]
The HTML <strike> element was used to indicate strikethrough text. It is not supported in HTML
5. Instead, use the <del> or <s> element.
<strong>
[HTMLElementStrong]
The HTML <strong> element is a phrase element indicating more important text. It is commonly used as a
way of highlighting text or making it bold.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<style>
[HTMLElementStyle]
The HTML <style> element indicates style information for a document. HTML documents can contain
multiple <style> elements. See CSS Tutorial for further details.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
(typically the style property of an element) supports standard DOM properties and methods, and
additional properties with the same name and meaning as the attributes of the underlying HTML element
referred to above. It also supports the following additional properties, see also CSS Properties:
88
animationTimingFunction animationTimingFunction Here
backfaceVisibility backface-visibility Here
background background Here
backgroundAttachment background-attachment Here
backgroundClip background-clip Here
backgroundColor background-color Here
backgroundImage background-image Here
backgroundOrigin background-origin Here
backgroundPosition background-position Here
backgroundRepeat background-repeat Here
backgroundSize background-size Here
border border Here
borderBottom border-bottom Here
borderBottomColor border-bottom-color Here
borderBottomLeftRadius border-bottom-left-radius Here
borderBottomRightRadius border-bottom-right-radius Here
borderBottomStyle border-bottom-style Here
borderBottomWidth border-bottom-width Here
borderCollapse border-collapse Here
borderColor border-color Here
borderImage border-image Here
borderImageOutset border-image-outset Here
borderImageRepeat border-image-repeat Here
borderImageSlice border-image-slice Here
borderImageSource border-image-source Here
borderImageWidth border-image-width Here
borderLeft border-left Here
borderLeftColor border-left-color Here
borderLeftStyle border-left-style Here
borderLeftWidth border-left-width Here
borderRadius border-radius Here
borderRight border-right Here
borderRightColor border-right-color Here
borderRightStyle border-right-style Here
borderRightWidth border-right-width Here
borderSpacing border-spacing Here
borderStyle border-style Here
borderTop border-top Here
borderTopColor border-top-color Here
borderTopLeftRadius border-top-left-radius Here
borderTopRightRadius border-top-right-radius Here
borderTopStyle border-top-style Here
borderTopWidth border-top-width Here
89
clip clip Here
color color Here
columnCount column-count Here
columnFill column-fill Here
columnGap column-gap Here
columnRule column-rule Here
columnRuleColor column-rule-color Here
columnRuleStyle column-rule-style Here
columnRuleWidth column-rule-width Here
columnSpan column-span Here
columnWidth column-width Here
columns columns Here
content content Here
counterIncrement counter-increment Here
counterReset counter-reset Here
cursor cursor Here
direction direction Here
display display Here
emptyCells empty-cells Here
filter filter Here
flex flex Here
flexBasis flex-basis Here
flexDirection flex-direction Here
flexFlow flex-flow Here
flexGrow flex-grow Here
flexShrink flex-shrink Here
flexWrap flex-wrap Here
cssFloat float Here
font font Here
fontFamily font-family Here
fontSize font-size Here
fontSizeAdjust font-size-adjust Here
fontStretch font-stretch Here
fontStyle font-style Here
fontVariant font-variant Here
fontWeight font-weight Here
hangingPunctuation hanging-punctuation Here
height height Here
justifyContent justify-content Here
left left Here
letterSpacing letter-spacing Here
lineHeight line-height Here
listStyle list-style Here
listStyleImage list-style-image Here
90
marginRight margin-right Here
marginTop margin-top Here
maxHeight max-height Here
maxWidth max-width Here
minHeight min-height Here
minWidth min-width Here
navDown nav-down Here
navIndex nav-index Here
navLeft nav-left Here
navRight nav-right Here
navUp nav-up Here
opacity opacity Here
order order Here
orphans orphans Here
outline outline Here
outlineColor outline-color Here
outlineOffset outline-offset Here
outlineStyle outline-style Here
outlineWidth outline-width Here
overflow overflow Here
overflowX overflow-x Here
overflowY overflow-y Here
Padding padding Here
paddingBottom padding-bottom Here
paddingLeft padding-left Here
paddingRight padding-right Here
paddingTop padding-top Here
pageBreakAfter page-break-after Here
pageBreakBefore page-break-before Here
pageBreakInside page-break-inside Here
perspective perspective Here
perspectiveOrigin perspective-origin Here
position position Here
quotes quotes Here
resize resize Here
right right Here
tabSize tab-size Here
tableLayout table-layout Here
textAlign text-align Here
textAlignLast text-align-last Here
textDecoration text-decoration Here
textDecorationColor text-decoration-color Here
textDecorationLine text-decoration-line Here
textDecorationStyle text-decoration-style Here
textIndent text-indent Here
91
top top Here
transform transform Here
transformOrigin transform-origin Here
transformStyle transform-style Here
transition transition Here
transitionDelay transition-delay Here
transitionDuration transition-duration Here
transitionProperty transition-property Here
transitionTimingFunction transition-timing-function Here
unicodeBidi unicode-bidi Here
userSelect user-select Here
verticalAlign vertical-align Here
visibility visibility Here
whiteSpace white-space Here
widows widows Here
width width Here
wordBreak word-break Here
wordSpacing word-spacing Here
wordWrap word-wrap Here
zIndex z-index Here
<sub>
[HTMLElementSub]
The HTML <sub> element indicates subscripted text.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<summary>
[HTMLElementSummary]
The HTML <summary> element indicates a heading for a <details> element. It is new in HTML 5.
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
92
<sup>
[HTMLElementSup]
The attributes it can take are HTML global attributes and HTML event attributes.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<table>
[HTMLElementTable]
The HTML <table> element indicates a table. It typically includes one or more <tr> elements and, within
them, <td> and/or <th> elements. More complicated table layouts can also include <caption>,
<col>, <colgroup>, <tbody>, <tfoot> and <thead> elements.
The attributes it can take are HTML global attributes and HTML event attributes.
It used to support the align, bgcolor, border, cellpadding, cellspacing, frame, rules, summary and width
attributes, but these are no longer supported by HTML 5. Original draft versions of HTML 5 also included
a sortable attribute, but this appears to have been dropped in later specifications and not to have been
implemented so far by major browsers.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. It also supports the following additional properties and
methods:
Additional properties:
Additional methods:
93
<tbody>
[HTMLElementTbody]
The HTML <tbody> element indicates the body of a table. It appears inside a <table> element and is used
in conjunction with <tfoot> and <thead> elements to differentiate between different parts of the table.
This can allow browsers to scroll the table body independently of the header and footer, or to allow
printing of the header and footer at the top and bottom of each page. A <tbody> element needs to come
after any <caption>, <colgroup> and <thead> elements. It needs to contain one or more <tr> elements.
The attributes it can take are HTML global attributes and HTML event attributes.
It used to support the align, char, charoff and valign attributes, but these are no longer supported by
HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<td>
[HTMLElementTd]
The HTML <td> element indicates a table cell (within a table row). They appear inside <tr> elements.
HTML tables contain two types of cells, i.e. header cells (<th> elements) and standard cells (<td>
elements), and the two are by default formatted differently.
The attributes it can take (in addition to HTML global attributes and HTML event attributes) are:
It used to support the abbr, align, axis, bgcolor, char, charoff, height, nowrap, scope, valign and width
attributes, but these are no longer supported by HTML 5.
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods. The default style applicable to this element is shown
here.
<textarea>
[HTMLElementTextarea]
94
The HTML <textarea> element indicates a multiline input control. It can hold an unlimited number of
characters, and the text used is typically rendered in a fixed-width font. The size of the text area can be
specified using the element’s cols and rows attributes or using corresponding CSS attributes.
The attributes it can take (other than HTML global attributes and HTML event attributes) include:
To create or access such an element in JavaScript see here. The corresponding HTML DOM object
supports standard DOM properties and methods, and additional properties with the same name and
meaning as the attributes of the underlying HTML element referred to above (with the maxlength and
readonly properties of the underlying element corresponding to the maxLength and readOnly properties
of the DOM object). It also supports the following additional properties and methods:
Additional properties:
Additional methods:
<tfoot>
[HTMLElementTfoot
95
96