Internet Programming Chapter 2. HTML.
Internet Programming Chapter 2. HTML.
HTML
By FIRAOL K. (Msc.)
[email protected]
[email protected]
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
Example Explained
• The DOCTYPE declaration defines the document type.
• The text between <html> and </html> describes the web page.
• The text between <body> and </body> is the visible page content.
• The text between <h1> and </h1> is displayed as a heading.
• The text between <p> and </p> is displayed as a paragraph.
• "HTML tags" and "HTML elements" are often used to describe the same thing.
• But strictly speaking, an HTML element is everything between the start tag and the end tag,
including the tags:
HTML Element:
<p>This is a paragraph.</p>
• The purpose of a web browser (such as Google Chrome, Internet Explorer, Firefox,
Safari) is to read HTML documents and display them as web pages.
• The browser does not display the HTML tags, but uses the tags to determine how the
content of the HTML page is to be presented/displayed to the user:
<h1>This is heading1<h1>
<h2>This is heading1<h2>
<h3>This is heading1<h3>
<h4>This is heading1<h4>
<h5>This is heading1<h5>
<h6>This is heading1<h6>
Attribute Description
Class Specifies one or more class names for an element (refers to a class in a
style sheet)
Tag Description
• HTML uses tags like <b> and <i> for formatting output, like bold or italic text.
HTML Text Formatting Tags
Tag Description
• The <head> element is a container for all the head elements. Elements inside <head> can include scripts,
instruct the browser where to find style sheets, provide meta information, and more.
• The following tags can be added to the head section: <title>, <style>, <meta>, <link>, <script>, <noscript>,
and <base>.
The HTML <title> Element
• The <title> tag defines the title of the document.
• The <title> element is required in all HTML/XHTML documents.
• The <title> element:
Defines a title in the browser toolbar.
Provides a title for the page when it is added to favorites.
Displays a title for the page in search-engine results.
The HTML <base> Element
• The <base> tag specifies the base URL/target for all relative URLs in a page:
• <head>
<base href="http://www.w3schools.com/images/" target="_blank">
</head>
The HTML <link> Element
• The <link> tag defines the relationship between a document and an external resource.
• The <link> tag is most used to link to style sheets:
• <head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
The HTML <style> Element
• The <style> tag is used to define style information for an HTML document.
• Inside the <style> element you specify how HTML elements should render in a browser:
<head>
<style type="text/css">
body {background-color:yellow;
}
p {color:blue;
}
</style>
</head>
Friday, April 04, 2025 Instructor: FIRAOL K (Msc.) 17
The HTML <meta> Element
• An internal style sheet can be used if one single document has a unique style. Internal styles are defined in the <head> section
of an HTML page, by using the <style> tag, like this:
• <head>
<style>
body {background-color:yellow;}
p {color:blue;}
</style>
</head>
• An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can
change the look of an entire Web site by changing one file. Each page must link to the style sheet using the
<link> tag. The <link> tag goes inside the <head> section:
• <head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
• A table is divided into rows with the <tr> tag. (tr stands for table row)
• A row is divided into data cells with the <td> tag. (td stands for table data)
• A row can also be divided into headings with the <th> tag. (th stands for table heading)
• The <td> elements are the data containers in the table.
• The <td> elements can contain all sorts of HTML elements like text, images, lists, other
tables, etc.
• The width of a table can be defined using CSS.
Example
• table
{
border-spacing:5px;
}
• The most common HTML lists are ordered and unordered lists:
• An unordered list starts with the <ul> tag. Each list item starts with the <li>
tag.
• The list items are marked with bullets (typically small black circles).
<ul>
<li>Coffee</li>
<li>Milk</li>
</ul>
• An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.
• The list items are marked with numbers.
<ol>
<li>Coffee</li>
<li>Milk</li>
</ol>
• The <dl> tag is used in conjunction with <dt> (defines terms/names) and <dd> (describes
each term/name):
• <dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
Tag Description
• The HTML <div> element is a block level element that can be used as a container for
grouping other HTML elements.
• The <div> element has no special meaning. Except that, because it is a block level
element, the browser will display a line break before and after it.
• When used together with CSS, the <div> element can be used to set style attributes to
large blocks of content.
• Another common use of the <div> element, is for document layout. It replaces the "old
way" of defining layout using tables. Using <table> elements for layout is not the correct
use of <table>. The purpose of the <table> element is to display tabular data.
Tag Description
• Most websites have put their content in multiple columns (formatted like a
magazine or newspaper).
• Multiple columns are created by using <div> or <table> elements. CSS are used to
position elements, or to create backgrounds or colorful look for the pages.
• NB: Even though it is possible to create nice layouts with HTML tables, tables were
designed for presenting tabular data - NOT as a layout tool!
• The div element is a block level element used for grouping HTML elements.
Example
<!DOCTYPE html>
<html>
<body>
<div id="container" style="width:500px">
<div id="header" style="background-color:#FFA500;">
<h1 style="margin-bottom:0;">Main Title of Web Page</h1></div>
<div id="menu" style="background-color:#FFD700;height:200px;width:100px;float:left;">
<b>Menu</b><br>
HTML<br>
CSS<br>
• JavaScript</div>
<div id="content" style="background-
color:#EEEEEE;height:200px;width:400px;float:left;">
Content goes here</div>
<div id="footer" style="background-color:#FFA500;clear:both;text-
align:center;">
Copyright © W3Schools.com</div>
</div>
</body>
</html>
• <form>
Password: <input type="password" name="pwd">
</form>
• Note: The characters in a password field are masked (shown as
asterisks or circles).
<form>
<input type="radio" name="sex" value="male">Male<br>
<input type="radio" name="sex" value="female">Female
</form>
• NB: If you type some characters in the text field above, and click the "Submit" button, the
browser will send your input to a page called "html_form_action.asp".
The page will show you the received input.
HTML Form Tags
Tag Description
<form> Defines an HTML form for user input.
<input> Defines an input control.