[go: up one dir, main page]

0% found this document useful (0 votes)
3 views56 pages

Lec02 - HTML

html

Uploaded by

ntisameh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views56 pages

Lec02 - HTML

html

Uploaded by

ntisameh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

CS 283

Lecture 02: HTML


(Fall 2022/2023)

Dr. Nehal M. Ali


CS283 1
2
Hypertext Markup Language (HTML)

• Describes the content and structure of information on


a web page
• Not the same as the presentation (appearance on
screen)
• Surrounds text content with opening and closing tags
TryIt Editor

CS283
EXtensible HyperText Markup Language (XHTML)
3

• XML is a markup language where all files must be marked up


properly (be "well-formed")
• Uses a markup format of XML
• XML-based version of HTML.
• XML + HTML = XHTML.
• Standardized in year 2000.
• XHTML is HTML defined as an XML application
• XHTML is supported by all major browsers.
•A strict XHTML page uses some different syntax and tags than HTML
CS283
4
Web Standards

• Why use XHTML and web standards?


• more rigid and structured language
• more interoperable across different web browsers
• more likely that our pages will display correctly in the future
• Easier to maintain

CS283
5
Structure of XHTML page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML


• HTML is saved with extension .html 1.1//EN"
• Basic structure: tags that enclose content, "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
• i.e., elements
<html xmlns="http://www.w3.org/1999/xhtml">
• Header describes the page <head>
• Body contains the page’s contents information about the page
</head>

<body>
page contents
</body>
</html>
HTML

CS283
HTML Elements

• The HTML element consists of a start tag, a content and an


end tag
• Syntax: <tagname>Some Content</tagname>

Start tag Element content End tag


<h1> Some Heading </h1>
<p> Some paragraph. </p>
<br> none none
Nested HTML Elements

• HTML elements can contain other HTM elements.


• All HTML documents consist of nested HTML elements.
• Tags must be correctly nested: a closing tag must match the most recently
opened tag
<!DOCTYPE html>
<html>
<body>

<h1>Heading</h1>
<p>paragraph.</p>

</body>
</html>
Flexible HTML !

• HTML is Not Case Sensitive


• Some of the HTML elements might display properly even if the End Tag is
missing.
• → this is not a recommended practice as the page might act unexpectedly!
<html>
<body>

<p>unclosed paragraph
<p>unclosed paragraph 2

</body>
</html>
Empty HTML Elements

• Empty elements are the HTML elements that has no content.

<!DOCTYPE html>
<html>
<body>

<h1>Heading</h1>
<p>paragraph.</p>
<p>This is a <br> paragraph with a line break.</p>

</body>
</html>
HTML Attributes

• HTML elements can include attributes


• Attributes deliver further information about the HTML
elements
• Attributes are defined in name/value pairs
E.g.: name="value“
• Attributes are determined in the start tag

<a href="https://www.msa.com">Our MSA</a>

<img src="img_sample.jpg">
HTML Style Tag

• Setting the style of an HTML element, can be done with the


Style attribute
• <tagname style="property:value;">

<body style="background-color:red;">

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

</body>
Defining the SRC attribute

• 1. Absolute URL -
src="http://www.msa.com/images/img_sample.jpg".
• 2. Relative URL - Links to an image that is hosted within
the website.
• The URL does not include the domain name.
• If the URL begins without a slash.
• src="img_girl.jpg“ →it will be relative to the current page.
• src="/images/img_sample.jpg“ → relative to the domain.
HTML Documents Structure

<!DOCTYPE html>

<html>

<body>
HTML Documents Structure

<!DOCTYPE html>
<html>
<body>

<h1>Page Heading</h1>
<p>Any paragraph.</p>

</body>
</html>
16
Page Title <title>


<head>
<title> HARRY POTTER AND THE DEATHLY HALLOWS - PART 2 </title>
</head>
… HTML

• Placed within the <head></head> tag of the page


• Displayed in web browser’s title mark and when
bookmarking the page

CS283
17
Paragraph <p>

<body>
<p> Harry Potter and the Deathly Hallows,
the last book in the series, begins directly after the
events of the sixth book.
Voldemort has completed his ascension to power and gains
control of the Ministry of Magic </p>
</body>
… HTML
Harry Potter and the Deathly Hallows, the last book in the series, begins
directly after the events of the sixth book. Voldemort has completed his
ascension to power and gains control of the Ministry of Magic
output

• Placed within the <body> </body> of the page


CS283
18
Headings <h1>, <h2>, … <h6>
<h1> Harry Potter </h1>
<h2> Books </h2>
<h3> Harry Potter and the Philosopher’s Stone </h3>
HTML

Harry Potter
Books
Harry Potter and the Philosopher’s Stone
output

CS283
19
Horizontal rule <hr />
<p> First paragraph </p>
<hr />
<p> Second Paragraph </p>
HTML
First Paragraph

Second Paragraph
output

• Should be immediately closed with />

CS283
20
Links <a>
<p>
Search
<a href="http://www.google.com/">Google</a>
now!
</p> HTML

Search Google now!


output

• The href attribute specifies the destination URL


• Links or anchors are inline elements, so they must be
placed inside a block element such as a p or h1

CS283
21
More about anchors
<p><a href=“deathlyHallows-book.html">Harry Potter and the
Deathly Hallows</a></p>

<p><a href="http://en.wikipedia.org”
title="Search">Wikipedia</a></p>
HTML

Harry Potter and the Deathly Hallows

Wikipedia output

• Types of URLs that can appear in anchors:


• Absolute: to another web site
• Relative: to another page on this web site
CS283
22
Images <img>

<img src="images/tobby.jpg" alt=“Tobby from Harry Potter" />


HTML

• The src attribute specifies source of the image URL


• XHTML also requires an alt attribute describing the
image

CS283
23
More about images

<a href="http://harrypotter.net/">
<img src="images/dumbledore.jpg" alt=“Dumbledore from Harry
Potter"
title="Alas! Ear wax!"/>
</a> HTML

• If placed inside an a anchor, the image will become a link


• The title attribute specifies an optional tooltip

CS283
24
Line Break <br>
<p>One Ring to rule them all, One Ring to find them, <br /> One
Ring to bring them all and in the darkness bind them.</p>
<p> In the Land of Mordor where the Shadows lie. </p>
HTML

One Ring to rule them all, One Ring to find them,


One Ring to bring them all and in the darkness bind them

In the Land of Mordor where the Shadows lie.


output
• br should be immediately closed with />
• br should not be used to separate paragraphs or used
multiple times in a row to create spacing
CS283
25
Comments <!-- … -- >

<!-- My web page, by Bob Student


CSE 380, Fall 2048 -->
<p>CS courses are <!-- NOT --> a lot of fun!</p>
HTML

CS courses are a lot of fun!


output

• Comments are useful for disabling sections of a page


• Comments cannot be nested and cannot contain a --

CS283
26
Phrase elements <em>, <strong>

<p>
HTML is <em>really</em>,
<strong>REALLY</strong> fun!
</p>
HTML

HTML is really REALLY fun!


output

• em: emphasized text (usually in italic)


• strong: strongly emphasized text (usually in bold)
• The tags must be properly nested for a valid page

CS283
27
Unordered list: <ul>, <li>

<ul>
<li>No shoes</li>
<li>No shirt</li>
<li>No problem!</li>
</ul> HTML

• No shoes
• No shirt
• No problem! output

• ul represents a bulleted list of items (block)


• li represents a single item within the list (block)

CS283
28
Nested unordered lists
<ul>
<li>Harry Potter characters:
<ul>
<li>Harry Potter</li> • Harry Potter characters:
<li>Hermione</li> • Harry Potter
<li>Ron</li> • Hermione
</ul> • Ron
</li> • LOTR characters:
<li>LOTR characters: • Frodo
<ul> • Bilbo
<li>Frodo</li>
• Sam
<li>Bilbo</li>
<li>Sam</li>
</ul>
output
</li>
</ul>
CS283 HTML
29
Ordered list <ol>
<p>Apple business model:</p>
<ol>
<li>Beat Microsoft</li>
<li>Beat Google</li>
<li>Conquer the world!</li>
</ol> HTML

Apple business model:


1. Beat Microsoft
2. Beat Google
3. Conquer the world output

• ol represents a numbered list of items


• we can make lists with letters or Roman numerals
CS283
using CSS (later)
30
Common error: Not closing a list!
<ul>
<li>No shoes</li>
<li>No shirt</li>
<li>No problem!</li>
<p>Paragraph after list...</p> HTML

• No shoes
• No shirt
• No problem!

Paragraph after list... output

• If you leave a list open, subsequent contents will be


indented
CS283
31
Common Error: Improper nested list placement
<ul>
<li>Harry Potter characters:</li>
<ul>
<li>Harry Potter</li>
<li>Hermione</li>
<li>Ron</li>
</ul>
</li>
<li>LOTR characters:
<ul>
<li>Frodo</li>
<li>Bilbo</li>
<li>Sam</li>
</ul>
</ul> HTML
• closing the outer li too early (or not at all) will render
CS283 correctly in most browsers, but it is incorrect XHTML
33
Definition list <dl>, <dt>, <dd>
<dl>
<dt>newbie</dt> <dd>one who does not have mad skills</dd>
<dt>jaded</dt> <dd>tired, bored, or lacking enthusiasm </dd>
<dt>frag</dt> <dd>a kill in a shooting game</dd>
</dl> HTML
newbie
one who does not have mad skills
jaded
Tired, bored, or lacking enthusiasm
frag
a kill in a shooting game output
• dl represents a list of definitions of terms
• dt represents each term, and dd its definition
CS283
34
Tables <table>, <tr>, <td>

<table>
<tr><td>1,1</td><td>1,2 okay</td></tr>
<tr><td>2,1 real wide</td><td>2,2</td></tr>
</table> HTML

1,1 1,2 okay


2,1 real wide 2,2
output

CS283
Tables (Cont.)

• table defines the overall table, tr each row, and td each cell's data
• Useful for displaying large row/column datasets
• NOTE: tables are sometimes used by beginners for web page layout, but
this is not proper semantic HTML and should be avoided
36
Table headers, captions: <th>, <caption>
<table>
<caption>My important data</caption>
<tr><th>Column 1</th><th>Column 2</th></tr>
<tr><td>1,1</td><td>1,2 okay</td></tr>
<tr><td>2,1 real wide</td><td>2,2</td></tr>
</table> HTML
My important data
Column 1 Column 2
1,1 1,2 okay
2,1 real wide 2,2
output

 th cells in a row are considered headers


 a caption at the start of the table labels its meaning
CS283
37
Quotations <blockquote>
<p>As Lincoln said in his famous Gettysburg Address:</p>
<blockquote>
<p>Fourscore and seven years ago, our fathers
brought forth
on this continent a new nation, conceived in
liberty, and
dedicated to the proposition that all men are
created equal.</p>
</blockquote> HTML

As Lincoln said in his famous Gettysburg Address:


Fourscore and seven years ago, our fathers brought forth on this
continent a new nation, conceived in liberty, and dedicated to the proposition
that all men are created equal.
output
• Browsers usually ident the lengthy quotation
CS283
38
Inline quotations <q>

<p>Quoth the Raven, <q>Nevermore.</q></p>


HTML

Quoth the Raven, “Nevermore.”


output

• Why not just write the following?


• <p>Quoth the Raven, "Nevermore."</p>
• We don't use " marks for two reasons:
• XHTML shouldn't contain literal quotation mark characters; they should be written as
&quot;
• using <q> allows us to apply CSS styles to quotations

CS283
39
HTML Character Entities

character(s) entity
<> &lt; &gt;
éèñ &eacute; &egrave; &ntilde;
™© &trade; &copy;
πδΔ &pi; &delta; &Delta;
И &#1048;
"& &quot; &amp;

CS283
40
Inline quotations <q>

&lt;p&gt;
&lt;a
href=&quot;http://google.com/search?q=xenia&amp;ie=utf-
8&amp;aq=t&quot;&gt;
Search Google for Xenia
&lt;/a&gt;
&lt;/p&gt; HTML

<p> <a href="http://google.com/search?q=xenia&ie=utf-8&aq=t"> Search


Google for Xenia </a> </p>
output

CS283
42
Computer code <code>

<p>
The <code>ul</code> and <code>ol</code>
tags make lists.
</p> HTML

The ul and ol tags make lists.


output
• code: a short section of computer code

CS283
43
Preformatted text <pre>

<pre>
Bill Gates speaks
You will be assimilated
Microsoft fans delirious
</pre> HTML

Bill Gates speaks


You will be assimilated
Microsoft fans delirious
output

• Displayed with exactly the whitespace / line breaks


given in the text
• Shown in a fixed-width font by default
CS283
44
Preformatted text <pre>
<pre><code>
public static void main(String[] args) {
System.out.println("Hello, world!");
}
</code></pre> HTML

public static void main(String[] args) {


System.out.println("Hello, world!");
}
output

• When showing a large section of computer code,


enclose it in a pre to preserve whitespace and a
code to describe the semantics of the content

CS283
45
W3C XHTML Validator
<p>
<a href="http:// https://validator.w3.org/">
<img src="http://www.w3.org/Icons/valid-xhtml11"
alt="Validate" />
</a>
</p> HTML

• Validates hecks your HTML code to make sure it


meets the official strict XHTML specifications

CS283
46
Web page metadata <meta>

<meta name="description"
content=“Harry Potter Official Website." />
<meta name="keywords" content="harry potter, harry potter
and the deathly hallows, deathly hallows, ministry of
magic, resurrection stone, clock of invisibility" />
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" /> HTML

• information about your page (for a browser, search engine, etc.)


• placed in the head of your XHTML page
• meta tags often have both the name and content attributes
• some meta tags use the http-equiv attribute instead of name

CS283
47
meta element to describe the page
<head>
<meta name="author"
content="web page's author" />
<meta name="revised"
content="web page version and/or last modification date"
/>
<meta name="generator"
content="the software used to create the page" />
</head> HTML

• many WYSIWYG HTML editors (FrontPage,


PageMaker, etc.) place their names in the meta
generator tag

CS283
48
meta element to aid search engines

<head>
<meta name="description"
content="how you want search engines to display your page"
/>
<meta name="keywords"
content="words to associate with your page (comma
separated)" />
</head> HTML

• these are suggestions to search engines about how to


index your page
• the search engine may choose to ignore them

CS283
HTML FORMs
HTML Form

<h1>The form element</h1>

<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit">
</form>
HTML Form Element (Cont.)
• A form can containany of the below elements:
• <input> → text box
• <textarea> → Multi-lined test box
• <button>
• <select> → Dropdown list
• <option> →the elements within the dropdown list
• <optgroup> → Nested Dropdown list
• <fieldset> → Group related elements in a form
• <label> → non-editable tag
• <output> → non-editable text box calculated given some input
Fieldset Element
<h1>CS283</h1>

<form action="/action_page.php">
<fieldset>
<legend>Personal Data:</legend>
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<label for="birthday">Birthday:</label>
<input type="date" id="birthday"
name="birthday"><br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
optgroup Element

<form action="/action_page.php">
<label for="cars">Choose a car:</label>
<select name="cars" id="cars">
<optgroup label="American Cars">
<option value="Lincoln">Lincoln</option>
<option value="cadillac">cadillac</option>
</optgroup>
<optgroup label="German Cars">
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</optgroup>
</select>
<br><br>
<input type="submit" value="Submit">
</form>
Project Details
Form

You might also like