HTML
HTML
DFT3013
HTML
LO
Create web page using HTML – Apply BODY tag with Bgcolor,
– Describe HTML – Apply background with image and text
– Define Markup language color.
– Identify the structure of HTML – Identify Text formatting
document: – Identify Text attributes
– a. <html>
– Heading tags (H1–H6)
– b. <head>
– c. <title> – Marquee text with or without
background, Blink the text attributes
– d. <body>
– Explain the Head section and its – Divide section using <HR> line with
width, align, size
elements
– a. Meta tags – Create a simple HTML file.
– b. external link tags
What is HTML?
– You can add metadata to your web pages by placing <meta> tags
inside the header of the document which is represented by
<head> and </head> tags. A meta tag can have following
attributes in addition to core attributes:
Example
– The <link> tag defines a link between a document and an external resource.
– The <link> tag is used to link to external style sheets.
<head>
<link rel="stylesheet" type="text/css" href="theme.css">
</head>
– Note: The <link> element is an empty element, it contains attributes only.
– Note: This element goes only in the head section, but it can appear any
number of times.
The <!DOCTYPE> Declaration
</body>
</html>
– Step 3: Save the HTML Page
– Save the file on your computer. Select File > Save as in the Notepad menu.
– Name the file "index.htm" and set the encoding to UTF-8 (which is the
preferred encoding for HTML files).
– There are following three different methods to set colors in your web page:
– Color names - You can specify color names directly like green, blue or red.
– Hex codes - A six-digit code representing the amount of red, green, and blue
that makes up the color.
– Color decimal or percentage values - This value is specified using the rgb( )
property.
https://www.tutorialspoint.com/html/html_colors.htm
Example
HTML <body> background
Attribute
– HTML also defines special elements for defining text with a special meaning.
– 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 https://www.w3schools.com/html/html_formatting.asp
Heading tags (H1–H6)
– The <hr> tag defines a thematic break in an HTML page (e.g. a shift of topic).
– The <hr> element is used to separate content (or define a change) in an
HTML page.
– In HTML5, the <hr> tag defines a thematic break.
– In HTML 4.01, the <hr> tag represents a horizontal rule.
– However, the <hr> tag may still be displayed as a horizontal rule in visual
browsers, but is now defined in semantic terms, rather than presentational
terms.
– All the layout attributes are removed in HTML5. Use CSS instead.
<HR> line with width, align, size
Hyperlinks
HTML
LO
Hyperlinks
– Use the <a> tag to link:
– a. within a page
– b. between pages
Hyperlinks
– Links are the defining feature of the web because they allow you to move
from one web page to another — enabling the very idea of browsing or
surfing.
– You will commonly come across the following types of links:
– Links from one website to another
– Links from one page to another on the same website
– Links from one part of a web page to another part of the same page
– Links that open in a new browser window
– Links that start up your email program and address a new email to someone
<a> tag
– A link is specified using HTML tag <a>. This tag is called anchor tag and
anything between the opening <a> tag and the closing </a> tag becomes part
of the link and a user can click that part to reach to the linked document.
Following is the simple syntax to use <a> tag.
– <a href="Document URL" ... attributes-list>Link Text</a>
Writing Links
Links are created using the <a> element. Users can click on anything
between the opening <a> tag and the closing </a> tag. You specify
which page you want to link to using the href attribute.
Linking to Other Sites
<p>List of polytechnics:
<ul>
<li><a href="http://www.psp.edu.my">
PSP</a></li>
<li><a href="http://www.puo.edu.my">
PUO</a></li>
<li><a href="http://www.ptss.edu.my ">
PTSS</a></li>
<li><a href="http://www.polimas.edu.my">
POLIMAS</a></li>
</ul>
</p> When you link to a different website, the
value of the href attribute will be the full
web address for the site, which is known
as an absolute URL.
Linking to Other Pages on the
Same Site
<p>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about-us.html">About</a></li>
<li><a href="movies.html">Movies</a></li>
<li><a href="contact.html">Contact</a></li>
</ul> When you are linking to other pages within the
same site, you do not need to specify the
</p>
domain name in the URL. You can use a
shorthand known as a relative URL.
Linking to a Specific Part of the
Same Page
<h1 id="top">Film-Making Terms</h1>
<h2 id="prologue">Prologue</h2>
<p>A speech, preface, introduction, or brief scene
<p><a href="#top">Top</a></p>
HTML Links - The target
Attribute
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
</head>
<body>
<p>Click any of the following links</p>
<a href="www.psp.edu.my" target="_blank">Opens in
New</a> |
<a href="www.psp.edu.my" target="_self">Opens in Self</a> |
<a href="www.psp.edu.my" target="_parent">Opens in
Parent</a> |
<a href="www.psp.edu.my" target="_top">Opens in Body</a>
</body>
</html>
Example
HiDAAHM | JUN2017
Table
HTML
LO
Table
– Set table and cell colour.
– Cell padding, table border and cell spacing.
– Align text in cells (horizontally, vertically).
– Set column and row span.
Table
– You can set table background using one of the following two ways:
– bgcolor attribute - You can set background color for whole table or just for
one cell.
– background attribute - You can set background image for whole table or just
for one cell.
– You can also set border color also using bordercolor attribute.
Tables Backgrounds
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Background</title>
</head>
<body>
<table border="1" bordercolor="green" bgcolor="yellow">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr><td rowspan="2">Row 1 Cell 1</td><td>Row 1 Cell 2</td><td>Row 1 Cell 3</td></tr>
<tr><td>Row 2 Cell 2</td><td>Row 2 Cell 3</td></tr>
<tr><td colspan="3">Row 3 Cell 1</td></tr>
</table>
</body>
</html>
Tables Backgrounds
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Background</title>
</head>
<body>
<table border="1" bordercolor="green" background="/images/test.png">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr><td rowspan="2">Row 1 Cell 1</td><td>Row 1 Cell 2</td><td>Row 1 Cell
3</td></tr>
<tr><td>Row 2 Cell 2</td><td>Row 2 Cell 3</td></tr>
<tr><td colspan="3">Row 3 Cell 1</td></tr>
</table>
</body>
</html>
Cellpadding and Cellspacing
Attributes
– There are two attribiutes called cellpadding and cellspacing which you will
use to adjust the white space in your table cells.
– The cellspacing attribute defines the width of the border, while cellpadding
represents the distance between cell borders and the content within a cell.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Cellpadding</title>
</head>
<body>
<table border="1" cellpadding="5" cellspacing="5">
<tr>
<th>Name</th>
<th>Salary</th>
</tr>
<tr>
<td>Ramesh Raman</td>
<td>5000</td>
</tr>
<tr>
<td>Shabbir Hussein</td>
<td>7000</td>
</tr>
</table>
</body>
</html>
Colspan and Rowspan
Attributes
– You will use colspan attribute if you want to merge two or more columns into
a single column. Similar way you will use rowspan if you want to merge two
or more rows.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Colspan/Rowspan</title>
</head>
<body>
<table border="1">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr><td rowspan="2">Row 1 Cell 1</td><td>Row 1 Cell 2</td><td>Row 1 Cell
3</td></tr>
<tr><td>Row 2 Cell 2</td><td>Row 2 Cell 3</td></tr>
<tr><td colspan="3">Row 3 Cell 1</td></tr>
</table>
</body>
</html>
HTML <tr> align Attribute
– The align attribute specifies the horizontal alignment of the content in a table
row.
– The align attribute of <tr> is not supported in HTML5. Use CSS instead.
– CSS syntax: <tr style="text-align:right">
– Syntax
– <tr align="left|right|center|justify|char">
HTML <tr> align Attribute
Example
<table>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr align="right">
<td>January</td>
<td>$100</td>
</tr>
</table>
Frames
HTML
HiDAYAHM | JUN2017
LO
– HTML frames are used to divide your browser window into multiple sections
where each section can load a separate HTML document.
– A collection of frames in the browser window is known as a frameset. The
window is divided into frames in a similar way the tables are organized: into
rows and columns.
Creating Frames
<!DOCTYPE html>
<html>
<head>
<title>HTML Frames</title>
</head>
<frameset rows="10%,80%,10%">
<frame name="top" src="/html/top_frame.htm" />
<frame name="main" src="/html/main_frame.htm" />
<frame name="bottom" src="/html/bottom_frame.htm" />
<noframes>
<body>
Your browser does not support frames.
</body>
</noframes>
</frameset>
</html>
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Frames</title>
</head>
<frameset cols="25%,50%,25%">
<frame name="left" src="/html/top_frame.htm" />
<frame name="center" src="/html/main_frame.htm" />
<frame name="right" src="/html/bottom_frame.htm" />
<noframes>
<body>
Your browser does not support frames.
</body>
</noframes>
</frameset>
</html>
The <frameset>
Tag Attributes
The <frame>
Tag Attributes
Frame Design
<!DOCTYPE html>
<html>
<head>
<title>HTML Target Frames</title>
</head>
<frameset cols="200, *">
<frame src="/html/menu.htm" name="menu_page" />
<frame src="/html/main.htm" name="main_page" />
<noframes>
<body>
Your browser does not support frames.
</body>
</noframes>
</frameset>
</html>
Frame Design
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<html>
<body bgcolor="#4a7d49">
<body bgcolor="#b5dcb3">
<a href="https://www.google.com"
<h3>This is main page and content from any
target="main_page">Google</a>
link will be displayed here.</h3>
<br /><br />
<p>So now click any link and see the
<a href="https://www.microsoft.com"
result.</p>
target="main_page">Microsoft</a>
</body>
<br /><br />
</html>
<a href="https://news.bbc.co.uk"
target="main_page">BBC News</a>
</body>
</html>
target
Forms in a web page
HTML
HiDAYAHM | JUN2017
LO
– The HTML <form> element defines a form that is used to collect user input:
<form action="Script URL" method="GET|POST">
form elements like input, textarea etc.
</form>
– An HTML form contains form elements.
– Form elements are different types of input elements, like text fields,
checkboxes, radio buttons, submit buttons, and more.
GET & POST Methods
– There are two ways the browser client can send information to the web server.
– The GET Method
– The POST Method
– Before the browser sends the information, it encodes it using a scheme called
URL encoding.
– In this scheme, name/value pairs are joined with equal signs and different pairs are
separated by the ampersand.
– name1=value1&name2=value2&name3=value3
– Spaces are removed and replaced with the + character and any other non-alphanumeric
characters are replaced with a hexadecimal values.
– After the information is encoded it is sent to the server.
The GET Method
– The GET method sends the encoded user information appended to the page request.
The page and the encoded information are separated by the ? character.
– http://www.test.com/index.htm?name1=value1&name2=value2
– The GET method produces a long string that appears in your server logs, in the
browser's Location: box.
– The GET method is restricted to send up to 1024 characters only.
– Never use GET method if you have password or other sensitive information to be
sent to the server.
– GET can't be used to send binary data, like images or word documents, to the
server.
– The data sent by GET method can be accessed using QUERY_STRING environment
variable.
– The PHP provides $_GET associative array to access all the sent information using
GET method.
Example
<?php
if( $_GET["name"] || $_GET["age"] ) {
echo "Welcome ". $_GET['name']. "<br />";
echo "You are ". $_GET['age']. " years old.";
exit();
}
?>
<html>
<body>
<form action = "<?php $_PHP_SELF ?>" method = "GET">
Name: <input type = "text" name = "name" />
Age: <input type = "text" name = "age" />
<input type = "submit" />
</form>
</body>
</html>
The POST Method
– The POST method transfers information via HTTP headers. The information is
encoded as described in case of GET method and put into a header called
QUERY_STRING.
– The POST method does not have any restriction on data size to be sent.
– The POST method can be used to send ASCII as well as binary data.
– The data sent by POST method goes through HTTP header so security depends on
HTTP protocol. By using Secure HTTP you can make sure that your information is
secure.
– The PHP provides $_POST associative array to access all the sent information using
POST method.
Example
<?php
if( $_POST["name"] || $_POST["age"] ) {
if (preg_match("/[^A-Za-z'-]/",$_POST['name'] )) {
die ("invalid name and name should be alpha");
}
echo "Welcome ". $_POST['name']. "<br />";
echo "You are ". $_POST['age']. " years old.";
exit();
}
?>
<html>
<body>
<form action = "<?php $_PHP_SELF ?>" method = "POST">
Name: <input type = "text" name = "name" />
Age: <input type = "text" name = "age" />
<input type = "submit" />
</form>
</body>
</html>
A form may have several form controls,
each gathering different information.
The server needs to know which piece
of inputted data corresponds with
which form element.
Form
https://www.tutorialspoint.com/html/html_forms.htm
https://www.w3schools.com/html/html_forms.asp
https://www.javatpoint.com/html-form
– a. text box
– b. radio button
– c. combo box
– d. text area
– e. submit button
– f. reset button
– g. file upload field
– h. hidden textfield
– i. password textfield
Example