Audio & Video HTML
Audio & Video HTML
What is HTML?
● HTML stands for Hyper Text Markup Language
● HTML is the standard markup language for creating Web pages
● HTML describes the structure of a Web page
● HTML consists of a series of elements
● HTML elements tell the browser how to display the content
● HTML elements label pieces of content such as "this is a heading", "this
is a paragraph", "this is a link", etc.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Example Explained
● The <!DOCTYPE html> declaration defines that this document is an
HTML5 document
● The <html> element is the root element of an HTML page
● The <head> element contains meta information about the HTML page
● The <title> element specifies a title for the HTML page (which is
shown in the browser's title bar or in the page's tab)
● The <body> element defines the document's body, and is a container
for all the visible contents, such as headings, paragraphs, images,
hyperlinks, tables, lists, etc.
● The <h1> element defines a large heading
● The <p> element defines a paragraph
<br> none
Web Browsers
The purpose of a web browser (Chrome, Edge, Firefox, Safari) is to read
HTML documents and display them correctly.
A browser does not display the HTML tags, but uses them to determine
how to display the document:
HTML Page Structure
Below is a visualization of an HTML page structure:
<html>
<head>
<title>Page title</title>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Note: The content inside the <body> section (the white area above) will
be
displayed in a browser. The content inside the <title> element will be
shown
in the browser's title bar or in the page's tab.
Year Version
HTML History
Since the early days of the World Wide Web, there have been many
versions of HTML:
This tutorial follows the latest HTML5 standard.
We believe in that using a simple text editor is a good way to learn HTML.
2014 HTML5
2017 HTML5.2
Follow the steps below to create your first web page with Notepad or
TextEdit.
Open the Start Screen (the window symbol at the bottom left on your
screen). Type Notepad.
Windows 7 or earlier:
Then under "Open and Save", check the box that says "Display HTML files
as HTML code instead of formatted text".
<!DOCTYPE html>
<html>
<body>
</body>
</html>
ADVERTISEMENT
Step 3: Save the HTML Page
Save the file on your computer. Select File > Save as in the Notepad
menu.
Name the file "index.htm" and set the encoding to UTF-8 (which is the
preferred encoding for HTML files).
Tip: You can use either .htm or .html as file extension. There is no
difference, it is up to you.
It is the perfect tool when you want to test code fast. It also has color
coding and the ability to save and share code with others:
Example
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
In this chapter we will show some basic HTML examples.
Don't worry if we use tags you have not learned about yet.
HTML DOCUMENTS
All HTML documents must start with a document type declaration: <!
DOCTYPE html>.
The HTML document itself begins with <html> and ends with </html>.
The visible part of the HTML document is between <body> and </body>.
EXAMPLE
<!DOCTYPE html>
<html>
<body>
It must only appear once, at the top of the page (before any HTML tags).
<!DOCTYPE html>
HTML HEADINGS
HTML headings are defined with the <h1> to <h6> tags.
<h1> defines the most important heading. <h6> defines the least important
heading:
EXAMPLE
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
ADVERTISEMENT
HTML PARAGRAPHS
HTML paragraphs are defined with the <p> tag:
EXAMPLE
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
HTML LINKS
HTML links are defined with the <a> tag:
EXAMPLE
<a href="https://www.googles.com">This is a link</a>
HTML IMAGES
HTML images are defined with the <img> tag.
The source file (src), alternative text (alt), width, and height are provided
as attributes:
EXAMPLE
<img src="googles.jpg" alt="Googles.com" width="104" height="142">
HTML ELEMENTS
An HTML element is defined by a start tag, some content, and an end
tag.
HTML ELEMENTS
The HTML element is everything from the start tag to the end tag:
<br> NONE
EXAMPLE
<!DOCTYPE html>
<html>
<body>
</body>
</html>
EXAMPLE EXPLAINED
The <html> element is the root element and it defines the whole HTML
document.
<body>
</body>
Then, inside the <body> element there are two other elements: <h1> and
<p>:
<p>This is a paragraph
<p>This is a paragraph
</body>
</html>
The <br> tag defines a line break, and is an empty element without a
closing tag:
EXAMPLE
<p>This is a <br> paragraph with a line break.</p>
Tag Description
HTML ATTRIBUTES
HTML ATTRIBUTES
● All HTML elements can have attributes
● Attributes provide additional information about elements
● Attributes are always specified in the start tag
● Attributes usually come in name/value pairs like: name="value"
You will learn more about links in our HTML Links chapter.
EXAMPLE
<img src="img_girl.jpg">
There are two ways to specify the URL in the src attribute:
Tip: It is almost always best to use relative URLs. They will not break if
you change domain.
EXAMPLE
<img src="img_girl.jpg" alt="Girl with a jacket">
EXAMPLE
See what happens if we try to display an image that does not exist:
You will learn more about images in our HTML Images chapter.
ADVERTISEMENT
EXAMPLE
<p style="color:red;">This is a red paragraph.</p>
You will learn more about styles in our HTML Styles chapter.
THE LANG ATTRIBUTE
You should always include the lang attribute inside the <html> tag, to
declare the language of the Web page. This is meant to assist search
engines and browsers.
<!DOCTYPE html>
<html lang="en">
<body>
...
</body>
</html>
Country codes can also be added to the language code in the lang
attribute. So, the first two characters define the language of the HTML page,
and the last two characters define the country.
<!DOCTYPE html>
<html lang="en-US">
<body>
...
</body>
</html>
You can see all the language codes in our HTML Language Code
Reference.
THE TITLE ATTRIBUTE
The title attribute defines some extra information about an element.
The value of the title attribute will be displayed as a tooltip when you
mouse over the element:
EXAMPLE
<p title="I'm a tooltip">This is a paragraph.</p>
The title attribute (and all other attributes) can be written with uppercase
or lowercase like title or TITLE.
GOOD:
<a href="https://www.googles.com/html/">Visit our HTML tutorial</a>
BAD:
<a href=https://www.googles.com/html/>Visit our HTML tutorial</a>
Sometimes you have to use quotes. This example will not display the
title attribute correctly, because it contains a space:
EXAMPLE
<p title=About Googles>
In some situations, when the attribute value itself contains double quotes,
it is necessary to use single quotes: <p title='John "ShotGun" Nelson'>
Or vice versa:
CHAPTER SUMMARY
● All HTML elements can have attributes
● The href attribute of <a> specifies the URL of the page the link goes
to
● The src attribute of <img> specifies the path to the image to be
displayed
● The width and height attributes of <img> provide size information for
images
● The alt attribute of <img> provides an alternate text for an image
● The style attribute is used to add styles to an element, such as color,
font, size, and more
● The lang attribute of the <html> tag declares the language of the Web
page
● The title attribute defines some extra information about an element
HTML EXERCISES
Top of Form
Submit Answer »
Bottom of Form
BACKGROUND COLOR
The CSS background-color property defines the background color for an
HTML element.
EXAMPLE
Set the background color for a page to powderblue:
<body style="background-color:powderblue;">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
EXAMPLE
Set background color for two different elements:
<body>
</body>
TEXT COLOR
The CSS color property defines the text color for an HTML element:
EXAMPLE
<h1 style="color:blue;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
FONTS
The CSS font-family property defines the font to be used for an HTML
element:
EXAMPLE
<h1 style="font-family:verdana;">This is a heading</h1>
<p style="font-family:courier;">This is a paragraph.</p>
TEXT SIZE
The CSS font-size property defines the text size for an HTML element:
EXAMPLE
<h1 style="font-size:300%;">This is a heading</h1>
<p style="font-size:160%;">This is a paragraph.</p>
TEXT ALIGNMENT
The CSS text-align property defines the horizontal text alignment for an
HTML element:
EXAMPLE
<h1 style="text-align:center;">Centered Heading</h1>
<p style="text-align:center;">Centered paragraph.</p>
The HTML <strong> element defines text with strong importance. The
content inside is typically displayed in bold.
EXAMPLE
<strong>This text is important!</strong>
ADVERTISEMENT
Tip: The <i> tag is often used to indicate a technical term, a phrase from
another language, a thought, a ship name, etc.
EXAMPLE
<i>This text is italic</i>
The HTML <em> element defines emphasized text. The content inside is
typically displayed in italic.
Tip: A screen reader will pronounce the words in <em> with an emphasis,
using verbal stress.
EXAMPLE
<em>This text is emphasized</em>
HTML <SMALL> ELEMENT
The HTML <small> element defines smaller text:
EXAMPLE
<small>This is some smaller text.</small>
EXAMPLE
<p>Do not forget to buy <mark>milk</mark> today.</p>
EXAMPLE
<p>My favorite color is <del>blue</del> red.</p>
EXAMPLE
<p>My favorite color is <del>blue</del> <ins>red</ins>.</p>
HTML <SUB> ELEMENT
The HTML <sub> element defines subscript text. Subscript text appears
half a character below the normal line, and is sometimes rendered in a
smaller font. Subscript text can be used for chemical formulas, like H O:
2
EXAMPLE
<p>This is <sub>subscripted</sub> text.</p>
EXAMPLE
<p>This is <sup>superscripted</sup> text.</p>
EXAMPLE
<p>Here is a quote from WWF's website:</p>
<blockquote cite="http://www.worldwildlife.org/who/index.html">
For 50 years, WWF has been protecting the future of nature.
The world's leading conservation organization,
WWF works in 100 countries and is supported
by 1.2 million members in the United States
and close to 5 million globally.
</blockquote>
HTML <Q> FOR SHORT QUOTATIONS
The HTML <q> tag defines a short quotation.
EXAMPLE
<p>WWF's goal is to: <q>Build a future where people live in harmony
with nature.</q></p>
ADVERTISEMENT
Tip: Use the global title attribute to show the description for the
abbreviation/acronym when you mouse over the element.
EXAMPLE
<p>The <abbr title="World Health Organization">WHO</abbr> was
founded in 1948.</p>
EXAMPLE
<address>
Written by John Doe.<br>
Visit us at:<br>
Example.com<br>
Box 564, Disneyland<br>
USA
</address>
EXAMPLE
<p><cite>The Scream</cite> by Edvard Munch. Painted in 1893.</p>
The HTML <bdo> tag is used to override the current text direction:
EXAMPLE
<bdo dir="rtl">This text will be written from right to left</bdo>
HTML COMMENT TAG
You can add comments to your HTML source by using the following
syntax:
Notice that there is an exclamation point (!) in the start tag, but not in
the end tag.
Note: Comments are not displayed by the browser, but they can help
document your HTML source code.
ADD COMMENTS
With comments you can place notifications and reminders in your HTML
code:
EXAMPLE
<!-- This is a comment -->
<p>This is a paragraph.</p>
HIDE CONTENT
Comments can be used to hide content.
EXAMPLE
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<!--
<p>Look at this cool image:</p>
<img border="0" src="pic_trulli.jpg" alt="Trulli">
-->
<p>This is a paragraph too.</p>
Comments are also great for debugging HTML, because you can comment
out HTML lines of code, one at a time, to search for errors.
ADVERTISEMENT
EXAMPLE
Hide a part of a paragaph:
HTML COLORS
HTML colors are specified with predefined color names, or with RGB,
HEX, HSL, RGBA, or HSLA values.
COLOR NAMES
In HTML, a color can be specified by using a color name:
Tomato
Orange
DodgerBlue
MediumSeaGreen
Gray
SlateBlue
Violet
LightGray
BACKGROUND COLOR
You can set the background color for HTML elements:
Hello World
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
nonummy
nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut
wisi
enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit
lobortis nisl ut aliquip ex ea commodo consequat.
EXAMPLE
<h1 style="background-color:DodgerBlue;">Hello World</h1>
<p style="background-color:Tomato;">Lorem ipsum...</p>
TEXT COLOR
You can set the color of text:
HELLO WORLD
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
EXAMPLE
<h1 style="color:Tomato;">Hello World</h1>
<p style="color:DodgerBlue;">Lorem ipsum...</p>
<p style="color:MediumSeaGreen;">Ut wisi enim...</p>
ADVERTISEMENT
BORDER COLOR
You can set the color of borders:
HELLO WORLD
HELLO WORLD
HELLO WORLD
EXAMPLE
<h1 style="border:2px solid Tomato;">Hello World</h1>
<h1 style="border:2px solid DodgerBlue;">Hello World</h1>
<h1 style="border:2px solid Violet;">Hello World</h1>
COLOR VALUES
In HTML, colors can also be specified using RGB values, HEX values, HSL
values, RGBA values, and HSLA values.
The following three <div> elements have their background color set with
RGB, HEX, and HSL values:
and HSLA values, which adds an Alpha channel to the color (here we have
50% transparency):
EXAMPLE
<h1 style="background-color:rgb(255, 99, 71);">...</h1>
<h1 style="background-color:#ff6347;">...</h1>
<h1 style="background-color:hsl(9, 100%, 64%);">...</h1>
Colors, Boxes
WHAT IS CSS?
Cascading Style Sheets (CSS) is used to format the layout of a webpage.
With CSS, you can control the color, font, the size of text, the spacing
between elements, how elements are positioned and laid out, what
background images or background colors are to be used, different displays
for different devices and screen sizes, and much more!
Tip: The word cascading means that a style applied to a parent element
will
also apply to all children elements within the parent. So, if you set the
color
of the body text to "blue", all headings, paragraphs, and other text
elements
within the body will also get the same color (unless you specify something
else)!
USING CSS
CSS can be added to HTML documents in 3 ways:
INLINE CSS
An inline CSS is used to apply a unique style to a single HTML element.
The following example sets the text color of the <h1> element to blue, and
the text color of the <p> element to red:
EXAMPLE
<h1 style="color:blue;">A Blue
paragraph.</p>
INTERNAL CSS
An internal CSS is used to define a style for a single HTML page.
The following example sets the text color of ALL the <h1> elements (on
that page) to blue, and the text color of ALL the <p> elements to red. In
addition, the page will be displayed with a "powderblue" background color:
EXAMPLE
<!DOCTYPE html>
<html>
<head> <style> body {background-
color: powderblue;} h1 {color:
blue;} p {color: red;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
EXTERNAL CSS
An external style sheet is used to define the style for many HTML pages.
EXAMPLE
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
The external style sheet can be written in any text editor. The file must
not contain any HTML code, and must be saved with a .css extension.
"STYLES.CSS":
body { background-color:
powderblue;
} h1 {
color: blue;
} p {
color: red;
}
Tip: With an external style sheet, you can change the look of an entire web
site, by changing one file!
EXAMPLE
Use of CSS color, font-family and font-size properties:
<!DOCTYPE html>
<html>
<head> <style> h1 {
color: blue; font-
family: verdana;
font-size: 300%;
} p { color: red;
font-family: courier;
font-size: 160%;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
CSS BORDER
The CSS border property defines a border around an HTML element.
Tip: You can define a border for nearly all HTML elements.
EXAMPLE
Use of CSS border property:
p {
border: 2px solid powderblue;
}
CSS PADDING
The CSS padding property defines a padding (space) between the text and
the border.
EXAMPLE
Use of CSS border and padding properties:
p {
border: 2px solid powderblue;
padding: 30px;
}
CSS MARGIN
The CSS margin property defines a margin (space) outside the border.
EXAMPLE
Use of CSS border and margin properties:
p {
border: 2px solid powderblue;
margin: 50px;
}
EXAMPLE
This example uses a full URL to link to a style sheet:
EXAMPLE
This example links to a style sheet located in the html folder on the current
web site:
<link rel="stylesheet"
href
="/html/styles.css"
>
Try it Yourself
»
EXAMPLE
HTML LINKS
Links are found in nearly all web pages. Links allow users to click their
way from page to page.
HTML LINKS - HYPERLINKS
HTML links are hyperlinks.
When you move the mouse over a link, the mouse arrow will turn into a
little hand.
Note: A link does not have to be text. A link can be an image or any other
HTML element!
The most important attribute of the <a> element is the href attribute,
which indicates the link's destination.
The LINK TEXT is the part that will be visible to the reader.
Clicking on the link text, will send the reader to the specified URL
address.
EXAMPLE
This example shows how to create a link to Schools.com:
Tip: Links can of course be styled with CSS, to get another look!
HTML LINKS - THE TARGET ATTRIBUTE
By default, the linked page will be displayed in the current browser
window. To change this, you must specify another target for the link.
EXAMPLE
Use target="_blank" to open the linked document in a new browser
window or tab:
EXAMPLE
<h2>Absolute URLs</h2>
<p><a href="https://www. .org/"> C</a></p>
<p><a href="https://www.google.com/">Google</a></p>
<h2>Relative URLs</h2>
<p><a href="html_images.asp">HTML Images</a></p>
<p><a href="/css/default.asp">CSS Tutorial</a></p>
HTML LINKS - USE AN IMAGE AS A LINK
To use an image as a link, just put the <img> tag inside the <a> tag:
EXAMPLE
<a href="default.asp"> <img
src="smiley.gif" alt="HTML
tutorial" style="width:42px;height:42px;">
</a>
EXAMPLE
<a href="mailto:[email protected]">Send email</a>
BUTTON AS A LINK
To use an HTML button as a link, you have to add some JavaScript code.
EXAMPLE
<button onclick="document.location='default.asp'">HTML
Tutorial</button>
EXAMPLE
<a href="https://www. schools.com/html/" title="Go to
Schools
HTML section">Visit our HTML Tutorial</a>
EXAMPLE
Link to a page located in the html folder on the current web site:
<a href="/html/default.asp"
>HTML tutorial
</a>
Try it Yourself
»
EXAMPLE
Link to a page located in the same folder as the current page:
EXAMPLE
Here, an unvisited link will be green with no underline. A visited link will
be pink with no underline. An active link will be yellow and underlined. In
addition, when mousing over a link (a:hover) it will become red and
underlined:
a:hover {
color: red;
background-
color:
transparent;
text-
decoration:
underline;
}
a:active { color: yellow;
background-color: transparent;
text-decoration: underline;
}
</style>
ADVERTISEMENT
LINK BUTTONS
A link can also be styled as a button, by using CSS:
This is a link
EXAMPLE
<style> a:link, a:visited
{ background-color:
#f44336; color: white;
padding: 15px 25px; text-
align: center; text-
decoration: none;
display: inline-block;
}
HTML IMAGES
Tag Description
Images can improve the design and the appearance of a web page.
EXAMPLE
<img src="pic_trulli.jpg" alt="Italian Trulli">
EXAMPLE
<img src="img_girl.jpg" alt="Girl in a jacket">
EXAMPLE
<img src="img_chania.jpg" alt="Flowers in Chania">
Images are not technically inserted into a web page; images are linked to
web pages. The <img> tag creates a holding space for the referenced image.
The <img> tag is empty, it contains attributes only, and does not have a
closing tag.
SYNTAX
<img src="url" alt="ALTERNATETEXT">
THE SRC ATTRIBUTE
The required src attribute specifies the path (URL) to the image.
Note: When a web page loads, it is the browser, at that moment, that
gets the image from a web server and inserts it into the page. Therefore,
make sure that the image actually stays in the same spot in relation to the
web page, otherwise your visitors will get a broken link icon. The broken link
icon and the alt text are shown if the browser cannot find the image.
EXAMPLE
<img src="img_chania.jpg" alt="Flowers in Chania">
ADVERTISEMENT
EXAMPLE
<img src="img_chania.jpg" alt="Flowers in Chania">
EXAMPLE
<img src="wrongname.gif" alt="Flowers in Chania">
Tip: A screen reader is a software program that reads the HTML code, and
allows the user to "listen" to the content. Screen readers are useful for
people who are visually impaired or learning disabled.
EXAMPLE
<img src="img_girl.jpg" alt="Girl in a
jacket" style="width:500px;height:600px;">
EXAMPLE
<img src="img_girl.jpg" alt="Girl in a
jacket" width="500" height="600">
The width and height attributes always define the width and height of the
image in pixels.
Note: Always specify the width and height of an image. If width and height
are not specified, the web page might flicker while the image loads.
EXAMPLE
<!DOCTYPE html>
<html>
<head>
<style> img {
width: 100%;
}
</style>
</head>
<body>
</body>
</html>
EXAMPLE
<img src="/images/html5.gif" alt="HTML5
Icon" style="width:128px;height:128px;">
EXAMPLE
<img src="https://www. schools.com/images/
schools_green.jpg" alt=" Schools.com">
EXAMPLE
<img src="programming.gif" alt="Computer
Man" style="width:48px;height:48px;">
IMAGE AS A LINK
To use an image as a link, put the <img> tag inside the <a> tag:
EXAMPLE
<a href="default.asp">
<img src="smiley.gif" alt="HTML
tutorial"
style="width:42px;height:42px;">
</a>
IMAGE FLOATING
Use the CSS float property to let the image float to the right or to the
left of a text:
EXAMPLE
<p><img src="smiley.gif" alt="Smiley face"
style="float:right;width:42px;height:42px;"> The
image will float to the right of the text.</p>
File
Abbreviation File Format
Extens
.jpg, .jpe
JPEG Joint Photographic Expert Group image
g,
Tip: To learn more about CSS Float, read our CSS Float Tutorial.
With HTML image maps, you can create clickable areas on an image.
IMAGE MAPS
The HTML <map> tag defines an image map. An image map is an image
with clickable areas. The areas are defined with one or more <area> tags.
Try to click on the computer, phone, or the cup of coffee in the image
below:
EXAMPLE
Here is the HTML source code for the image map above:
<map name="workmap">
<area shape="rect" coords="34,44,270,350" alt="Computer"
href="comput er.htm">
<area shape="rect" coords="290,172,333,250" alt="Phone"
href="phone.h tm">
<area shape="circle" coords="337,300,44" alt="Coffee"
href="coffee.ht m">
</map>
To create an image map you need an image, and some HTML code that
describes the clickable areas.
ADVERTISEMENT
THE IMAGE
The image is inserted using the <img> tag. The only difference from other
images is that you must add a usemap attribute:
The usemap value starts with a hash tag # followed by the name of the
image map, and is used to create a relationship between the image and the
image map.
The <map> element is used to create an image map, and is linked to the
image by using the required name attribute:
<map name="workmap">
The name attribute must have the same value as the <img>'s usemap
attribute
.
THE AREAS
Then, add the clickable areas.
SHAPE
You must define the shape of the clickable area, and you can choose one
of these values:
You must also define some coordinates to be able to place the clickable
area onto the image.
SHAPE="RECT"
The coordinates for shape="rect" come in pairs, one for the x-axis and
one for the y-axis.
So, the coordinates 34,44 is located 34 pixels from the left margin and 44
pixels from the top:
The coordinates 270,350 is located 270 pixels from the left margin and
350 pixels from the top:
This is the area that becomes clickable and will send the user to the page
"computer.htm":
SHAPE="CIRCLE"
To add a circle area, first locate the coordinates of the center of the
circle:
337,300
Then specify the radius of the circle:
44 pixels
This is the area that becomes clickable and will send the user to the page
"coffee.htm":
SHAPE="POLY"
The shape="poly" contains several coordinate points, which creates a
shape formed with straight lines (a polygon).
How can we make the croissant in the image below become a clickable
link?
We have to find the x and y coordinates for all edges of the croissant:
The coordinates come in pairs, one for the x-axis and one for the y-axis:
EXAMPLE
<area shape="poly"
coords="140,121,181,116,204,160,204,222,191,270,140,
329,85,355,58,352,37,322,40,259,103,161,128,147"
href="croissant.htm">
This is the area that becomes clickable and will send the user to the page
"croissant.htm":
HTML BACKGROUND IMAGES
EXAMPLE
Add a background image on a HTML element:
You can also specify the background image in the <style> element,
in the <head> section:
EXAMPLE
Specify the background image in the <style> element:
<style>
p { background-image:
url('img_girl.jpg');
}
</style>
EXAMPLE
Add a background image for the entire page:
<style>
body {
background-image: url('img_girl.jpg');
}
</style>
BACKGROUND REPEAT
If the background image is smaller than the element, the image will
repeat itself, horizontally and vertically, until it reaches the end of the
element:
EXAMPLE
<style> body { background-image:
url('example_img_girl.jpg'); }
</style>
EXAMPLE
<style>
body {
background-image: url('example_img_girl.jpg'); background-
repeat: no-repeat;
}
</style>
ADVERTISEMENT
BACKGROUND COVER
If you want the background image to cover the entire element, you can
set the background-size property to cover.
This way, the background image will cover the entire element, with no
stretching (the image will keep its original proportions):
EXAMPLE
<style> body { background-image:
url('img_girl.jpg'); background-
repeat: no-repeat; background-
attachment: fixed; background-size:
cover;
}
</style>
BACKGROUND STRETCH
If you want the background image to stretch to fit the entire element, you
can set the background-size property to 100% 100%:
Try resizing the browser window, and you will see that the image will
stretch, but always cover the entire element.
EXAMPLE
<style> body { background-image:
url('img_girl.jpg'); background-
repeat: no-repeat; background-
attachment: fixed; background-size:
100% 100%;
}
</style>
HTML TABLES
HTML tables allow web developers to arrange data into rows and
columns.
EXAMPLE
Company Contact
Try it Yourself »
EXAMPLE
A simple HTML table:
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
</table>
More Videos
TABLE CELLS
Each table cell is defined by a <td> and a </td>
Everything between <td> and </td> are the content of the table cell.
EXAMPLE
<table>
<tr>
<td>Emil</td>
<td>Tobias</td>
<td>Linus</td>
</tr>
</table>
Note: table data elements are the data containers of the table.
They can contain all sorts of HTML elements; text, images, lists, other
tables,
etc.
ADVERTISEMENT
TABLE ROWS
Each table row starts with a <tr> and end with a </tr> tag.
EXAMPLE
<table>
<tr>
<td>Emil</td>
<td>Tobias</td>
<td>Linus</td>
</tr>
<tr>
<td>16</td>
<td>14</td>
<td>10</td>
</tr>
</table>
You can have as many rows as you like in a table, just make sure that the
number of cells are the same in each row.
Note: There are times where a row can have less or more cells than
another.
You will learn about that in a later chapter.
TABLE HEADERS
Sometimes you want your cells to be headers, in those cases
use the <th> tag instead of the <td> tag:
EXAMPLE
Let the first row be table headers:
<table>
<tr>
<th>Person 1</th>
<th>Person 2</th>
<th>Person 3</th>
</tr>
<tr>
<td>Emil</td>
<td>Tobias</td>
<td>Linus</td>
</tr>
<tr>
<td>16</td>
<td>14</td>
<td>10</td>
</tr>
</table>
By default, the text in <th> elements are bold and centered, but you can
change that with CSS.
HTML EXERCISES
Top of Form
TEST YOURSELF WITH EXERCISES
EXERCISE:
Add a table row with two table headers.
Tag Description
The two table headers should have the value "Name" and "Age".
<table>
<tr>
<td>Jill Smith</td>
<td>50</td>
</tr>
</table>
Submit Answer »
Bottom of Form
HTML TABLE TAGS
EXAMPLE
table, th, td {
border: 1px solid black;
}
EXAMPLE
table, th, td { border:
1px solid black; border-
collapse: collapse;
}
ADVERTISEMENT
STYLE TABLE BORDERS
If you set a background color of each cell, and give the border a white
color (the same as the document background), you get the impression of an
invisible border:
E XAMPLE
table, th, td { border:
1px solid white; border-
collapse: collapse;
} th,
td {
background-color: #96D4D4;
}
EXAMPLE
table, th, td {
border: 1px solid black;
border-radius: 10px;
}
Skip the border around the table by leaving out table from the css
selector:
EXAMPLE
th, td {
border: 1px solid black;
border-radius: 10px;
}
● dotted
● dashed
● solid
● double
● groove
● ridge
● inset
● outset
● none
● hidden
EXAMPLE
th, td {
border-style: dotted;
}
BORDER COLOR
With the border-color property, you can set the color of the border.
EXAMPLE
th, td { border-
color: #96D4D4; }
EXAMPLE
table, th, td {
border: 1px solid black;
}
EXAMPLE
table, th, td { border:
1px solid black; border-
collapse: collapse;
}
ADVERTISEMENT
EXAMPLE
table, th, td {
border: 1px solid black;
border-radius: 10px;
}
Skip the border around the table by leaving out table from the css
selector:
EXAMPLE
th, td {
border: 1px solid black;
border-radius: 10px;
}
● dotted
● dashed
● solid
● double
● groove
● ridge
● inset
● outset
● none
● hidden
EXAMPLE
th, td {
border-style: dotted;
}
BORDER COLOR
With the border-color property, you can set the color of the border.
EXAMPLE
th, td {
border-color:
#96D4D4; }
HTML tables can have different sizes for each column, row or the
entire table.
Use the style attribute with the width or height properties to specify
the size of a table, row or column.
EXAMPLE
Set the width of the table to 100%:
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
Note: Using a percentage as the size unit for a width means how wide
will this element be compared to its parent element, which in this case is
the <body> element.
EXAMPLE
Set the width of the first column to 70%:
<table style="width:100%">
<tr>
<th style="width:70%">Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
To set the height of a specific row, add the style attribute on a table row
element:
EXAMPLE
Set the height of the second row to 200 pixels:
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr style="height:200px">
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
HTML EXERCISES
Top of Form
<table >
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Points</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
</table>
Bottom of Form
8:00
9:00
10:00
11:00
12:00
13:00
T
M W TH
U FRI
ON ED U
E
8:0
0
9:0
0
10:
00
11:
00
12:
00
DECEMBER
EXAMPLE
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
VERTICAL TABLE HEADERS
To use the first column as table headers, define the first cell in each row
as a th element:
EXAMPLE
<table>
<tr>
<th>Firstname</th>
<td>Jill</td>
<td>Eve</td>
</tr>
<tr>
<th>Lastname</th>
<td>Smith</td>
<td>Jackson</td>
</tr>
<tr>
<th>Age</th>
<td>94</td>
<td>50</td>
</tr>
</table>
ADVERTISEMENT
Jill Smith 50
Eve Jackson 94
Name Age
Jill Smith 50
Eve Jackson 94
Monthly savings
Month Savings
January $100
February $50
EXAMPLE
<table style="width:100%">
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$50</td>
</tr>
</table>
Note: The <caption> tag should be inserted immediately after
the <table> tag.
HTML EXERCISES
Top of Form
TEST YOURSELF WITH EXERCISES
EXERCISE:
Add a table caption that says "Names".
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Points</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
</table>
Bottom of Form
With Padding
With Spacing
hel hel hel
lo lo lo
hel hel hel
lo lo lo
hel hel hel
lo lo lo
EXAMPLE
th, td {
padding:
15px; }
To add padding only above the content, use the padding-top property.
EXAMPLE
th, td { padding-
top: 10px; padding-
bottom: 20px;
padding-left: 30px;
padding-right: 40px;
}
HTML TABLE - CELL SPACING
Cell spacing is the space between each cell.
EXAMPLE
table { border-
spacing: 30px;
}
NAME
APRIL
2022
FIESTA
EXAMPLE
<table>
<tr>
<th colspan="2">Name</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>43</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>57</td>
</tr>
</table>
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
EXAMPLE
<!DOCTYPE html>
<html>
<head>
100%;
th, td { text-
align: left;
padding: 8px;
tr:nth-child(even) { background-
color: #D6EEEE;
}
</style>
</head>
<body>
<p>For zebra-striped tables, use the nth-child() selector and add a background-color to all even
(or odd) table rows:</p>
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Points</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
<td>$100</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
<td>$150</td>
</tr>
<tr>
<td>Joe</td>
<td>Swanson</td>
<td>$300</td>
</tr>
<tr>
<td>Cleveland</td>
<td>Brown</td>
<td>$250</td>
</tr>
</table>
</body>
</html>
Note: If you use (odd) instead of (even), the styling will occur on row 1,3,5 etc. instead of
2,4,6 etc.
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
EXAMPLE
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
th:nth-child(even),td:nth-child(even) {
background-color: #D6EEEE;
</style>
</head>
<body>
<h2>Striped Table</h2>
<table style="width:100%">
<tr>
<th>MON</th>
<th>TUE</th>
<th>WED</th>
<th>THU</th>
<th>FRI</th>
<th>SAT</th>
<th>SUN</th>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
Use an rgba() color to specify the transparency of the color:
EXAMPLE
<!DOCTYPE html>
<html>
<head>
<style> table, th, td
border-collapse: collapse;
tr:nth-child(even) { background-color:
th:nth-child(even),td:nth-child(even) { background-
</style>
</head>
<body>
<h2>Striped Table</h2>
<tr>
<th>MON</th>
<th>TUE</th>
<th>WED</th>
<th>THU</th>
<th>FRI</th>
<th>SAT</th>
<th>SUN</th>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td> <td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table> </body>
</html>
HORIZONTAL DIVIDERS
First Name Last Name Savings
If you specify borders only at the bottom of each table row, you will have
a table with horizontal dividers.
EXAMPLE
<!DOCTYPE html>
<html>
<head>
<style> table { border-
100%;
}
tr { border-bottom: 1px solid
#ddd;
</style>
</head>
<body>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Savings</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
<td>$100</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
<td>$150</td>
</tr>
<tr>
<td>Joe</td>
<td>Swanson</td>
<td>$300</td>
</tr>
<tr>
<td>Cleveland</td>
<td>Brown</td>
<td>$250</td>
</tr>
</table>
</body>
</html>
HOVERABLE TABLE
Use the :hover selector on tr to highlight table rows on mouse over:
EXAMPLE
<!DOCTYPE html>
<html>
{ border-collapse:
th, td {
padding: 8px; text-align:
solid #DDD;
</style>
</head>
<body>
<h2>Hoverable Table</h2>
<p>Move the mouse over the table rows to see the effect.</p>
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Points</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
<td>$100</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
<td>$150</td>
</tr>
<tr>
<td>Joe</td>
<td>Swanson</td>
<td>$300</td>
</tr>
<tr>
<td>Cleveland</td>
<td>Brown</td>
<td>$250</td>
</tr>
</table>
</body>
</html>
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
The span attribute specifies how many columns that gets the style.
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td { border: 1px
collapse: collapse;
</style>
</head>
<body>
<h2>Colgroup</h2>
<p>Add the a colgroup with a col element that spans over two columns to define a style for the
two columns:</p>
<colgroup>
</colgroup>
<tr>
<th>MON</th>
<th>TUE</th>
<th>WED</th>
<th>THU</th>
<th>FRI</th>
<th>SAT</th>
<th>SUN</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
<tr>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
</tr>
<tr>
<td>15</td>
<td>16</td> <td>17</td>
<td>18</td>
<td>19</td>
<td>20</td>
<td>21</td>
</tr>
<tr>
<td>22</td>
<td>23</td>
<td>24</td>
<td>25</td>
<td>26</td>
<td>27</td>
<td>28</td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
border-collapse:
collapse;
</style>
</head>
<body>
<colgroup>
</colgroup>
<tr>
<th>MON</th>
<th>TUE</th>
<th>WED</th>
<th>THU</th>
<th>FRI</th>
<th>SAT</th>
<th>SUN</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
<tr>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
</tr>
<tr>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>20</td>
<td>21</td>
</tr>
<tr>
<td>22</td>
<td>23</td>
<td>24</td>
<td>25</td>
<td>26</td>
<td>27</td>
<td>28</td>
</tr>
</table> </body>
</html>
EMPTY COLGROUPS
If you want to style columns in the middle of a table, insert a
"empty" <col> element (with no styles) for the columns before:
<!DOCTYPE html>
<html>
<head>
<style>
collapse: collapse;
}
</style>
</head>
<body>
<h2>Empty Colgroups</h2>
<p>Add "empty" col elements that represents the columns before the columns you want to
style:</p>
<colgroup>
<col span="3">
</colgroup>
<tr>
<th>MON</th>
<th>TUE</th>
<th>WED</th>
<th>THU</th>
<th>FRI</th>
<th>SAT</th>
<th>SUN</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
<tr>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
</tr>
<tr>
<td>15</td>
<td>16</td>
<td>17</td> <td>18</td>
<td>19</td>
<td>20</td>
<td>21</td>
</tr>
<tr>
<td>22</td>
<td>23</td>
<td>24</td>
<td>25</td>
<td>26</td>
<td>27</td>
<td>28</td>
</tr>
</table>
</body>
</html>
HIDE COLUMNS
You can hide columns with the visibility: collapse property:
<!DOCTYPE html>
<html>
<head>
<style>
collapse: collapse;
</style>
</head>
<body>
<h2>Hide Columns</h2>
<colgroup>
<col span="2">
</colgroup>
<tr>
<th>MON</th>
<th>TUE</th>
<th>WED</th>
<th>THU</th>
<th>FRI</th>
<th>SAT</th>
<th>SUN</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
<tr>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
</tr>
<tr>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>20</td>
<td>21</td>
</tr>
<tr>
<td>22</td>
<td>23</td>
<td>24</td>
<td>25</td>
<td>26</td>
<td>27</td>
<td>28</td>
</tr>
</table>
<p><b>Note:</b> The table columns does not collapse properly in Safari browsers.</p> </body>
</html>
HTML FORMS
First name:
Last name:
An HTML form is used to collect user input. The user input is most
often sent to a server for processing
<!DOCTYPE html>
<html>
<body>
<h2>HTML Forms</h2>
<form action="/action_page.php">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page called
"/action_page.php".</p>
</body>
</html>
THE <FORM> ELEMENT
The HTML <form> element is used to create an HTML form for user input:
<form>
.
form elements
.
</form>
All the different form elements are covered in this chapter: HTML Form
Elements.
TEXT FIELDS
The <input type="text"> defines a single-line input field for text input.
<!DOCTYPE html>
<html>
<body>
<form>
</form>
<p>Also note that the default width of text input fields is 20 characters.</p>
</body>
</html>
First name:
Last name:
The <label> element is useful for screen-reader users, because the screen-
reader will read out loud the label when the user focus on the input element.
The <label> element also help users who have difficulty clicking on very
small regions (such as radio buttons or checkboxes) - because when the user
clicks the text within the <label> element, it toggles the radio
button/checkbox.
The for attribute of the <label> tag should be equal to the id attribute of
the <input> element to bind them together.
RADIO BUTTONS
The <input type="radio"> defines a radio button.
EXAMPLE
A form with radio buttons:
<!DOCTYPE html>
<html>
<body>
<h2>Radio Buttons</h2>
<form>
<label for="html">HTML</label><br>
<label for="css">CSS</label><br>
<label for="javascript">JavaScript</label>
</form>
</body>
</html>
HTML
CSS
JavaScript
CHECKBOXES
The <input type="checkbox"> defines a checkbox.
EXAMPLE
A form with checkboxes:
<!DOCTYPE html>
<html>
<body>
<h2>Checkboxes</h2>
<form action="/action_page.php">
</form>
</body>
</html>
I have a bike
I have a car
I have a boat
EXAMPLE
A form with a submit button:
<!DOCTYPE html>
<html>
<body>
<h2>HTML Forms</h2>
<form action="/action_page.php">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page called
"/action_page.php".</p>
</body>
</html>
First name:
Last name:
HE NAME ATTRIBUTE FOR <INPUT>
Notice that each input field must have a name attribute to be submitted.
If the name attribute is omitted, the value of the input field will not be sent
at all.
EXAMPLE
This example will not submit the value of the "First name" input field:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page called
"/action_page.php".</p>
<p>Notice that the value of the "First name" field will not be submitted, because the input element
does not have a name attribute.</p>
</body>
</html>
● <input>
● <label>
● <select>
● <textarea>
● <button>
● <fieldset>
● <legend>
● <datalist>
● <output>
● <option>
● <optgroup>
EXAMPLE
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
</form>
</body>
</html>
The <label> element is useful for screen-reader users, because the screen-
reader will read out loud the label when the user focus on the input element.
The <label> element also help users who have difficulty clicking on very
small regions (such as radio buttons or checkboxes) - because when the user
clicks the text within the <label> element, it toggles the radio
button/checkbox.
The for attribute of the <label> tag should be equal to the id attribute of
the <input> element to bind them together.
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
<input type="submit">
</form>
</body>
</html>
EXAMPLE
<!DOCTYPE html>
<html>
<body>
<h2>Pre-selected Option</h2>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</select>
<input type="submit">
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select><br><br>
<input type="submit">
</form>
</body>
</html>
ALLOW MULTIPLE SELECTIONS:
Use the multiple attribute to allow the user to select more than one value:
<!DOCTYPE html>
<html>
<body>
<p>Use the multiple attribute to allow the user to select more than one value.</p>
<form action="/action_page.php">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select><br><br>
<input type="submit">
</form>
<p>Hold down the Ctrl (windows) / Command (Mac) button to select multiple options.</p>
</body>
</html>
HE <TEXTAREA> ELEMENT
The <textarea> element defines a multi-line input field (a text area):
EXAMPLE
<!DOCTYPE html>
<html>
<body>
<h2>Textarea</h2>
<form action="/action_page.php">
<br><br>
<input type="submit">
</form>
</body>
</html>
The rows attribute specifies the visible number of lines in a text area.
You can also define the size of the text area by using CSS:
<!DOCTYPE html>
<html>
<body>
<h2>Styling Textarea</h2>
<form action="/action_page.php">
<br>
<input type="submit">
</form>
</body>
</html>
EXAMPLE
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Click Me!
THE <FIELDSET> AND <LEGEND> ELEMENTS
The <fieldset> element is used to group related data in a form.
<!DOCTYPE html>
<html>
<body>
<p>The fieldset element is used to group related data in a form, and the legend element defines a
caption for the fieldset element.</p>
<form action="/action_page.php">
<fieldset>
<legend>Personalia:</legend>
</fieldset>
</form>
</body>
</html>
Top of Form
Personalia:First name:
Last name:
Bottom of Form
Users will see a drop-down list of the pre-defined options as they input
data.
The list attribute of the <input> element, must refer to the id attribute
of the <datalist> element.
<!DOCTYPE html>
<html>
<body>
<p>The datalist element specifies a list of pre-defined options for an input element.</p>
<form action="/action_page.php">
<datalist id="browsers">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
<input type="submit">
</form>
<p><b>Note:</b> The datalist tag is not supported in Safari prior version 12.1.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php"
oninput="x.value=parseInt(a.value)+parseInt(b.value)">
100 +
<br><br>
<input type="submit">
</form>
<p><strong>Note:</strong> The output element is not supported in Edge prior version 13.</p>
</body>
</html>
<p>The output element represents the result of a calculation.</p>
+parseInt(b.value)">
100 +
<br><br>
<input type="submit">
</form>
<p><strong>Note:</strong> The output element is not supported in Edge prior version 13.</p>
</body>
</html>
This chapter describes the different types for the HTML <input> element.
Example
<!DOCTYPE html>
<html>
<body>
<h2>Text field</h2>
<form action="/action_page.php">
</form>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<body>
<h2>Password field</h2>
<p>The <strong>input type="password"</strong> defines a password
field:</p>
<form action="/action_page.php">
<label for="username">Username:</label><br>
<label for="pwd">Password:</label><br>
</form>
</body>
</html>
The form-handler is typically a server page with a script for processing input
data.
<!DOCTYPE html>
<html>
<body>
<h2>Submit Button</h2>
<p>The <strong>input type="submit"</strong> defines a button for
submitting form data to a form-handler:</p>
<form action="/action_page.php">
</form>
<p>If you click "Submit", the form-data will be sent to a page called
"/action_page.php".</p>
</body>
</html>
If you omit the submit button's value attribute, the button will get a default
text:
Example
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<input type="submit">
</form>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<body>
<h2>Reset Button</h2>
<form action="/action_page.php">
<input type="reset">
</form>
<p>If you change the input values and then click the "Reset" button, the
form-data will be reset to the default values.</p>
</body>
</html>
Radio buttons let a user select ONLY ONE of a limited number of choices:
Example
Example
Input Type Button
<input type="button"> defines a button:
Example
Depending on browser support, a color picker can show up in the input field.
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
</form>
</body>
</html>
Depending on browser support, a date picker can show up in the input field.
Example
<!DOCTYPE html>
<html>
<body>
<h2>Date Field</h2>
<form action="/action_page.php">
<label for="birthday">Birthday:</label>
</form>
</body>
</html>
Input Type Date
The <input type="date"> is used for input fields that should contain a date.
Depending on browser support, a date picker can show up in the input field.
Example
<!DOCTYPE html>
<html>
<body>
<h2>Date Field</h2>
<form action="/action_page.php">
<label for="birthday">Birthday:</label>
</form>
</body>
</html>
nput Type Datetime-local
The <input type="datetime-local"> specifies a date and time input field, with
no time zone.
Depending on browser support, a date picker can show up in the input field.
Example
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
</form>
</body>
</html>
Input Type Email
The <input type="email"> is used for input fields that should contain an e-mail
address.
Some smartphones recognize the email type, and add ".com" to the keyboard
to match email input.
<!DOCTYPE html>
<html>
<body>
<h2>Email Field</h2>
<form action="/action_page.php">
</form>
</body>
</html>
A hidden field lets web developers include data that cannot be seen or modified
by users when a form is submitted.
A hidden field often stores what database record that needs to be updated
when the form is submitted.
Note: While the value is not displayed to the user in the page's content, it is
visible (and can be edited) using any browser's developer tools or "View
Source" functionality. Do not use hidden inputs as a form of security!
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
</form>
</body>
</html>
Depending on browser support, a date picker can show up in the input field.
Example
<!DOCTYPE html>
<html>
<body>
<h2>Month Field</h2>
<form action="/action_page.php">
</form>
</body>
</html>
Input Type Number
The <input type="number"> defines a numeric input field.
The following example displays a numeric input field, where you can enter a
value from 1 to 5:
<!DOCTYPE html>
<html>
<body>
<h2>Number Field</h2>
<p>You can use the min and max attributes to add numeric restrictions
in the input field:</p>
<form action="/action_page.php">
</form>
</body>
</html>
Input Restrictions
Here is a list of some common input restrictions:
Attribute Description
The following example displays a numeric input field, where you can enter
a value from 0 to 100, in steps of 10. The default value is 30:
<!DOCTYPE html>
<html>
<body>
<h2>Numeric Steps</h2>
<form action="/action_page.php">
<label for="quantity">Quantity:</label>
</form>
</body>
</html>
Input Type Range
The <input type="range"> defines a control for entering a number whose exact
value is not important (like a slider control). Default range is 0 to 100.
However, you can set restrictions on what numbers are accepted with
the min, max, and step attributes:
<!DOCTYPE html>
<html>
<body>
<h2>Range Field</h2>
</form>
</body>
</html>
Input Type Search
The <input type="search"> is used for search fields (a search field behaves
like a regular text field).
<!DOCTYPE html>
<html>
<body>
<h2>Search Field</h2>
<form action="/action_page.php">
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h2>Search Field</h2>
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h2>Telephone Field</h2>
<form action="/action_page.php">
<small>Format: 123-45-678</small><br><br>
</body>
</html>
Depending on browser support, a time picker can show up in the input field.
<!DOCTYPE html>
<html>
<body>
<p>If the browser supports it, a time picker pops up when entering the
input field.</p>
<form action="/action_page.php">
</form>
</html>
Some smartphones recognize the url type, and adds ".com" to the keyboard to
match url input.
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
</form>
</body>
</html>
Input Type Week
The <input type="week"> allows the user to select a week and year.
Depending on browser support, a date picker can show up in the input field.
<!DOCTYPE html>
<html>
<body>
<p>If the browser supports it, a date picker pops up when entering the
input field.</p>
<form action="/action_page.php">
</form>
</body>
</html>
HTML Input Attributes
Example
Input fields with initial (default) values:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
</form>
</body>
</html>
A read-only input field cannot be modified (however, a user can tab to it,
highlight it, and copy the text from it).
The value of a read-only input field will be sent when submitting the form!
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
</form>
</body>
</html>
The disabled Attribute
The input disabled attribute specifies that an input field should be disabled.
The value of a disabled input field will not be sent when submitting the form!
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
</form>
</body>
</html>
The size Attribute
The input size attribute specifies the visible width, in characters, of an input
field.
Note: The size attribute works with the following input types: text, search, tel,
url, email, and password.
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<label for="pin">PIN:</label><br>
</form>
</body>
</html>
The maxlength Attribute
The input maxlength attribute specifies the maximum number of characters
allowed in an input field.
Note: When a maxlength is set, the input field will not accept more than the
specified number of characters. However, this attribute does not provide any
feedback. So, if you want to alert the user, you must write JavaScript code.
Example
Set a maximum length for an input field:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<label for="pin">PIN:</label><br>
</form>
</body>
</html>
The multiple Attribute
The input multiple attribute specifies that the user is allowed to enter more
than one value in an input field.
The multiple attribute works with the following input types: email, and file.
Example
A file upload field that accepts multiple values:
<!DOCTYPE html>
<html>
<body>
<p>The multiple attribute specifies that the user is allowed to enter more
than one value in an input field.</p>
<form action="/action_page.php">
</form>
<p>To select multiple files, hold down the CTRL or SHIFT key while
selecting.</p>
</body>
</html>
The pattern Attribute
The input pattern attribute specifies a regular expression that the input field's
value is checked against, when the form is submitted.
The pattern attribute works with the following input types: text, date, search,
url, tel, email, and password.
Tip: Use the global title attribute to describe the pattern to help the user.
Example
An input field that can contain only three letters (no numbers or special
characters):
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
</form>
</html>
The short hint is displayed in the input field before the user enters a value.
The placeholder attribute works with the following input types: text, search,
url, tel, email, and password.
Example
An input field with a placeholder text:
The required attribute works with the following input types: text, search, url,
tel, email, password, date pickers, number, checkbox, radio, and file.
Example
A required input field:
Tip: This attribute can be used together with the max and min attributes to
create a range of legal values.
The step attribute works with the following input types: number, range, date,
datetime-local, month, time and week.
Example
An input field with a specified legal number intervals:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<label for="points">Points:</label>
<input type="number" id="points" name="points" step="3">
<input type="submit">
</form>
</body>
</html>
Example
Let the "First name" input field automatically get focus when the page loads:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
</form>
</body>
</html>
Tip: Always specify both the height and width attributes for images. If height
and width are set, the space required for the image is reserved when the page
is loaded. Without these attributes, the browser does not know the size of the
image, and cannot reserve the appropriate space to it. The effect will be that
the page layout will change during loading (while the images load).
Example
Define an image as the submit button, with height and width attributes:
<!DOCTYPE html>
<html>
<body>
<h1>The input height and width attributes</h1>
<p>The height and width attributes specify the height and width of an input
type="image" element.</p>
<form action="/action_page.php">
</form>
</body>
</html>
Example
An <input> element with pre-defined values in a <datalist>:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<datalist id="browsers">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
</form>
</body>
</html>
The autocomplete Attribute
The input autocomplete attribute specifies whether a form or an input field
should have autocomplete on or off.
Autocomplete allows the browser to predict the value. When a user starts to
type in a field, the browser should display options to fill in the field, based on
earlier typed values.
The autocomplete attribute works with <form> and the following <input> types:
text, search, url, tel, email, password, datepickers, range, and color.
Example
An HTML form with autocomplete on, and off for one input field:
<!DOCTYPE html>
<html>
<body>
<p>Fill in and submit the form, then reload the page to see how
autocomplete works.</p>
<p>Notice that autocomplete is "on" for the form, but "off" for the
e-mail field!</p>
<label for="email">Email:</label>
</form>
</body>
</html>
The value of this attribute must be equal to the id attribute of the <form>
element it belongs to.
Example
An input field located outside of the HTML form (but still a part of the form):
The formaction Attribute
The input formaction attribute specifies the URL of the file that will process the
input when the form is submitted.
Note: This attribute overrides the action attribute of the <form> element.
The formaction attribute works with the following input types: submit and
image.
Example
An HTML form with two submit buttons, with different actions:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
</form>
</body>
</html>
Note: This attribute overrides the enctype attribute of the <form> element.
The formenctype attribute works with the following input types: submit and
image.
Example
A form with two submit buttons. The first sends the form-data with default
encoding, the second sends the form-data encoded as "multipart/form-data":
<!DOCTYPE html>
<html>
<body>
</form>
</body>
</html>
Note: This attribute overrides the method attribute of the <form> element.
The formmethod attribute works with the following input types: submit and
image.
Example
A form with two submit buttons. The first sends the form-data with
method="get". The second sends the form-data with method="post":
The form target Attribute
The input formtarget attribute specifies a name or a keyword that indicates
where to display the response that is received after submitting the form.
Note: This attribute overrides the target attribute of the <form> element.
The formtarget attribute works with the following input types: submit and
image.
Example
A form with two submit buttons, with different target windows:
Note: This attribute overrides the novalidate attribute of the <form> element.
The formnovalidate attribute works with the following input types: submit.
Example
A form with two submit buttons (with and without validation):
When present, novalidate specifies that all of the form-data should not be
validated when submitted.
Example
Specify that no form-data should be validated on submit:
HTML Canvas Graphic
The HTML <canvas> element is used to draw graphics on a web page.
The graphic to the left is created with <canvas>. It shows four elements: a
red rectangle, a gradient rectangle, a multicolor rectangle, and a multicolor
text.
The <canvas> element is only a container for graphics. You must use JavaScript
to actually draw the graphics.
Canvas has several methods for drawing paths, boxes, circles, text, and adding
images.
Canvas Examples
A canvas is a rectangular area on an HTML page. By default, a canvas has no
border and no content.
<html>
<body>
</canvas>
</body>
</html>
Add a JavaScript
After creating the rectangular canvas area, you must add a JavaScript to do the
drawing.
Draw a Line
<!DOCTYPE html>
<html>
<body>
<script>
var c = document.getElementById("myCanvas");
ctx.moveTo(0,0);
ctx.lineTo(200,100);
ctx.stroke();
</script>
</body>
</html>
Draw a Circle
<!DOCTYPE html>
<html>
<body>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.arc(95,50,40,0,2*Math.PI);
ctx.stroke();
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.arc(95,50,40,0,2*Math.PI);
ctx.stroke();
</script>
</body>
</html>
Draw a Text
<!DOCTYPE html>
<html>
<body>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.font = "30px Arial";
ctx.fillText("Hello World",10,50);
</script>
</body>
</html>
Stroke Text
<!DOCTYPE html>
<html>
<body>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.font = "30px Arial";
ctx.strokeText("Hello World",10,50);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Draw Image
<!DOCTYPE html>
<html>
<body>
<p>Image to use:</p>
<img id="scream" src="img_the_scream.jpg" alt="The Scream"
width="220" height="277">
<p>Canvas to fill:</p>
<canvas id="myCanvas" width="250" height="300"
style="border:1px solid #d3d3d3;">
Your browser does not support the HTML canvas tag.</canvas>
<script>
function myCanvas() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var img = document.getElementById("scream");
ctx.drawImage(img,10,10);
}
</script>
</body>
</html>
HTML SVG Graphics
What is SVG?
● SVG stands for Scalable Vector Graphics
● SVG is used to define graphics for the Web
● SVG is a W3C recommendation
SVG has several methods for drawing paths, boxes, circles, text, and graphic
images.
SVG Circle
<!DOCTYPE html>
<html>
<body>
</body>
</html>
SVG Rectangle
<!DOCTYPE html>
<html>
<body>
</body>
</html>
</body>
</html>
SVG Star
Example
SVG Logo
SVG
Example
SVG is XML based, which means that every element is available within the SVG
DOM. You can attach JavaScript event handlers for an element.
Canvas SVG
What is Multimedia?
Multimedia comes in many different formats. It can be almost anything you can
hear or see, like images, music, sound, videos, records, films, animations, and
more.
Web pages often contain multimedia elements of different types and formats.
Browser Support
The first web browsers had support for text only, limited to a single font in a
single color.
Later came browsers with support for colors, fonts, images, and multimedia!
Multimedia Formats
Multimedia elements (like audio or video) are stored in media files.
The most common way to discover the type of a file, is to look at the file
extension.
Note: Only MP4, WebM, and Ogg video are supported by the HTML standard.
MIDI .mid MIDI (Musical Instrument Digital Interface). Main format for all
.midi electronic music devices like synthesizers and PC sound cards.
MIDI files do not contain sound, but digital notes that can be
played by electronics. Plays well on all computers and music
hardware, but not in web browsers.
WMA .wma WMA (Windows Media Audio). Developed by Microsoft. Plays well
on Windows computers, but not in web browsers.
AAC .aac AAC (Advanced Audio Coding). Developed by Apple as the default
format for iTunes. Plays well on Apple computers, but not in web
browsers.
WAV .wav WAV. Developed by IBM and Microsoft. Plays well on Windows,
Macintosh, and Linux operating systems. Supported by HTML.
MP3 .mp3 MP3 files are actually the sound part of MPEG files. MP3 is the
most popular format for music players. Combines good
compression (small files) with high quality. Supported by all
browsers.
MP4 .mp4 MP4 is a video format, but can also be used for audio. Supported
by all browsers.
Note: Only MP3, WAV, and Ogg audio are supported by the HTML standard.
HTML Multimedia
What is Multimedia?
Multimedia comes in many different formats. It can be almost anything you can
hear or see, like images, music, sound, videos, records, films, animations, and
more.
Web pages often contain multimedia elements of different types and formats.
Browser Support
The first web browsers had support for text only, limited to a single font in a
single color.
Later came browsers with support for colors, fonts, images, and multimedia!
Multimedia Formats
Multimedia elements (like audio or video) are stored in media files.
The most common way to discover the type of a file, is to look at the file
extension.
Note: Only MP4, WebM, and Ogg video are supported by the HTML standard.
MIDI .mi MIDI (Musical Instrument Digital Interface). Main format for all
d electronic music devices like synthesizers and PC sound cards.
MIDI files do not contain sound, but digital notes that can be
.mi played by electronics. Plays well on all computers and music
di hardware, but not in web browsers.
WAV .wa WAV. Developed by IBM and Microsoft. Plays well on Windows,
v Macintosh, and Linux operating systems. Supported by HTML.
MP3 .m MP3 files are actually the sound part of MPEG files. MP3 is the
p3 most popular format for music players. Combines good
compression (small files) with high quality. Supported by all
browsers.
MP4 .m MP4 is a video format, but can also be used for audio.
p4 Supported by all browsers.
Example
<audio controls>
</audio>
The <source> element allows you to specify alternative audio files which the
browser may choose from. The browser will use the first recognized format.
The text between the <audio> and </audio> tags will only be displayed in
browsers that do not support the <audio> element.
HTML <audio> Autoplay
To start an audio file automatically, use the autoplay attribute:
Example
</audio>
Note: Chromium browsers do not allow autoplay in most cases. However, muted
autoplay is always allowed.
Add muted after autoplay to let your audio file start playing automatically (but
muted):
Example
</audio>
HTML Audio Formats
There are three supported audio formats: MP3, WAV, and OGG. The browser
support for the different formats is:
Browser MP3 WAV OGG
MP3 audio/mpeg
OGG audio/ogg
WAV audio/wav
Tag Description
HTML5 supports <video> and <audio> controls. The Flash, Silverlight and similar technologies
are used to play the multimedia items.
this table defines that which web browser supports which audio file format.
Browser mp3 wav ogg
<audio controls>
</audio>
Let's see the example to play ogg file using HTML audio tag.
1. <audio controls>
2. <source src="koyal.ogg" type="audio/ogg">
3. Your browser does not support the html audio tag.
4. </audio>
Supporting Browsers
Element Chrome IE Firefox Opera Safari
Attribut Description
e
autoplay It specifies that the audio will start playing as soon as it is ready.
loop It specifies that the audio file will start over again, every time
when it is completed.
preload It specifies the author view to upload audio file when the page
loads.
mp3 audio/mpeg
ogg audio/ogg
wav audio/wav
HTML Video
The HTML <video> element is used to show a video on a web page.
<p>
Video courtesy of
<a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck
Bunny</a>.
</p>
</body>
</html>
Example
</video>
How it Works
The controls attribute adds video controls, like play, pause, and volume.
It is a good idea to always include width and height attributes. If height and
width are not set, the page might flicker while the video loads.
The <source> element allows you to specify alternative video files which the
browser may choose from. The browser will use the first recognized format.
The text between the <video> and </video> tags will only be displayed in
browsers that do not support the <video> element.
Example
</video>
Note: Chromium browsers do not allow autoplay in most cases. However, muted
autoplay is always allowed.
Add muted after autoplay to let your video start playing automatically (but
muted):
Example
</video>
MP4 video/mp4
WebM video/webm
Ogg video/ogg
HTML Video - Methods, Properties, and Events
The HTML DOM defines methods, properties, and events for the <video>
element.
This allows you to load, play, and pause videos, as well as setting duration
and volume.
There are also DOM events that can notify you when a video begins to play,
is paused, etc.
<!DOCTYPE html>
<html>
<body>
<div style="text-align:center">
<button onclick="playPause()">Play/Pause</button>
<button onclick="makeBig()">Big</button>
<button onclick="makeSmall()">Small</button>
<button onclick="makeNormal()">Normal</button>
<br><br>
<video id="video1" width="420">
<source src="mov_bbb.mp4" type="video/mp4">
<source src="mov_bbb.ogg" type="video/ogg">
Your browser does not support HTML video.
</video>
</div>
<script>
var myVideo = document.getElementById("video1");
function playPause() {
if (myVideo.paused)
myVideo.play();
else
myVideo.pause();
}
function makeBig() {
myVideo.width = 560;
}
function makeSmall() {
myVideo.width = 320;
}
function makeNormal() {
myVideo.width = 420;
}
</script>
</body>
</html>
Tag Description
HTML 5 supports <video> tag also. The HTML video tag is used for streaming video files such
as a movie clip, song clip on the web page.
Currently, there are three video formats supported for HTML video tag:
1. mp4
2. webM
3. ogg
Let's see the table that defines which web browser supports video file
format.
1. <video controls>
2. <source src="movie.mp4" type="video/mp4">
3. Your browser does not support the html video tag.
4. </video>
Let's see the example to play ogg file using HTML video tag.
1. <video controls>
2. <source src="movie.ogg" type="video/ogg">
3. Your browser does not support the html video tag.
4. </video>
Supporting Browsers
Attribu Description
te
poster It specifies the image which is displayed on the screen when the
video is not played.
autopla It specifies that the video will start playing as soon as it is ready.
y
loop It specifies that the video file will start over again, every time
when it is completed.
preload It specifies the author view to upload video file when the page
loads.
mp4 video/mp4
ogg video/ogg
webM video/webM
HTML Plug-ins
Plug-ins are computer programs that extend the standard functionality of
the browser.
Plug-ins
Plug-ins were designed to be used for many different purposes:
Warning !
Most browsers no longer support Java Applets and Plug-ins.
ActiveX controls are no longer supported in any browsers.
The support for Shockwave Flash has also been turned off in modern
browsers.
It was designed to embed plug-ins (like Java applets, PDF readers, and Flash
Players) in web pages, but can also be used to include HTML in HTML:
Example
Example
<object data="audi.jpeg"></object>
The <embed> Element
The <embed> element is supported in all major browsers.
Web browsers have supported the <embed> element for a long time. However,
it has not been a part of the HTML specification before HTML5.
Example
<embed src="audi.jpeg">
Note that the <embed> element does not have a closing tag. It can not contain
alternative text.
Example
An easier solution is to let YouTube play the videos in your web page.
YouTube Video Id
YouTube will display an id (like tgbNymZ7vqY), when you save (or play) a
video.
You can use this id, and refer to your video in the HTML code.
Example
src="https://www.youtube.com/">
</iframe>
YouTube Autoplay + Mute
You can let your video start playing automatically when a user visits the page,
by adding autoplay=1 to the YouTube URL. However, automatically starting a
video is annoying for your visitors!
Note: Chromium browsers do not allow autoplay in most cases. However, muted
autoplay is always allowed.
Add mute=1 after autoplay=1 to let your video start playing automatically (but
muted).
src="https://www.youtube.com/">
</iframe>
YouTube Playlist
A comma separated list of videos to play (in addition to the original URL).
YouTube Loop
Add loop=1 to let your video loop forever.
YouTube - Loop
<iframe width="420" height="315"
src="https://www.youtube.com/">
</iframe>
YouTube Controls
Add controls=0 to not display controls in the video player.
YouTube - Controls
src="https://www.youtube.com/">
</iframe>
5. <video controls>
6. <source src="movie.mp4" type="video/mp4">
7. Your browser does not support the html video tag.
8. </video>
Let's see the example to play ogg file using HTML video tag.
5. <video controls>
6. <source src="movie.ogg" type="video/ogg">
7. Your browser does not support the html video tag.
8. </video>
Supporting Browsers
Attribu Description
te
poster It specifies the image which is displayed on the screen when the
video is not played.
autopla It specifies that the video will start playing as soon as it is ready.
y
loop It specifies that the video file will start over again, every time
when it is completed.
preload It specifies the author view to upload video file when the page
loads.
src It specifies the source URL of the video file.
mp4 video/mp4
ogg video/ogg
webM video/webM
HTML Plug-ins
Plug-ins are computer programs that extend the standard functionality of
the browser.
Plug-ins
Plug-ins were designed to be used for many different purposes:
Warning !
Most browsers no longer support Java Applets and Plug-ins.
ActiveX controls are no longer supported in any browsers.
The support for Shockwave Flash has also been turned off in modern
browsers.
It was designed to embed plug-ins (like Java applets, PDF readers, and Flash
Players) in web pages, but can also be used to include HTML in HTML:
Example
Example
<object data="audi.jpeg"></object>
Web browsers have supported the <embed> element for a long time. However,
it has not been a part of the HTML specification before HTML5.
Example
<embed src="audi.jpeg">
Note that the <embed> element does not have a closing tag. It can not contain
alternative text.
Example
An easier solution is to let YouTube play the videos in your web page.
YouTube Video Id
YouTube will display an id (like tgbNymZ7vqY), when you save (or play) a
video.
You can use this id, and refer to your video in the HTML code.
src="https://www.youtube.com/">
</iframe>
Note: Chromium browsers do not allow autoplay in most cases. However, muted
autoplay is always allowed.
Add mute=1 after autoplay=1 to let your video start playing automatically (but
muted).
src="https://www.youtube.com/">
</iframe>
YouTube Playlist
A comma separated list of videos to play (in addition to the original URL).
YouTube Loop
Add loop=1 to let your video loop forever.
YouTube - Loop
src="https://www.youtube.com/">
</iframe>
YouTube Controls
Add controls=0 to not display controls in the video player.
YouTube - Controls
src="https://www.youtube.com/">
</iframe>