Chapter 2
Chapter 2
Example: Output:
<body>
<H1>Heading 1</H1>
<P>Paragraph 1, <BR>
Line 2 <BR>
Line 3 <BR>
... </P>
</body>
Horizontal rule:
<hr>
• The <HR> element causes the browser to display a horizontal
line (rule) in your document.
• This element does not use a closing tag, </HR>.
• Simply type <HR> to insert a horizontal line (rule) element into
your document.
Character formatting elements
• <TT> element
– <TT>TELETYPE </TT> Text is displayed in a mono-
spaced font.
e.g. <TT>TELETYPE </TT>
• This will produce following result:
Character formatting elements
• <CITE> element
• The cite element is used to identify a reference to
another document, such as a book, magazine, article title,
and so on.
– <p>Passages of this article were inspired by <cite>The
Complete Manual of Typography</cite> by James
Felici.</p>
Character formatting elements
• Output:
Character formatting elements
• <BLOCKQUOTE> element
<blockquote>…</blockquote>
• The <blockquote> tag specifies a section that is
quoted (refer to) from another source.
• This element can also contain most other formatting
elements such as Headings, paragraphs, tables, etc.
• E.g <p>Matthew Carter, said:</p>
<blockquote><p>Our alphabet hasn't changed;.</p>
</blockquote>
Character formatting elements
• ADDRESS> element
<ADDRESS>…</ADDRESS>
• The address element specifies information such as authorship and
contact details for the current document. You will need to use some
other method if you want the address displayed differently from left
aligned.
• E.g. <address> Our contact address is: [email protected] </address>
• To align the text in to center use <center>..</center>
• Let’s Break !
Generic element
• HTML provides two generic elements that can be customized to describe your
content perfectly.
• You give a generic element a name using either an id or class attribute.
• The difference between span and div is that a span element is in-line and
usually used for a small chunk of HTML inside a line (such as inside a
paragraph).
• Whereas a div (division) element is block-line (which is basically equivalent to
having a line-break before and after it) and used to group larger chunks of code.
The <div>
element
• The <div> tag is used to group the large section of HTML element
together.
• The HTML <div> tag is used for defining a section of your document.
• The <div> used to break a page into sections for context, structure, and
lay out purposes.
• The div (short for division) is used to indicate a generic block-level element.
• With the <div> tag, you can group large sections of HTML elements together
and format them with CSS.
The <div>
•
element
E.g. A heading and several paragraph are enclose in a div and identified as
the “news” section.
<div style="font-size:24px; color:red">DIV example</div>
<p>This one is <span style="color:red; font-weight:bold">only
a test</span>.</p>
The <span> element
• The <span> tag is an inline element container used to mark a part of a text, or part of
a document.
• The <span> tag is easily styled by CSS or manipulated with JavaScript using the class
or id attribute.
• The <span> element is used to indicate a generic inline element.
<p>This one is <span style="color:red; font-weight:bold">only a
test</span>.</p>
<p>This one is another <span style="font-size:32px; font-
weight:bold">TEST</span>.</p>
Element identifier
• The class identifier
– The class attribute is used for grouping similar elements
– they can be used multiple times in the same HTML document
• Id and class value
– the values for id and class attribute should start with a letter (A- Z or a-z) or
underscore
– they should not content any character spaces or special
characters
– Letter, number, hyphens, underscore, colons, and periods are
allowed.
Character entity
• Some characters have a special meaning in HTML, like the less
than sign (<) that defines the start of an HTML tag.
• If want the browser to actually display these characters, we must
insert character entities in the HTML source.
• A character entity has three parts: an ampersand (&), an entity
name or a # and an entity number and finally a semicolon (;)
The most common character entities
Result description Entity na m e Entity number
Non-braking space  
< Less than < <
> Greater than > >
“ Quotation mark " "
‘ apostrophe ' '
cent ¢ ¢
• HTML Description list is also a list style which is supported by HTML and
XHTML.
• It is also known as definition list where entries are listed like a dictionary or
encyclopedia.
• The definition list is very appropriate when you want to present glossary,
list of terms or other name-value list.
• The HTML definition list contains following three tags:
• <dl> tag defines the start of the list.
• <dt> tag defines a term.
• <dd> tag defines the term definition (description).
Cont…
• Example:
• <html>
• <body> output:
• <h2>A Description List</h2>
• <dl>
A Description List
• <dt>Coffee</dt>
Coffee
• <dd>- black hot drink</dd>
- black hot drink
• <dt>Milk</dt>
Milk
• <dd>- white cold drink</dd>
- white cold drink
• </dl>
• </body>
• </html>
Adding links
• Anchor tag or <a> element allows us to link to other sites.
• To make a selection of text a link, simply wrap it in opening
and closing <a>...</a> tags and use the href attribute to
provide the URL of the target page.
• Example:
<a href=“http://www.google.com”>Google</a>
Inserting image
• You can insert any image in your web page by using
<img> tag.
• Syntax:
<img src="image URL" attr_name = "attr_value“ ...more
attributes />
e.g. <img src=“image1.jpg” alt=“lion image” width=“300”
height=“200”>
Inserting
• Following are most frequently used attributesattributes:
for <img> tag.
– width: sets width of the image.
– height: sets height of the image.
– border: sets a border around the image.
– src: specifies URL of the image file.
– alt: this is an alternate text which will be displayed if image is missing.
– align: this sets horizontal alignment of the image and takes value
either left, right or center.
– name: name of the image with in the document.
– id: id of the image with in the document.
– title: specifies a text title. The browser, perhaps flashing the title when the mouse
passes over the link.
Inserting multimedia in HTML
Multimedia is a form of communication that combines different content forms such as text,
audio, images, animations, or video into a single interactive presentation, in contrast to
traditional mass media which features little to no interaction from users, such as printed
material or audio recordings.
42
Different types of files
43
Inserting audios:
• The audio element is used to insert audio into web pages.
• Example:
<audio id="audiolist" controls>
<source src="music.mp3" type="audio/mp3">
</audio>
Output:
Inserting video
• The video element is used to insert video into web pages.
• Example:
<video width="500" height="350" controls>
<source src="Tedy.mp4" type="video/mp4">
</video>
Inserting tables:
• The <table> tag defines an HTML table.
• Each table row is defined with a <tr> tag.
• Each table header is defined with a <th> tag.
• Each table data is defined with a <td> tag.
• By default the text in <th> elements are bold and
centered.
Inserting
• Example: tables:
<table border=“1”>
<tr>
Output:
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Kedir</td>
<td>Mohammed</td>
<td>25</td>
</tr>
<tr>
<td>Abel</td>
<td>Solomon</td>
<td>48</td>
</tr>
</table>
Col span:
• Column spans, created with the colspan attribute in the td or th
element, stretch a cell to the right to span over
the subsequent columns. Output:
<table border="1">
<tr>
<th colspan="2">Movie categories</th>
</tr>
<tr>
<td>Adventure</td> <td>Action</td>
</tr>
</table>
Row span:
• Row spans, created with the rowspan attribute, work just
like column spans. Output:
<table border="1">
<tr><th rowspan=“2">Serving Size</th>
<td>Small</td>
</tr>
<tr><td>Medium </td></tr>
</table>
Cell Spacing and Padding
Tables have two important attributes:
cellspacing cellpadding
cell cell cell cell
table-cells.html
<html>
<head><title>Table Cells</title></head>
<body>
<table cellspacing="15" cellpadding="0">
<tr><td>First</td>
<td>Second</td></tr>
</table>
<br/>
<table cellspacing="0" cellpadding="10">
<tr><td>First</td><td>Second</td></tr>
</table>
</body>
</html>
51
HTML Frames
Frame divides a browser window into several individual frames or panes, each pane
containing a separate HTML page.
The page can be split into separate views (frames) horizontally and vertically.
One of the key advantages that frames offer is that you can then load and reload single
panes without having to reload the entire contents of the browser window.
• A lot of beginners use frames in their sites, particularly creating one for navigation and
the other for content. But then as they learn more about HTML and XHTML they tend to
HTML Frames cont…
• A couple of other drawbacks you should be aware of with frames are as follows:
Some smaller devices cannot cope with frames, often because their screen is not big enough to
be divided up.
Frames are not supported by all user agents (browsers, search engines, etc.)
The browser’s back button might not work as the user hopes and so on.
When writing a frameset document, you use a different DOCTYPE declaration. This is because
frameset documents use a few elements in different ways than other XHTML documents.
53
Cont…
HTML Frames
<frameset> and <frame>
HTML Frames cont…
To create a frameset document, first you need the <frameset> element, which is used
instead of the <body> element.
The frameset defines the rows and columns your page is divided into, which in turn
specify where each individual frame will go. Each frame is then represented by a
<frame> element.
You also need to use the <noframes> element, which provides a message for users whose
browsers do not support frames.
The <frameset> element have many attributes rows, cols, noresize, scrolling, and src.
But rows and cols attributes used to specify the number of rows and columns that make
55
Cont…
• <!DOCTYPE html>
• <html>
• <head>
• <title>Frame</title>
• </head>
• <frameset cols="50%,50%">
• <frame src=“frame1.html">
• <frame src=“frame2.html">
• <noframes>Sorry! Your browser does not support frames. </noframes>
• </frameset>
• </html>
56
HTML iframes (internal frames)
An HTML <iframe> is used to display a web page within a web page.
The HTML <iframe> tag specifies an inline frame.
An inline frame is used to embed another document within the current
HTML document.
It is a good practice to always include a title attribute for the <iframe>.
This is used by screen readers to read out what the content of the iframe is.
Summary
57
iframes:
• The iframe element lets you embed a separate HTML
document or other web resource in a document.
• Example: <iframe src=“check.html” width=“500”
height=“300”> </iframe>
HTML Forms:
• Forms are used to collect input from the user.
• Forms are added to web pages with the <form> element.
• Example: Output:
<form>
<label for="tname">Name </label>
<input type="text" id="tname"><br>
</form>
TEXT FIELDS:
• Text fields are used for entering a single word or line of text.
• Add a text input field to a form by inserting an input element with its type
attribute set to text.
Output
• Example:
<form>
<label for="tname">Name </label>
<input type="text" id="tname“ value=“Abel”
maxlength=“30”><br>
</form>
Multiline text-entry field:
• Textarea element, is used for multiline, scrollable
text entry box when displayed by the browser.
Output:
• Example:
<form>
<label for=“com">Name </label>
<textarea id=“com” cols=“6” rows=“12”>write your comment
</textarea>
</form>
Password entry field:
• the input type password makes the inputted text hidden.
• Example: Output:
<form>
<label for=“pass">Password </label>
<input type=“password" id=“pass”><br>
</form>
Radio buttons:
• Radio buttons are added to a form via the input
element with the type attribute set to “radio.”
• Example
Output:
<label for="gend">Gender</label>
<input type="radio" id="gend" value="male"
name="gender">Male
<input type="radio" id="gend" value="female"
name="gender">Female
Check box:
• Checkboxes are added via the input element with its type
set to checkbox.
• Check boxes allows the user to select multiple options.
• Example
<label for="gend">Select your Hobbies</label><br>
<input type="checkbox" name="hobbie"
value="football">Playing football<br>
<input type="checkbox" name="hobbie"
value="games">Playing games
<br>
<input type="checkbox" name="hobbie"
value="sing">singing songs
Menus or Combo box:
• Another way to provide a list of choices is to put them in a drop-
down or scrolling menu.
• Example:
<form>
<label for="cnt">country</label><br> Output:
<select id="cnt">
<option>Ethiopia</option>
<option>Uganda</option>
<option>Kenya</option>
</select>
</form>
File selection control
• The file selection control makes it possible for users to select a
document from the hard drive to be submitted with the form data.
• We add it to the form by using input element, with its type set to
file.
• Example: Output:
<form>
<p>select your file</p>
<input type="file" name="image">
</form>
Submit and reset button
• <input type="submit"> Submits the form data to the server
• <input type="reset"> Resets the form controls to their default
settings.
Output:
• Example:
<form>
<input type="submit" value="Register">
<input type="Reset" value="Clear">
</form>
HTML Graphics
There are two modern web technologies for creating rich drawn graphics within the
Canvas: A hypertext markup language element introduced in HTML5 for creating and
The Canvas specification provides a JavaScript API for accessing the element's graphics
SVG: An XML-based vector graphics format. It is a markup language for describing all
aspects of an image or web application, from the geometry of shapes, to the styling of simple
71
Scalable Vector Graphics (SVG) in HTML
SVG has several methods for drawing paths, boxes, circles, text, and
Example
graphic images. The stroke attribute is a presentation attribute defining the color
(or any SVG paint servers like gradients or patterns) used to
paint the outline of the shape; Note: As a presentation attribute
stroke can be used as a CSS property.
72
Difference b/n SVG and Canvas
• SVG • Canvas
• Vector based (composed of • Raster based (composed of
shapes). pixel).
• Modified through CSS and Script. • Modified through Script.
• Better scalability. Can be printed • Poor scalability. Not suitable for
with high quality. printing on higher resolution.
Q&A