HTML
HTML
Krishnan T
Subject Matter Expert
TrainLab Academy
Introduction
Every website has two parts:
Front-end
Back-end
The front end is responsible for the visual look and feel of the website
or app that a user will interact with (the client side). The front-end is
built using a combination of technologies such as Hypertext Markup
Language (HTML), JavaScript and Cascading Style Sheets (CSS).
Back end development focuses on the side of a website users can't see
(the server side).
A full stack developer is someone who works with both the front end
and back end of a web application.
HTML
HTML stands for Hyper Text Markup Language.
HTML is the standard markup language for creating Web
pages.
With HTML you can create your own Website.
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 Element
An HTML element is defined by a start tag, some content, and
an end tag:
<tagname>Content goes here...</tagname>
Example:
Start tag Elementcontent Endtag
<h1> My First Heading </h1>
<p> My first paragraph. </p>
<br> none none
Example
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
</body>
</html
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
HTML Editors
TextEdit (Mac).
Step 1: Open Notepad (PC)
Windows 8 or later:
◦ Open the Start Screen (the window symbol at the bottom left on your screen).
Type Notepad.
Windows 7 or earlier:
◦ Open Start > Programs > Accessories > Notepad
Step 2: Write Some HTML
◦ Write or copy the following HTML code into Notepad
<!DOCTYPE html>
HTML Headings
HTML headings are defined with the <h1> to <h6> tags.
<h1> defines the most important heading.
Example: Output:
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>
Example: Describe metadata within an HTML document:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="Free Web tutorials">
<meta name="keywords" content="HTML,CSS,XML,JavaScript">
</head>
<body>
</body>
</html>
Examples
Define keywords for search engines:
devices:
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
HTML Paragraphs
HTML paragraphs are defined with the <p> tag.
HTML Links
HTML links are defined with the <a> tag.
Example:
<a href="https://www.google.com">Clickhere for link</a>
The link's destination is specified in the href attribute.
Attributes are used to provide additional information
about HTML elements.
HTML Images
Example:
<img src=“image.jpg" alt=“google.com" width="104"
height="142">
<audio controls>
<source src=“PATH" type="audio/mp3">
</audio>
Other Attributes:
autoplay,loop,muted
HTML Elements
<img src="img.jpg">
There are two ways to specify the URL in the src attribute:
Absolute URL - Links to an external image that is hosted on another
website.
src=" https://www.caranddriver.com/shopping-advice/g26100588/car-types/
".
Relative URL - Links to an image that is hosted within the website. Here, the
URL does not include the domain name. If the URL begins without a slash,
it will be relative to the current page.
src="img_girl.jpg".
If the URL begins with a slash, it will be relative to the domain.
src="/images/img_girl.jpg".
Tip: It is almost always best to use relative URLs. They will not break if you
change domain.
The alt Attribute
The required alt attribute for the <img> tag specifies an
<!DOCTYPE html>
<html>
<body>
<h2>English</h2>
<p lang="en">This is demo text</p>
<h2>French</h2>
<p lang="fr">Ceci est un texte de démonstration</p>
<h2>Spanish</h2>
<p lang="es">Este es un texto de demostración</p>
</body>
</html>
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
<!DOCTYPE html>
<html>
<body>
<p><abbr title="World Health Organization">WHO</abbr> was
founded in 1948.</p>
<p title=“HTML tutorials">Ethnotech.com</p>
</body>
</html>
specify the size for any heading with the style attribute, using
the CSS font-size property:
<h1 style="font-size:60px;">Heading 1</h1>
Output:
HTML Styles and Colors
The HTML style attribute is used to add styles to an element, such as color, font,
size, and more.
Syntax: <tagname style="property: value;">
Example:
Text Color
The CSS color property defines the text color for an HTML element
Background Color
Set the background color for a page to powderblue.
HTML element.
<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.
<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
Color Values
Colors can also be specified using RGB values, HEX values, HSL
sources.
An RGBA color value is an extension of RGB with an Alpha
channel (opacity).
colors!
For example, rgb(255, 0, 0) is displayed as red, because red is set
to its highest value (255), and the other two (green and blue) are
set to 0.
Experiment by mixing the RGB values below:
RGBA Color Values
rgba(red, green, blue, alpha)
The alpha parameter is a number between 0.0 (fully
its highest value (ff), and the other two (green and blue) are
set to 00.
To display black, set all color parameters to #000000.
white.
HTML Text Formatting
Formatting elements were designed to display special
types of text:
<b> - Bold text
<strong> - Important text
<i> - Italic text
<em> - Emphasized text
<mark> - Marked text
<small> - Smaller text
<del> - Deleted text
<ins> - Inserted text //underline inserted text
<sub> - Subscript text
<sup> - Superscript text
Example:
<!DOCTYPE html>
<html>
<body>
<p><b>This text is bold</b></p>
<p><i>This text is italic</i></p>
<p>This is<sub> subscript</sub> and <sup>superscript</sup></p>
<p><em>This text is emphasized.</em></p>
<p>Do not forget to buy <mark>milk</mark> today.</p>
</body>
</html>
direction.
<bdo dir="rtl">This text will be written from right to left</bdo>
HTML Comments
Comments are not displayed by the browser, but they can help
document your HTML source code.
You can also hide more than one line, everything between
the <!-- and the --> will be hidden from the display.
Comments can be used to hide parts in the middle of the HTML
code.
<!-- Write your comments here -->
Example:
<!-- This is a comment -->
<p>This is a paragraph.</p>
<p>This <!-- great text (inline comment) --> is a paragraph.</p>
HTML Styles - CSS
CSS stands for Cascading Style Sheets.
Cascading Style Sheets (CSS) is used to format the layout of a
webpage. It can control the layout of multiple web pages all at
once.
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!
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)!
CSS can be added to HTML documents in 3 ways:
Inline - by using the style attribute inside HTML elements
Internal - by using a <style> element in the <head> section
External - by using a <link> element to link to an external CSS
file
Inline CSS:
An inline CSS is used to apply a unique style to a single HTML
element.
An inline CSS uses the style attribute of an HTML element.
Example:
<h1 style="color:blue;">A Blue Heading</h1>
<p style="color:red;">A red paragraph.</p>
Internal CSS
An internal CSS is used to define a style for a single HTML page.
To use an external style sheet, add a link to it in the <head> section of each HTML
page.
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
< ! - -save as "styles.css": - - >
body {
background-color: powderblue;
}
h1 {
color: blue;
}
p{
color: red;
}
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.
With an external style sheet, you can change the look of an entire
web site, by changing one file!
HTML Links
HTML links are hyperlinks.
The HTML <a> tag defines a hyperlink.
<!DOCTYPE html>
<html>
<body>
<h3>HTML Links</h3>
<a href="https://www.google.com/"> Visit Google !</a>
</body>
</html>
The target Attribute
By default, the linked page will be displayed in the current
slash basically tells the browser to go to the domain of the site. A local link (a
link to a page within the same website) is specified with a relative
URL (without the "https://www" part).
Example:
<h2>Absolute URLs</h2>
<p><a href="https://www.google.com/">Google</a></p>
<h2>Relative URLs</h2>
Link from home page to product page: href="t-shirts/t-shirt-life-is-good/"
Link from product page to home page : href="../../"
Button as a Link
Example:
<p>Click the button to go to the Google.</p>
<button onclick="document.location=
'https://www.google.com/'">Search here</button>
HTML Tables
HTML tables allow web developers to arrange data into rows and columns.
HTML Table Tags
<table> Defines a table
<th> Defines a header cell in a table
<tr> Defines a row in a table
<td> Defines a cell in a table
<caption> Defines a table caption
<colgroup> Specifies a group of one or more columns in a table for
formatting
<col> Specifies column properties for each column within a
<colgroup> element
<thead> Groups the header content in a table
<tbody> Groups the body content in a table
<tfoot> Groups the footer content in a table
<style>
table, th, td {
border:1px solid black; border-collapse: collapse;
}
</style>
<h2>TH elements define table headers</h2>
<table style="width:100%">
<table>
<tr>
<th>Person 1</th>
<th>Person 2</th>
<th>Person 3</th>
</tr>
<tr>
<td>John</td>
<td>Robert</td>
<td>Ruby</td>
</tr>
<tr>
<td>16</td>
<td>14</td>
<td>10</td>
</tr>
</table>
HTML Lists
HTML lists allow to group a set of related items in lists.
term.
The <dl> tag defines the description list, the <dt> tag defines the
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
HTML Block and Inline Elements
A block-level element always starts on a new line, and the
browsers automatically add some space (a margin) before and
after the element.
A block-level element always takes up the full width available
(stretches out to the left and right as far as it can).
Two commonly used block elements are: <p> and <div>.
The <p> element defines a paragraph in an HTML document.
requirement).
HTML JavaScript
JavaScript makes HTML pages more dynamic and interactive.
Example:
<button type="button"
Onclick = "document.getElementById('demo').innerHTML =
Date()" >
Click me to display Date and Time.</button>
The HTML <script> Tag
The HTML <script> tag is used to specify a client-side script. It may
Example1:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Hello
JavaScript!";
</script>
The above JavaScript example writes "Hello JavaScript!" into an
Example:
Note:
A browser without support for JavaScript will show the text
written inside the noscript element.
HTML Layout
HTML layouts provide a way to arrange web pages in well-
mannered, well-structured, and in responsive form or we can
say that HTML layout specifies a way in which the web pages
can be arranged.
Web-page layout works with arrangement of visual elements
of an HTML document.
Web page layout is the most important part to keep in mind
while creating a website so that our website can appear
professional with the great look.
Every website has a specific layout to display content in a
specific manner.
HTML Layout Elements
<header> - Defines a header for a document or a section
<nav> - Defines a set of navigation links
<section> - Defines a section in a document
<article> - Defines an independent, self-contained
content
<aside> - Defines content aside from the content (like a
sidebar)
<footer> - Defines a footer for a document or a section
<details> - Defines additional details that the user can
open and close on demand
<summary> - Defines a heading for the <details> element
HTML Entities
HTML character entities are used as a replacement of reserved
characters in HTML. You can also replace characters that are
not present on your keyboard by entities.
HTML entities provide a wide range of characters which can
semicolon (;).
Syntax:
&entity_name;
OR
&#entity_number;
HTML Character Entities
Result Description Entity Entity
Name Number
<!DOCTYPE html>
<html>
<body>
<h1>HTML Entity Example</h1>
<h2>The greater-than sign: > </h2>
<h2>The cent sign: ¢ </h2>
<h2>The pound sign: £ </h2>
<h2>The pound sign: £ </h2>
</body>
</html>
HTML URL Encode
HTML URL - Uniform Resource Locators
A URL is another word for a web address.
A URL can be composed of words (e.g. google.com), or an
Internet Protocol (IP) address (e.g. 192.68.20.50).
Most of the user use URL in the form of words because it is
easy to remember than numbers.
Web browsers request pages from web servers by using a URL.
A Uniform Resource Locator (URL) is used to address a
document (or other data) on the web.
Syntax of a URL:
scheme://prefix.domain:port/path/filename
scheme://prefix.domain:port/path/filename
Type Description
GET.
Always use POST if the form data contains sensitive or
personal information.
GET: Sends form data via a URL string
Appends the form data to the URL, in name/value pairs
NEVER use GET to send sensitive data! (the submitted form
the result
GET is good for non-secure data, like query strings in Google
amounts of data.
Form submissions with POST cannot be bookmarked
The below diagram shows the difference between get
and post
HTML Quick List
The basic HTML document
Common link:
<a href = http://www.example.com/>link text </ a>
image link:
<a href = "http://www.example.com/">
<img src = "URL" alt = "replacement text"> </ a>
Mail link:
<a href = "mailto: webmaster@example.com"> Send e-mail </
a>
Bookmark:
<a id = "tips"> Tips section </ a> <A href = "#tips"> Skip Tips
section </ a>
Style / Block (Styles / Sections)
<Style type = "text / css">
h1 {Color: red ;} p {Color: blue ;}
</ Style> <Div> block-level elements in the document </ div> <Span> docu-
ment inline elements </ span>
Unordered list
<Ul>
<Li> item </ li>
<Li> item </ li>
</ Ul>
Ordered List
<Ol>
<Li> The first </ li>
<Li> Second item </ li>
</ Ol>
Definition List
<Dl>
<Dt> Item 1 </ dt>
<Dd> Item Description 1 </ dd>
<Dt> Item 2 </ dt>
<Dd> Description Item 2 </ dd>
</ Dl>
Tables (Tables)
<Table border = "1">
<Tr>
<Th> table header </ th>
<Th> table header </ th>
</ Tr>
<Tr>
<Td> table data </ td>
<Td> table data </ td>
</ Tr>
</ Table>
Frame (Iframe)
<Iframe src = "demo_iframe.htm"> </ iframe>
Forms (Forms)
<Form action = "demo_form.php" method = "post / get">
<Input type = "text" name = "email" size = "40" maxlength = "50">
<Input type = "password">
<Input type = "checkbox" checked = "checked">
<Input type = "radio" checked = "checked">
<Input type = "submit" value = "Send">
<Input type = "reset">
<Input type = "hidden">
<Select>
<Option> Apple </ option>
<Option selected = "selected"> banana </ option>
<Option> Cherry </ option>
</ Select>
<Textarea name = "comment" rows = "60" cols = "20"> </ textarea>
</ Form>