PL Lec 1
PL Lec 1
Programming Languages
Lecture One
HTML Basics
Prepared By
1- What is HTML?
HTML stands for Hyper Text Markup Language, which is the most widely
used language on Web to develop web pages.
2- HTML Tags:
Sr.No Tag & Description
1 <!DOCTYPE...>
3- Quick Examples:
For the following examples, just copy the HTML code to a text file,
and modify the extension to .html instead of .txt, then open the
file with any browser.
<head>
<title>Heading Example</title>
</head>
<body>
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>
</body>
</html>
كلية الهندسة المعلوماتية
<head>
<title>Paragraph Example</title>
</head>
<body>
<p>Here is a first paragraph of text.</p>
<p>Here is a second paragraph of text.</p>
<p>Here is a third paragraph of text.</p>
</body>
</html>
<head>
<title>Line Break Example</title>
</head>
<body>
<p>Hello<br />
You delivered your assignment
ontime.<br />
Thanks<br />
Mahnaz</p>
</body>
</html>
كلية الهندسة المعلوماتية
For example, <p> is starting tag of a paragraph and </p> is closing tag of
the same paragraph but <p>This is paragraph</p> is a paragraph element.
Example:
<head>
<title>Nested Elements Example</title>
</head>
<body>
<h1>This is <i>italic</i> heading</h1>
<p>This is <u>underlined</u> paragraph</p>
</body>
</html>
Core attributes:
Id
Title
Class
Style
Generic attributes:
Example:
<head>
<title>Align Attribute Example</title>
</head>
<body>
<p id = "p1" align = "left">This is left aligned</p>
<p id = "p2" align = "center">This is center aligned</p>
<p id = "p3" align = "right">This is right aligned</p>
</body>
</html>
Result
7- Comments:
Comment is a piece of code which is ignored by any web browser. It is a
good practice to add comments into your HTML code, especially in complex
documents, to indicate sections of a document, and any other notes to
anyone looking at the code. Comments help you and others understand
your code and increases code readability.
كلية الهندسة المعلوماتية
Example:
<!DOCTYPE html>
<html>
<body>
<p>Document content goes here.....</p>
</body>
</html>
8- Images:
You can insert any image in your web page by using <img> tag. Following is
the simple syntax to use this tag.
<img src = "Image URL" ... attributes-list/>
Example: (To try following example, keep your HTML file test.html and
image file test.png in the same directory)
<head>
<title>Using Image in Webpage</title>
</head>
<body>
<p>Simple Image Insert</p>
<img src = "/html/images/test.png" alt = "Test Image" />
</body>
</html>
كلية الهندسة المعلوماتية
Result
<head>
<title>Set Image Width and Height</title>
</head>
<body>
<p> Simple Image Insert</p>
<img src = "/html/images/test.png" alt = "Test Image" width
= "150" height = "100"/>
</body>
</html>
Result
كلية الهندسة المعلوماتية
9- Tables:
The HTML tables allow web authors to arrange data like text, images, links,
other tables, etc. into rows and columns of cells.
The HTML tables are created using the <table> tag in which the <tr> tag is
used to create table rows and <td> tag is used to create data cells. The
elements under <td> are regular and left aligned by default
Example:
<head>
<title>HTML Tables</title>
</head>
<body>
<table border = "1">
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
</tr>
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
</tr>
</table>
</body>
</html>
Result
كلية الهندسة المعلوماتية
Example:
<head>
<title>HTML Unordered List</title>
</head>
<body>
<ul>
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ul>
</body>
</html>
Result
كلية الهندسة المعلوماتية
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol>
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
Result
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>
كلية الهندسة المعلوماتية
Example:
<head>
<title>Hyperlink Example</title>
</head>
<body>
<p>Click following link</p>
<a href = "https://www.example.com">Example</a>
</body>
</html>
Result
Cascading Style Sheets (CSS) provide easy and effective alternatives to specify
various attributes for the HTML tags. Using CSS, you can specify a number of style
properties for a given HTML element. Each property has a name and a value,
separated by a colon (:). Each property declaration is separated by a semi-colon
(;).
كلية الهندسة المعلوماتية
Example:
<head>
<title>HTML CSS</title>
</head>
<body>
<p style = "color:green; font-size:24px;" >Hello,
World!</p>
</body>
</html>
Result
External Style Sheet: Define style sheet rules in a separate .css file
and then include that file in your HTML document using HTML <link>
tag.
Internal Style Sheet: Define style sheet rules in header section of the
HTML document using <style> tag.
Inline Style Sheet: Define style sheet rules directly along-with the
HTML elements using style attribute.
كلية الهندسة المعلوماتية
If you need to use your style sheet to various pages, then its always
recommended to define a common style sheet in a separate file. A cascading style
sheet file will have extension as .css and it will be included in HTML files using
<link> tag.
Example (create a style sheet file style.css in the same directory of html file):
<head>
<title>HTML External CSS</title>
<link rel = "stylesheet" type = "text/css" href =
"/html/style.css">
</head>
<body>
<p class = "red">This is red</p>
<p class = "thick">This is thick</p>
<p class = "green">This is green</p>
<p class = "thick green">This is thick and green</p>
</body>
</html>
كلية الهندسة المعلوماتية
Result
If you want to apply Style Sheet rules to a single document only, then you can
include those rules in header section of the HTML document using <style> tag.
Rules defined in internal style sheet overrides the rules defined in an external CSS
file.
Example:
<head>
<title>HTML Internal CSS</title>
<body>
<p class = "red">This is red</p>
<p class = "thick">This is thick</p>
<p class = "green">This is green</p>
<p class = "thick green">This is thick and green</p>
</body>
</html>
Result
You can apply style sheet rules directly to any HTML element using style attribute
of the relevant tag. This should be done only when you are interested to make a
particular change in any HTML element only.
Rules defined inline with the element overrides the rules defined in an external
CSS file as well as the rules defined in <style> element.
Example:
<head>
<title>HTML Inline CSS</title>
</head>
<body>
<p style = "color:red;">This is red</p>
<p style = "font-size:20px;">This is thick</p>
<p style = "color:green;">This is green</p>
كلية الهندسة المعلوماتية
</html>
Result
14- JavaScript:
A script is a small piece of program that can add interactivity to your website. For
example, a script could generate a pop-up alert box message, or provide a
dropdown menu. This script could be written using JavaScript or VBScript.
You can write various small functions, called event handlers using any of the
scripting language and then you can trigger those functions using HTML
attributes.
Now-a-days, only JavaScript and associated frameworks are being used by most of
the web developers, VBScript is not even supported by various major browsers.
You can keep JavaScript code in a separate file and then include it wherever it's
needed, or you can define functionality inside HTML document itself. Let's see
both the cases one by one with suitable examples.
كلية الهندسة المعلوماتية
External JavaScript
If you are going to define a functionality which will be used in various HTML
documents then it's better to keep that functionality in a separate JavaScript file
and then include that file in your HTML documents. A JavaScript file will have
extension as .js and it will be included in HTML files using <script> tag.
Example (create a javascript file script.js in the same directory of html file):
<head>
<title>Javascript External Script</title>
<script src = "/html/script.js" type =
"text/javascript"/></script>
</head>
<body>
<input type = "button" onclick = "Hello();" name = "ok"
value = "Click Me" />
</body>
</html>
Result
كلية الهندسة المعلوماتية
Internal JavaScript
You can write your script code directly into your HTML document. Usually we
keep script code in header of the document using <script> tag, otherwise there is
no restriction and you can put your source code anywhere in the document but
inside <script> tag.
Example:
<head>
<title>JavaScript Internal Script</title>
<body>
<input type = "button" onclick = "Hello();" name = "ok"
value = "Click Me" />
</body>
</html>
Result