Lecture1 HTML
Lecture1 HTML
Note: Comments are not displayed by the browser, but they can
help document your HTML source code.
Example
<!-- This is a comment -->
<p>This is a paragraph.</p>
</body>
</html>
Step 3: Save the HTML Page
Save the file on your computer.
Select File > Save as in the Notepad menu.
Example
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
HTML Paragraphs
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
HTML Links
Example
<a href="https://www.w3schools.com">This is a link</a>
Example
<img src="w3schools.jpg" alt="W3Schools.com" width="104" height="142">
Nested HTML Elements
</body>
</html>
Example Explained
The <html> element defines the whole document.
It has a start tag <html> and an end tag </html>.
The element content is another HTML element (the <body>
element).
<html>
<body>
</body>
</html>
The <body> element defines the document
body.
It has a start tag <body> and an end tag
</body>.
The element content is two other HTML
elements (<h1> and <p>).
<body>
</body>
The <h1> element defines a heading.
It has a start tag <h1> and an end tag </h1>.
The element content is: My First Heading.
<h1>My First Heading</h1>
<body>
</body>
Do Not Forget the End Tag
What end tag is missing??
<html>
<body>
<p>This is a paragraph
<p>This is a paragraph
</body>
</html>
Example
<h1>This is heading 1</h1>
<p>This is some text.</p>
<hr size=10 color=red align=left width=
50%>
<h2>This is heading 2</h2>
<p>This is some other text.</p>
<hr>
The HTML <head> Element
The HTML <head> element has nothing to do with HTML
headings.
The <head> element is a container for metadata. HTML
metadata is data about the HTML document. Metadata is not
displayed.
The <head> element is placed between the <html> tag and
the <body> tag:
Example
<!DOCTYPE html>
<html>
<head>
<title>My First HTML</title>
<meta charset="UTF-8">
</head>
Note: Metadata typically define the document title, character set, styles,
<body>
links, scripts, and other meta information.
HTML Text Formatting
Text Formatting
This text is bold
This text is italic
This is subscript and superscript
HTML uses elements like <b> and <i> for formatting output, like
bold or italic text.
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> - Small text
<del> - Deleted text
<ins> - Inserted text
<sub> - Subscript text
<sup> - Superscript text
See w3schools website
HTML Colors
000000 = black
FFFFFF = white
HTML Images
<!DOCTYPE html>
<html>
<body>
<h2>Spectacular Mountain</h2>
<img src="pic_mountain.jpg" alt="Mountain View" style="width:304px;height:228px;">
</body>
</html>
HTML Links
HTML links are hyperlinks.
You can click on a link and jump to another document.
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. It can be an image or any other
HTML element.
In HTML, links are defined with the <a> tag:
Example
<img src="html5.gif" alt="HTML5 Icon"
style="width:128px;height:128px;">
Alternatively, you can use the width and height attributes. Here, the values
are specified in pixels by default:
Example
Example
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
The CSS list-style-type property is used to define
the style of the list item marker:
Value Description
Sets the list item marker to a
disc
bullet (default)
Sets the list item marker to a
circle
circle
Sets the list item marker to a
square
square
The list items will not be
none
marked
Example - Circle
<ul style="list-style-type:circle">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Ordered HTML List
Example
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
<ul type="disc">
<li>Apple</li>
<li>Orange</li>
<li>Grapefruit</li>
</ul>
<dl>
<dt>HTML</dt>
<dd>A markup lang…</dd>
</dl>
46
* Tables represent tabular data
* A table consists of one or several rows
* Tables should not be used for layout. Use CSS floats and positioning
styles instead
*Formatting Content
47
with Tables
* Start and end of a table
<table> ... </table>
* Start and end of a row
<tr> ... </tr>
* Start and end of a cell in a row
50
*Nested Tables
*Table data “cells” (<td>) can contain nested
tables (tables within tables):
<table> nested-tables.html
<tr>
<td>Contact:</td>
<td>
<table>
<tr>
<td>First Name</td>
<td>Last Name</td>
</tr>
</table>
</td>
</tr>
</table> 51
* Cell Spacing and Padding
* Tables have two important attributes:
cellspacing cellpadding
53
*Column and Row Span
* Table cells have two important attributes:
colspan rowspan
<table cellspacing="0">
<tr class="1"><td>Cell[1,1]</td>
<td colspan="2">Cell[2,1]</td></tr>
<tr class=“2"><td>Cell[1,2]</td>
<td rowspan="2">Cell[2,2]</td>
<td>Cell[3,2]</td></tr>
<tr class=“3"><td>Cell[1,3]</td>
<td>Cell[2,3]</td></tr>
</table>
Cell[1,2] Cell[3,2]
Cell[2,2]
Cell[1,3] 56 Cell[2,3]
* Home work: Design the
following table
57
*Collecting Input with
Forms
* Forms are the primary method for gathering data from site
visitors
* Create a form block with The “method" attribute tells
<form></form> how the form data should be
sent – via GET or POST request
* Example:
<form name="myForm" method="post"
action="path/to/some-script.php">
...
</form>
The "action" attribute tells
where the form data should be
sent 58
*Form Fields
*Single-line text input fields:
<input type="text" name="FirstName" value="This
is a text field" />
*Multi-line
<textareatextarea fields:
name="Comments">This is a multi-line
text field</textarea>
*Radio buttons:
<input type="radio" name="title" value="Mr." />
61
*Reset button – brings the form to its initial
state
<input type="reset" name="resetBtn"
value="Reset the form" />
63
*Form labels are used to associate an explanatory
text to a form field using the field's ID.
<label for="fn">First Name</label>
<input type="text" id="fn" />
<br />
Gender:
<input name="gender" type="radio" id="gm" value="m" />
<label for="gm">Male</label>
<input name="gender" type="radio" id="gf" value="f" />
<label for="gf">Female</label>
<br />
<label for="email">Email</label>
<input type="text" name="email" id="email" />
</fieldset>
<p>
<textarea name="terms" cols="30" rows="4"
readonly="readonly">TERMS AND CONDITIONS...</textarea>
</p>
<p>
<input type="submit" name="submit" value="Send Form" />
<input type="reset" value="Clear Form" />
</p>
</form>
66
* HTML5: New form elements
67
68
Error-Prevention Tip :
* The autocomplete attribute works only if you specify a name
or id attribute for the input element.
69
* Once you fill a data in the text box ..html 5 can recover the
previous input. *we use a datalist element to
obtain the user’s birth month.
*Output
70