Chapter 2 - Introduction to HTML
Chapter 2 - Introduction to HTML
Development &
Application
INTRODUCTION TO HTML
Introduction to 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.
What is an HTML Element?
An HTML element is defined by a start tag, some content, and an end tag:
<tagname> Content goes here... </tagname>
The HTML element is everything from the start tag to the end tag:
<h1>My First Heading</h1>
<p>My first paragraph.</p>
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Empty HTML Elements
HTML empty elements (also known as self-closing or void elements) are
elements that do not have any content or closing tags. They represent
elements that are complete in themselves and do not require any child
elements. Some of the most common empty elements in HTML include:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
We will have…
HTML Attributes
With a code like this:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
We will have…
HTML Attributes
With a code like this:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
We will have…
HTML Attributes
The style Attribute
The style attribute is used to add styles to an element, such as color, font, size, and more.
• <p style="color:red;">This is a red paragraph.</p>
<!DOCTYPE html>
<html lang="en-US">
<body>
...
</body>
</html>
<!DOCTYPE html>
<html lang="en-US">
<body>
<h2 style="color: red;">The title Attribute</h2>
<p title="I'm a tooltip">Mouse over this paragraph, to display the title attribute as a
tooltip.</p>
</body>
</html>
Or vice versa:
• <p title="John 'ShotGun' Nelson">
HTML Style Attribute
The HTML style attribute is used to add styles to an element, such as color, font, size, and more.
Setting the style of an HTML element, can be done with the style attribute.
<body style="background-color:powderblue;">
<h1 style="color:blue;>This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
</body>
HTML Colors
HTML colors are specified with predefined color names, or with RGB, HEX, HSL, RGBA, or HSLA values.
HTML supports 140 standard color names. https://www.w3schools.com/colors/colors_names.asp
Color Values
I am a color red
HTML Style Attribute
Fonts family, size, style, weight and alignment
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Text Formatting
Formatting elements were designed to display special types of text:
</body>
</html>
HTML Quotations and Citations
The HTML <blockquote> element defines a <!DOCTYPE html>
<html>
section that is quoted from another source.
<body>
Browsers usually indent <blockquote> elements.
<p>Here is a quote from WWF's website:</p>
The HTML <q> tag defines a short quotation.
Browsers normally insert quotation marks around <blockquote
the quotation. cite="www.worldwildlife.org/who/index.html"><q>For 60
years, <abbr title="World Wild Life">WWF</abbr> has
worked to help people and nature thrive.</q> As the
The HTML <abbr> tag defines an abbreviation or
world's leading conservation organization, WWF works in
an acronym, like "HTML", "CSS", "Mr.", "Dr.", nearly 100 countries. At every level, we collaborate
"ASAP", "ATM". with people around the world to develop and deliver
Marking abbreviations can give useful innovative solutions that protect communities,
information to browsers, translation systems and wildlife, and the places in which they live.
search-engines. </blockquote>
</body>
</html>
Creating your first HTML file
Before you start coding, you need to set up the file for the correct programming language. This is done by
saving the file with the appropriate file extension for HTML.
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.
HTML Comments
Example:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
HTML Comments
Hide Content
Comments can be used to hide content.
This can be helpful if you hide content temporarily:
Example:
<!DOCTYPE html>
<html>
<body>
<p>This is a paragraph.</p>
</body>
</html>
HTML Links
Links are found in nearly all web pages. Links allow users to click their way from page to page.
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!
HTML Links
HTML Links - Syntax
The HTML <a> tag defines a hyperlink. It has
the following syntax:
Example:
<a href="https://www.example.com/">Visit
example.com!</a>
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.
_self - Default. Opens the document in the same window/tab as it was clicked
_blank - Opens the document in a new window or tab
_parent - Opens the document in the parent frame
_top - Opens the document in the full body of the window
Link Colors
An HTML link is displayed in a different color depending on whether it has been visited, is
unvisited, or is active.
Then, add a link to the bookmark ("Jump to Chapter 4"), from within the same page:
Example:
<a href="#C4">Jump to Chapter 4</a>
Absolute URLs vs. Relative
URLs
Absolute URLs
An absolute URL contains the complete address required to locate a resource on the web. It
includes the protocol (http/https), domain name, and the path to the specific file or resource.
Components of an Absolute URL:
• Protocol: http:// or https://
• Domain name: The main address of the website (e.g., www.example.com).
• Path: The file or resource path (e.g., /images/picture.jpg).
Relative URLs
A relative URL provides a shorthand link to a resource that is located relative to the current
document or directory. It does not include the domain name or protocol, just the path to the
resource from the current location.
HTML Tables
A table in HTML consists of table cells inside rows and columns.
Table Rows
Each table row starts with a <tr> and ends with a </tr> tag, tr stands for table row.
Table Cells
Each table cell is defined by a <td> and a </td> tag, td stands for table data.
Table Headers
Sometimes you want your cells to be table header cells. In those cases use the <th> tag
instead of the <td> tag, th stands for table header
HTML Tables
<table style="width:100%;" border="1">
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
To avoid having double borders like in the example above, set the
<td>Alfreds Futterkiste</td>
CSS border-collapse property to collapse.
<td>Maria Anders</td>
<td>Germany</td> <table style="width:100%; border-collapse: collapse;" border="1">
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
</table>
HTML Tables: Colspan and
Rowspan
HTML Table - Colspan
To make a cell span over multiple columns, use the colspan attribute:
<table style="width:100%">
<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>
HTML Tables: Colspan and
Rowspan
HTML Table - Colspan
To make a cell span over multiple rows, use the rowspan attribute:
<table style="width:100%">
<tr>
<th>Name</th>
<td>Jill</td>
</tr>
<tr>
<th rowspan="2">Phone</th>
<td>555-1234</td>
</tr>
<tr>
<td>555-8745</td>
</tr>
</table>
HTML Tables: Colgroup
The <colgroup> element is used to style specific columns of a table.
The <colgroup> element should be used as a container for the column specifications.
The span attribute specifies how many columns that get the style.
The list items will be marked with bullets (small black circles) by default:
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Unordered HTML List - Choose List
Item Marker
The CSS list-style-type property is used to define the style of the list item marker. It can
have one of the following values:
Unordered HTML List - Choose List
Item Marker
Unodered List with different list-style-type examples:
<ul style="list-style-type:disc;">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<ul style="list-style-type:circle;">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<ul style="list-style-type:square;">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<ul style="list-style-type:none;">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Ordered HTML List
Ordered HTML List
An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Ordered HTML List - The Type
Attribute
The type attribute of the <ol> tag, defines the type of the list item marker:
Ordered HTML List - The Type
Attribute
Ordered List example with different types:
<ol type="1">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
<ol type="A">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
<ol type="a">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
<ol type="I">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
<ol type="i">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
HTML Description Lists
A description list is a list of terms, with a description of each term.
The <dl> tag defines the description list, the <dt> tag defines the term (name), and the <dd>
tag describes each term:
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
HTML Images
The HTML <img> tag is used to embed an image in a web page.
The <img> tag has two required attributes:
• src - Specifies the path to the image
• alt - Specifies an alternate text for the 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.
To create an image map you need an image, and some HTML code that describes the
clickable areas.
HTML Image Maps
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 <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.
HTML Image Maps
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:
So, the coordinates 34,44 is located 34 pixels from the left margin
and 44 pixels from the top:
HTML Image Maps
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:
Shape="poly"
The shape="poly" contains several coordinate points, which
creates a shape formed with straight lines (a polygon).
Each <source> element has a media attribute that defines when the image is
the most suitable.
<picture>
<source media="(min-width: 650px)" srcset="img_food.jpg">
<source media="(min-width: 465px)" srcset="img_car.jpg">
<img src="img_girl.jpg" style="width:auto;">
</picture>
HTML Multimedia
HTML Media
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.
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.
Multimedia files have formats and different extensions
like: .wav, .mp3, .mp4, .mpg, .wmv, and .avi.
HTML Multimedia
Common Video Formats:
HTML Multimedia
Common Audio Formats:
HTML Video
The HTML <video> Element
To show a video in HTML, use the <video> element:
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.
HTML Audio
To play an audio file in HTML, use the <audio> element:
How it Works
The controls attribute adds audio controls, like play, pause, and volume.
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.