01 HTML (1)
01 HTML (1)
What is HTML?
➢ HTML is the standard markup language for creating Web pages.
➢ HTML stands for Hyper Text Markup Language
➢ 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 are represented by tags
➢ HTML tags label pieces of content such as "heading", "paragraph", "table",
and so on
➢ Browsers do not display the HTML tags, but use them to render the content
of the page
A Simple HTML Document
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
</body>
</html>
Example Explained
✓ The <!DOCTYPE html> declaration defines this <!DOCTYPE html>
document to be HTML5 <html>
<head>
✓ The <html> element is the root element of an HTML
<title>Page Title</title>
page
</head>
✓ The <head> element contains meta information <body>
about the document
✓ The <title> element specifies a title for the <h1>My First Heading</h1>
document <p>My first paragraph.</p>
</body>
</html>
HTML Editors
Web pages can be created and modified by
using professional HTML editors.
Example:
✓Notepad++
✓Sublime Text
✓VS Code
✓Bracket
HTML Tags
HTML Tags
Tip: The start tag is also called the opening tag, and the end
tag the closing tag.
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>
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
➢ The link's destination is specified in the href attribute.
Example:
<a href="https://www.sample.com"> This is a link </a>
HTML Images
Example:
<img src=“Images/sample.jpg" width="104" height="142">
HTML Buttons
➢ HTML buttons are defined with the <button> tag
Example
<button> Click me </button>
HTML Lists
HTML lists are defined with the <ul> (unordered/bullet list) or
the <ol> (ordered/numbered list) tag, followed by <li> tags (list
items):
Example:
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
HTML
Elements
HTML Elements
An HTML element usually consists of a start tag and an end tag,
with the content inserted in between:
Example:
<tagname>Content goes here...</tagname>
The HTML element is everything from the start tag to the end tag:
<p>My first paragraph.</p>
</body>
</html>
Empty HTML Elements
HTML elements with no content are called empty elements.
<br> is an empty element without a closing tag (the <br> tag defines
a line break):
Example
<p>This is a <br> paragraph with a line break.</p>
Empty elements can be "closed" in the opening tag like this: <br/>.
HTML does not require empty elements to be closed. But if you want
stricter validation, or if you need to make your document readable
by XML parsers, you must close all HTML elements properly.
HTML Is Not Case Sensitive
HTML tags are not case sensitive: <P> means
the same as <p>.
Example
<a href="https://www.w3schools.com">This is a link</a>
The src Attribute
HTML images are defined with the <img> tag.
Example:
<img src="img_girl.jpg">
The width and height Attributes
Example:
<img src="img_girl.jpg" width="500" height="600">
The value of the alt attribute can be read by screen readers. This way, someone
"listening" to the webpage, e.g. a vision impaired person, can "hear" the
element.
Example
<img src="img_girl.jpg" alt="Girl with a jacket">
The alt attribute is also useful if the image cannot be displayed
(e.g. if it does not exist):
Example
See what happens if we try to display an image that does not exist:
<img src="img_typo.jpg" alt="Girl with a jacket">
The style Attribute
The style attribute is used to specify the styling of an
element, like color, font, size etc.
Example
<p style="color:red">This is a paragraph.</p>
The title Attribute
Here, a title attribute is added to the <p> element. The value of the
title attribute will be displayed as a tooltip when you mouse over
the paragraph:
Example
<p title="I'm a tooltip">
This is a paragraph.
</p>
Suggestion: Quote Attribute Values
The HTML standard does not require quotes around attribute values.
Bad
<a href=https://www.w3schools.com>
Good
<a href="https://www.w3schools.com">
HTML
Headings
HTML Headings
Headings are defined with the <h1> to <h6> tags.
<h1> defines the most important heading. <h6> defines the least
important heading.
Heading 1
Example
<h1>Heading 1</h1> Heading 2
<h2>Heading 2</h2> Heading 3
<h3>Heading 3</h3>
Heading 4
<h4>Heading 4</h4>
<h5>Heading 5</h5> Heading 5
<h6>Heading 6</h6> Heading 6
Note: Use HTML headings for headings only. Don't use headings
to make text BIG or bold.
HTML Horizontal Rules
The <hr> tag defines a thematic break in an HTML page, and is
most often displayed as a horizontal rule.
Example
<h1>This is heading 1</h1>
<p>This is some text.</p>
<hr>
<h2>This is heading 2</h2>
<p>This is some other text.</p>
<hr>
The HTML <head> Element
The HTML <head> element is a Example
container for metadata. HTML <!DOCTYPE html>
metadata is data about the HTML <html>
document. Metadata is not
displayed. <head>
<title>My First HTML</title>
<meta charset="UTF-8">
The <head> element is placed </head>
between the <html> tag and
<body>
the <body> tag: .
.
Note: Metadata typically define the .
document title, character set, styles,
scripts, and other meta information.
How to View HTML Source?
Have you ever seen a Web page and wondered
"Hey! How did they do that?"
Example
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
Use <br> if you want a line break (a new line) without starting a
new paragraph:
Example
<p>This is<br>a paragraph<br>with line breaks.</p>
The <br> tag is an empty tag, which means that it has no end tag.
The HTML <pre> Element
The HTML <pre> element defines preformatted text.
Example
<pre>
My Bonnie lies over the ocean.
Tag Description
<p> Defines a paragraph
<br> Inserts a single line break
<pre> Defines pre-formatted text
HTML Styles
HTML Styles
I am Green
I am Blue
I am Big
I am the Bigger Blue
The HTML Style Attribute
<tagname style="property:value;">
Example
<body style="background-color:powderblue;">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
Text Color
Example
<h1 style="color:blue;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
Fonts
Example
<h1 style="font-family:verdana;">This is a heading</h1>
<p style="font-family:courier;">This is a paragraph.</p>
Text Size
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>
Discussion Summary
Example
<b>This text is bold</b>
Example
<i>This text is italic</i>
Example
<em>This text is emphasized</em>
Note:
Example
<h2>HTML <small>Small</small> Formatting</h2>
HTML <mark> Element
Example
<h2>HTML <mark>Marked</mark> Formatting</h2
HTML <del> Element
Example
<p>My favorite color is <del>blue</del> red.</p>
HTML <ins> Element
Example
<p>My favorite <ins>color</ins> is red.</p>
HTML <sub> Element
Example
<p>This is <sub>subscripted</sub> text.</p>
HTML <sup> Element
Example
<p>This is <sup>superscripted</sup> text.</p>
HTML Text Formatting Elements
Tag Description
<b> Defines bold text
<em> Defines emphasized text
<i> Defines italic text
<small> Defines smaller text
<strong> Defines important text
<sub> Defines subscripted text
<sup> Defines superscripted text
<ins> Defines inserted text
<del> Defines deleted text
<mark> Defines marked/highlighted text
HTML
Comments
HTML Comment Tags
Comment tags are used to insert comments in the HTML source
code.
<p>This is a paragraph.</p>
Example2
<!–-
Do not display this image at the moment
<img border="0" src="pic_trulli.jpg" alt="Trulli">
-->
HTML Colors
HTML colors are specified using predefined color names, or RGB, HEX,
HSL, RGBA, HSLA values.
Color Names
In HTML, a color can be specified by
using a color name:
Example
<h1 style="background-color:DodgerBlue;">Hello World</h1>
<p style="background-color:Tomato;">Lorem ipsum...</p>
Text Color
Example
<h1 style="color:Tomato;">Hello World</h1>
<p style="color:DodgerBlue;">Lorem ipsum...</p>
<p style="color:MediumSeaGreen;">Ut wisi enim...</p>
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.
Border Color
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, HEX, HSL, RGBA, and HSLA values:
RGB Value
In HTML, a color can be specified as an RGB value, using this formula:
To display black, set all color parameters to 0, like this: rgb(0, 0, 0).
To display white, set all color parameters to 255, like this: rgb(255, 255,
255).
Experiment by mixing the RGB
values below:
GREEN: 99
#rrggbb
Where rr (red), gg (green) and bb (blue) are hexadecimal
values between 00 and ff (same as decimal 0-255).
#ff6347
RED ff
GREEN 63
BLUE 47 # + ff + 63 + 47
Examples:
Example Shades of Gray
Shades of gray are often defined using equal values for all the 3
light sources:
HSL Value
In HTML, a color can be specified using hue, saturation, and
lightness (HSL) in the form:
Centro comercial
Francisco Chang Mexico
Moctezuma
Laughing Bacchus
Yoshi Tannamuri Canada
Winecellars
Magazzini Alimentari
Giovanni Rovelli Italy
Riuniti
Defining an HTML Table
Form elements are different types of input elements, like text fields,
checkboxes, radio buttons, submit buttons, and more.
The <input> Element
Type Description
<input type="text"> Defines a one-line text input field
<input type="radio"> Defines a radio button (for selecting one of many choices)
<input type="submit"> Defines a submit button (for submitting the form)
Text Input
Example
<form>
<br>First name:<br>
<input type="text" name="firstname">
<br>Last name:<br>
<input type="text" name="lastname">
</form>
Radio Button Input
Example
<form>
<input type="radio" name="gender" value="male" checked> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other
</form>
Checkbox Button Input
<input type=“checkbox"> defines a checkbox button.
Example
<form>
<input type=“checkbox" name="gender" value="male" checked> Male<br>
<input type="checkbox" name="gender" value="female"> Female<br>
<input type="checkbox" name="gender" value="other"> Other
</form>
The Submit Button
<input type="submit"> defines a button for submitting the form data
to a form-handler. The form-handler is typically a server page with a
script for processing input data. The form-handler is specified in the
form's action attribute:
Example
<form action="/action_page.php">
<br> First name:<br>
<input type="text" name="firstname" value="Mickey"><br>
Last name:<br>
<input type="text" name="lastname" value="Mouse"><br><br>
<input type="submit" value="Submit">
</form>
The <select> Element
The <select> element defines a drop-down list:
Example
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
RESOURCES/REFERENCES