HTML (Hyper Text Markup Language) Sample Code
HTML (Hyper Text Markup Language) Sample Code
Sample Code
1 A very simple HTML document
2 Giving comments
3 Simple paragraph tag
4 Paragraph with multiple lines in the source code
5 Problems with HTML Spacing
6 Preformat tag
7 Line Breaks on web page
8 HTML Headings
9 Centralized heading
10 Giving Horizontal Line on a web page
11 Add a Background Color
12 Add a Background Color
13 Add a Background Image
14 Text formatting
15 Insert Image
16 Adjust Images to different Sizes
17 Working with Images from Different Folder
18 Working with Moving Images
19 Display an Alternate Text for an Image
20 How to create Hyperlinks
21 Set an Image as a Link
22 Open a Link in a new browser window
23 Jumping to another part of a document in the same page
24 How to link to a mail message
25 Simple Unordered List
26 Nested Unordered List
27 Bulleted List
28 An Ordered List
29 A Numbered List
30 A Definition List
31 Simple Tables
32 Different Table Borders
33 Table with no borders
34 Headings in a Table
35 Table with Empty Cells
36 Table cell spans more than one row or column-
36 Tags inside table
37 Cell padding the white space between cell content and the border
38 Cell Spacing - control the distance between cells
39 Align the Content in a Table Cell
40 Add a Background Color or a Background image to a Table Cell
41 How to Create Input Field
42 How to Create Password Field
43 How to Create MultiLine Input Field
44 How to Use Check Boxes
45 How to Use Radio Buttons on a Form
46 How to Create Simple Drop-Down List
47 How to Create Drop-Down box with pre-selected Value
48 How to Create Push Buttons
49 How to Draw a Border with a Caption Around Data
50 Source code of navigation frame
51 HTML file for creating frame for navigation
Example 23, Jumping to another part of a document in the same page Go Top
<html>
<body>
<p>
<a href="#C4">
See also Chapter 4.
</a>
</p>
<p>
<h2>Chapter 1</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 2</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 3</h2>
<p>This chapter explains ba bla bla</p>
<a name="C4"><h2>Chapter 4</h2></a>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 5</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 6</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 7</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 8</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 9</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 10</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 11</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 12</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 13</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 14</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 15</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 16</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 17</h2>
<p>This chapter explains ba bla bla</p>
</body>
</html>
Example 36, Table cell spans more than one row or column Go Top
<html>
<body>
<h4>Cell that spans two columns:</h4>
<table border="1">
<tr>
<th>Name</th>
<th colspan="2">Telephone</th>
</tr>
<tr>
<td>Bill Gates</td>
<td>555 77 854</td>
<td>555 77 855</td>
</tr>
</table>
<h4>Cell that spans two rows:</h4>
<table border="1">
<tr>
<th>First Name:</th>
<td>Bill Gates</td>
</tr>
<tr>
<th rowspan="2">Telephone:</th>
<td>555 77 854</td>
</tr>
<tr>
<td>555 77 855</td>
</tr>
</table>
</body>
</html>
Example 37, Cell padding the white space between cell content and the border Go
Top
<html>
<body>
<h4>Without cellpadding:</h4>
<table border="1">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With cellpadding:</h4>
<table border="1"
cellpadding="10">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
</body>
</html>
Example 38, Cell Spacing - control the distance between cells Go Top
<html>
<body>
<h4>Without cellspacing:</h4>
<table border="1">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With cellspacing:</h4>
<table border="1"
cellspacing="10">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
</body>
</html>
Example 47, How to Create Drop-Down box with pre-selected Value Go Top
<html>
<body>
<form>
<select name="cars">
<option value="volvo">Volvo
<option value="saab">Saab
<option value="fiat" selected>Fiat
<option value="audi">Audi
</select>
</form>
</body>
</html>
Example 49, How to Draw a Border with a Caption Around Data Go Top
<html>
<body>
<fieldset>
<legend>
Health information:
</legend>
<form>
Height <input type="text" size="3">
Weight <input type="text" size="3">
</form>
</fieldset>
<p>
If there is no border around the input form, your browser is too old.
</p>
</body>
</html>
Example 51, HTML file for creating frame for navigation Go Top
<html>
<frameset cols="120,*">
<frame src="framea.htm">
<frame src="frameb.htm" name="showframe">
</frameset>
</html>