Lec02 HTML Css PDF
Lec02 HTML Css PDF
Lecture 2
GUI
HTML
CSS
User Interfaces
● Method for a computer or device to interact with
a user
● Device receive inputs/command
● Device provides feedback/response
● HTML Document
● Actual webpage, described in HTML
● Usually has file extension .htm or .html
General Flow
● HTML is interpreted by the browser
Web
Browser
HTML
(e.g. IE,
Internet Firefox,
GUI
Safari,
Opera,etc)
Device
Sample HTML
<html> HTML Tags
<body>
Hello World!
</body>
</html>
● Web browser
● Usually comes with the operating system
● e.g., Internet Explorer, Safari, Firefox, Chrome
Sample 1
● Display web page with "Hello World" body
<html>
<body>Hello World</body>
</html>
<body>
● Defines the content of the page
Common Body Elements
<h#>
● Headings
– h1 = main
– h2 = subheading
– etc
<p>
● Paragraph
Sample 2
<html>
<body>
<h1>Introduction</h1>
<p>The quick brown fox jumps over the lazy dog.
Mary had a little lamb.</p>
<p>Every good boy does fine. My very eager
mother just served us noodles.</p>
</body>
</html>
Sample 3
<html>
<body>
<h1>Animals</h1>
<h2>Herbivores</h2>
<h3>Cow</h3>
<h3>Rabbit</h3>
<h2>Carnivores</h2>
<h3>Wolf</h3>
</body>
</html>
Empty Elements
● Tags which do not have close tags
● Examples:
<br> = newline
<hr> = horizontal line
<html>
<body>
<img src="http://www.upd.edu.ph/imag/updbanner01.jpg">
<br/>Wrong link<br/>
<img src="http://www.upd.edu.ph/imag/updbanner01.jpg"
alt=“UP banner“>
</body>
</html>
Sample 8
<html>
<body>
<h1>Image link</h1>
<a href="http://www.upd.edu.ph">
<img src="http://www.upd.edu.ph/images/UPD_head.jpg">
</a>
</body>
</html>
Relative Paths
● urls that do not start with http:// are assumed to
be relative paths
● Relative to the location of the HTML file
● Examples
<img src="sample.jpg">
<a href="sample.htm">
<img src="images/logo.jpg">
Sample 9
● Write this in test.htm
<html>
<body>
Go to <a href="new.htm">New File</a>
<br/>
The quick brown fox jumps over the lazy dog
</body>
</html>
Links Content
Footer
Lists
● Bulletted items
<ul> = Unordered list
<ol> = Ordered list
<html>
<body>
Ordered List
<ol>
<li>First item</li>
<li>Second item</li>
</ol>
Unordered List
<ul>
<li>First item</li>
<li>Second item</li>
</ul>
</body>
</html>
Sample 14
<html>
<body>
Nested List
<ul>
<li>First item</li>
<ol>
<li>First subitem</li>
<li>Second subitem</li>
</ol>
<li>Second item</li>
</ul>
</body>
</html>
Possible Color Values
● Defined names ● Hex Value (#RRGGBB)
● red ● #FF0000
● blue ● #0000FF
● green ● #00FF00
● black ● #000000
● gold ● #FFD700
● Orchid ● #DA70D6
● etc
<html>
<head>
<title>My title</title>
<base target=“_blank“ />
</head>
<body>
Look at the browser's title bar<br/>
<a href=“http://www.upd.edu.ph“>Test Base</a>
</body>
</html>
Style tag
● Encloses style language called Cascading style
sheet (CSS)
● Example
<style type="text/css">
h1 {
color: red;
font-family: arial;
}
</style>
Sample 17
<html>
<head>
<style type="text/css">
h1 {
color: red;
font-family: arial;
}
</style>
</head>
<body>
<h1>Styled header</h1>
Normal text
<h1>Another header, also styled</h1>
</body>
</html>
CSS Syntax
<selector> {
<property> : <value>;
<property> : <value>;
...
}
● Example
h1 {
color: red;
}
Advantage of using CSS
● Centralized formatting
● Ensures all tags of the same type have the same
attributes
● Without it, changing the color means changing
every instance