Professional Documents
Culture Documents
What is HTML?
HTML Tags
HTML Elements
An HTML element usually consists of a start tag and end tag, with the content
inserted in between:
The HTML element is everything from the start tag to the end tag
<br> is an empty element without a closing tag (the <br> tag defines a line
break).
Empty elements can be "closed" in the opening tag like this: <br />.
HTML5 does not require empty elements to be closed. But if you want stricter
validation, or if you need to make your document readable by XML parsers, you
must close all HTML elements properly.
1
HTML Attributes
HTML tags are not case sensitive: <P> means the same as <p>.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
</body>
</html>
HTML Headings
<h1> defines the most important heading. <h6> defines the least important
heading:
2
<html>
<body>
</body>
</html>
HTML Links
HTML Images
The source file (src), alternative text (alt), width, and height are provided as
attributes, The alt attribute provides an alternate text for an image, if the user for
some reason cannot view it (because of slow connection, an error in the src
attribute, or if the user uses a screen reader).
If a browser cannot find an image, it will display the value of the alt attribute
3
<img src="w3schools.jpg" alt="W3Schools.com" width="104" height="142">
However, it is common to store images in a sub-folder. You must then include the
folder name in the src attribute.
Double quotes around attribute values are the most common in HTML, but single
quotes can also be used.
In some situations, when the attribute value itself contains double quotes, it is
necessary to use single quotes:
Or vice versa:
With HTML, you cannot change the output by adding extra spaces or extra lines in
your HTML code.
The browser will remove any extra spaces and extra lines when the page is
displayed:
<p>
This paragraph
contains a lot of lines
in the source code,
but the browser
ignores it.
</p>
<pre>
This paragraph
contains a lot of spaces
in the source code,
now the browser
considers it.
</pre>
4
<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
<!DOCTYPE html>
<html>
<body>
<p><mark>Hello</mark></p>
<p><small>Hello</small></p>
<p><del>Hello</del></p>
</body>
</html>
<html>
<body>
<p>WWF's goal is to: <q>Build a future where people live in harmony with nature.</q></p>
5
<blockquote>
</blockquote>
<address>
Visit us at:<br>
Example.com<br>
USA
</address>
</body>
</html>
6
HTML Comments
Notice that there is an exclamation point (!) in the opening tag, but not in the
closing tag.
HTML Colors
In HTML, a color can be specified by using a
i. Color name, or
ii. RGB value, or
iii. HEX value.
<font color="orange">
Font-color set by using orange
</font>
<h2 style="background-color:red">
Background-color set by using red
</h2>
<h2 style="background-color:rgb(255,0,0)">
Background-color set by using rgb(255,0,0)
</h2>
7
<h2 style="background-color:rgb(190,0,0)">
Background-color set by using rgb(0,255,0)
</h2>
<h2 style="background-color:rgb(100,30,255)">
Background-color set by using rgb(0,0,255)
</h2>
<h2 style="background-color:#FF0000">
Background-color set by using #FF0000
</h2>
<h2 style="background-color:#00FF00">
Background-color set by using #00FF00
</h2>
HTML Tables
<html>
<body>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Bill</td>
<td>Gates</td>
<td>65</td>
</tr>
<tr>
<td>Arnold</td>
<td>Subasinghe</td>
<td>48</td>
8
</tr>
<tr>
<td>Dawal</td>
<td>Tharu</td>
<td>18</td>
</tr>
</table>
</body>
</html>
<html>
<body bgcolor="orange">
<tr bgcolor="pink">
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<html>
<body bgcolor="orange">
<tr>
<th colspan=2>Name</th>
<th rowspan=2>Age</th>
</tr>
<tr>
<th>Firstname</th>
<th>Lastname</th>
9
</tr>
<tr>
<td>Bill</td>
<td>Gates</td>
<td>65</td>
</tr>
<tr>
<td>Arnold</td>
<td>Subasinghe</td>
<td>48</td>
</tr>
<tr>
<td>Dawal</td>
<td>Tharu</td>
<td>18</td>
</tr>
</table>
</body>
</html>
HTML Lists
1. Unordered List
<html>
<body>
<ul>
<li>Coffee</li>
<li>Tea</li>
10
</ul>
</body>
</html>
The HTML type or CSS list-style-type property is used to define the style of the
list item marker:
Value Description
<ul type="square">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
2. Ordered List
<html>
<body>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
11
Type Description
type="I" The list items will be numbered with uppercase roman numbers
type="i" The list items will be numbered with lowercase roman numbers
<html>
<body>
<dl>
<dt>Coffee</dt>
<dt>Milk</dt>
</dl>
</body>
</html>
HTML Forms
Type Description
<input type="radio"> Defines a radio button (for selecting one of many choices)
12
<form>
First name: <input type="text" name="firstname">
<br>
Last name: <input type="text" name="lastname">
</form>
<form action="/action_page.php">
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
<br><br>
<input type="submit">
</form>
The action attribute defines the action to be performed when the form is submitted.
Normally, the form data is sent to a web page on the server when the user clicks on the submit button.
In the example above, the form data is sent to a page on the server called "/action_page.php". This page
contains a server-side script that handles the form data:
<form action="/action_page.php">
<br>
<input type="submit">
</form>
13
<form action="">
First name:<br>
<br>
Last name:<br>
</form>
<form action="/action_page.php">
<input type="submit">
</form>
However, when GET is used, the submitted form data will be visible in the page address field:
14
Clear Input Field with a Button
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Copy a Text
<!DOCTYPE html>
<html>
<body>
<p>A function is triggered when the button is clicked. The function copies the text from Field1 into
Field2.</p>
<script>
15
function myFunction() {
document.getElementById("field2").value = document.getElementById("field1").value;
</script>
</body>
</html>
16