HTML Tags Chart
HTML Tags Chart
source: [Link]
Tag Name Code Example Browser View
<!--This can be viewed in the HTML part of a
<!-- comment Nothing will show
document-->
<A HREF="[Link]
<A - anchor Visit Our Site
Our Site</A>
<B> bold <B>Example</B> Example
<BIG> big (text) <BIG>Example</BIG> Example
body of
<BODY> <BODY>The content of your page</BODY> Contents of your webpage
document
The contents of your page<BR>The contents of The contents of your page
<BR> line break
your page The contents of your page
<CENTER>This will center your
<CENTER> center This will center your contents
contents</CENTER>
<DL> Definition Term
<DT>Definition Term Definition of the
definition
<DD>Definition of the term term
<DD> descriptio
<DT>Definition Term Definition Term
n
<DD>Definition of the term Definition of the
</DL> term
<DL>
<DT>Definition Term Definition Term
definition <DD>Definition of the term Definition of the term
<DL>
list <DT>Definition Term Definition Term
<DD>Definition of the term Definition of the term
</DL>
<DL>
<DT>Definition Term Definition Term
definition <DD>Definition of the term Definition of the term
<DT>
term <DT>Definition Term Definition Term
<DD>Definition of the term Definition of the term
</DL>
This is an <EM>Example</EM> of using This is an Example of using
<EM> emphasis
the emphasis tag the emphasis tag
embed <EMBED src="[Link]" width="100%"
<EMBED>
object height="60" align="center">
heading
<HEAD>Contains elements describing the
<HEAD> of Nothing will show
document</HEAD>
document
<META name="Description"
content="Description of your site">
<META> meta Nothing will show
<META name="keywords" content="keywords
describing your site">
<META HTTP-EQUIV="Refresh"
<META> meta CONTENT="4;URL=[Link] Nothing will show
/">
<META http-equiv="Pragma" content="no-
<META> meta Nothing will show
cache">
<META> meta <META name="rating" content="General"> Nothing will show
<META> meta <META name="ROBOTS" content="ALL"> Nothing will show
<META NAME="ROBOTS"
<META> meta Nothing will show
content="NOINDEX,FOLLOW">
Example 1:
Example 1:
<OL>
<LI>List item 1 1. List item 1
<LI>List item 2 2. List item 2
<LI>List item 3 3. List item 3
<LI>List item 4 4. List item 4
</OL>
ordered
<OL>
list Example 2:
Example 2:
<OL type="a">
a. List item 1
<LI>List item 1 b. List item 2
<LI>List item 2 c. List item 3
<LI>List item 3 d. List item 4
<LI>List item 4
</OL>
<FORM METHOD=post ACTION="/cgi-
bin/[Link]">
<CENTER>
Select an option:
<SELECT>
<OPTION>option 1 Select an option:
listbox <OPTION SELECTED>option 2
<OPTION> option 2
option <OPTION>option 3
<OPTION>option 4
<OPTION>option 5
<OPTION>option 6
</SELECT><BR>
</CENTER>
</FORM>
This is an example displaying the use of the This is an example displaying
<P> paragraph paragraph tag. <P> This will create a line break the use of the paragraph tag.
and a space between lines.
This will create a line break
Attributes: and a space between lines.
<TABLE BORDER="4"
CELLPADDING="2" CELLSPACING="2"
WIDTH="100%"> Example 1:
<TR>
<TD>Column 1</TD> Column 1 Column 2
<TD>Column 2</TD>
</TR>
</TABLE>
Example 2:
Example 2: (Internet Explorer)
Column 1 Column 2
<TABLE> table <TABLE BORDER="2"
BORDERCOLOR="#336699"
CELLPADDING="2" CELLSPACING="2"
WIDTH="100%"> Example 3:
<TR>
<TD>Column 1</TD>
<TD>Column 2</TD> Column 1 Column 2
</TR> Row 2 Row 2
</TABLE>
Example 3:
<TABLE CELLPADDING="2"
CELLSPACING="2" WIDTH="100%">
<TR>
<TD BGCOLOR="#CCCCCC">Column 1</TD>
<TD BGCOLOR="#CCCCCC">Column 2</TD>
</TR>
<TR>
<TD>Row 2</TD>
<TD>Row 2</TD>
</TR>
</TABLE>
<TABLE BORDER="2" CELLPADDING="2"
CELLSPACING="2" WIDTH="100%">
<TR>
<TD> table data <TD>Column 1</TD> Column 1 Column 2
<TD>Column 2</TD>
</TR>
</TABLE>
<DIV align="center"><TABLE>
<TR>
<TH>Column 1</TH>
<TH>Column 2</TH>
<TH>Column 3</TH>
</TR>
<TR>
<TD>Row 2</TD>
<TD>Row 2</TD> Column Column Column
<TD>Row 2</TD> 1 2 3
</TR> Row 2 Row 2 Row 2
table
<TH> <TR>
header Row 3 Row 3 Row 3
<TD>Row 3</TD>
<TD>Row 3</TD> Row 4 Row 4 Row 4
<TD>Row 3</TD>
</TR>
<TR>
<TD>Row 4</TD>
<TD>Row 4</TD>
<TD>Row 4</TD>
</TR>
</TABLE>
</DIV>
document Title of your webpage will be
<TITLE> <TITLE>Title of your webpage</TITLE>
title viewable in the title bar.
<TABLE BORDER="2" CELLPADDING="2"
CELLSPACING="2" WIDTH="100%">
<TR> Column 1 Column 2
<TR> table row <TD>Column 1</TD>
<TD>Column 2</TD>
</TR>
</TABLE>
<TT> teletype <TT>Example</TT> Example
<U> underline <U>Example</U> Example
Example 1:<BR>
unordered Example 1:
<UL> <BR>
list
<UL>
<LI>List item 1 List item 1
<LI>List item 2 List item 2
</UL>
<BR>
Example 2:<BR>
<UL type="disc"> Example 2:
<LI>List item 1
<LI>List item 2 List item 1
<UL type="circle"> List item 2
<LI>List item 3 o List item 3
<LI>List item 4 o List item 4
</UL>
</UL>
Tag Description
Tag Description
Note: The <form> element does not itself create a form but it is container to contain all required form
elements, such as <input>, <label>, etc.
Syntax:
1. <form>
2. //Form elements
3. </form>
ADVERTISEMENT
Example:
1. <body>
2. <form>
3. Enter your name <br>
4. <input type="text" name="username">
5. </form>
6. </body>
Output:
ADVERTISEMENT
1. <form>
2. First Name: <input type="text" name="firstname"/> <br/>
3. Last Name: <input type="text" name="lastname"/> <br/>
4. </form>
Output:
Note: If you will omit 'name' attribute then the text filed input will not be submitted to server.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Form in HTML</title>
5. </head>
6. <body>
7. <form>
8. Enter your address:<br>
9. <textarea rows="2" cols="20"></textarea>
10. </form>
11. </body>
12. </html>
Output:
If you click on the label tag, it will focus on the text control. To do so, you need to have for
attribute in label tag that must be same as id attribute of input tag.
NOTE: It is good to use <label> tag with form, although it is optional but if you will use it, then it will
provide a focus when you tap or click on label tag. It is more worthy with touchscreens.
1. <form>
2. <label for="firstname">First Name: </label> <br/>
3. <input type="text" id="firstname" name="firstname"/> <br/>
4. <label for="lastname">Last Name: </label>
5. <input type="text" id="lastname" name="lastname"/> <br/>
6. </form>
Output:
1. <form>
2. <label for="password">Password: </label>
3. <input type="password" id="password" name="password"/> <br/>
4. </form>
Output:
1. <form>
2. <label for="email">Email: </label>
3. <input type="email" id="email" name="email"/> <br/>
4. </form>
Note: If we will not enter the correct email, it will display error like:
The radio button is used to select one option from multiple options. It is used for selection of
gender, quiz questions etc.
If you use one name for all the radio buttons, only one radio button can be selected at a time.
Using radio buttons for multiple options, you can only choose a single option at a time.
1. <form>
2. <label for="gender">Gender: </label>
3. <input type="radio" id="gender" name="gender" value="male"/>Male
4. <input type="radio" id="gender" name="gender" value="female"/>Female <br/>
5. </form>
Checkbox Control
The checkbox control is used to check multiple options from given checkboxes.
1. <form>
2. Hobby:<br>
3. <input type="checkbox" id="cricket" name="cricket" value="cricket"/>
4. <label for="cricket">Cricket</label> <br>
5. <input type="checkbox" id="football" name="football" value="football"/>
6. <label for="football">Football</label> <br>
7. <input type="checkbox" id="hockey" name="hockey" value="hockey"/>
8. <label for="hockey">Hockey</label>
9. </form>
Note: These are similar to radio button except it can choose multiple options at a time and radio button
can select one button at a time, and its display.
Output:
Syntax:
Example:
1. <form>
2. <label for="name">Enter name</label><br>
3. <input type="text" id="name" name="name"><br>
4. <label for="pass">Enter Password</label><br>
5. <input type="Password" id="pass" name="pass"><br>
6. <input type="submit" value="submit">
7. </form>
Output:
ADVERTISEMENT
Example:
1. <form>
2. <fieldset>
3. <legend>User Information:</legend>
4. <label for="name">Enter name</label><br>
5. <input type="text" id="name" name="name"><br>
6. <label for="pass">Enter Password</label><br>
7. <input type="Password" id="pass" name="pass"><br>
8. <input type="submit" value="submit">
9. </fieldset>
10. lt;/form>
Output:
HTML Form Example
Following is the example for a simple form of registration.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Form in HTML</title>
5. </head>
6. <body>
7. <h2>Registration form</h2>
8. <form>
9. <fieldset>
10. <legend>User personal information</legend>
11. <label>Enter your full name</label><br>
12. <input type="text" name="name"><br>
13. <label>Enter your email</label><br>
14. <input type="email" name="email"><br>
15. <label>Enter your password</label><br>
16. <input type="password" name="pass"><br>
17. <label>confirm your password</label><br>
18. <input type="password" name="pass"><br>
19. <br><label>Enter your gender</label><br>
20. <input type="radio" id="gender" name="gender" value="male"/>Male <br>
21. <input type="radio" id="gender" name="gender" value="female"/>Female <br/>
22. <input type="radio" id="gender" name="gender" value="others"/>others <br/>
23. <br>Enter your Address:<br>
24. <textarea></textarea><br>
25. <input type="submit" value="sign-up">
26. </fieldset>
27. </form>
28. </body>
29. </html>
Test it Now
Output:
1. <form action="#">
2. <table>
3. <tr>
4. <td class="tdLabel"><label for="register_name" class="label">Enter name:</label></td>
5. <td><input type="text" name="name" value="" id="register_name" style="width:160px"/><
/td>
6. </tr>
7. <tr>
8. <td class="tdLabel"><label for="register_password" class="label">Enter password:</label>
</td>
9. <td><input type="password" name="password" id="register_password" style="width:160px
"/></td>
10. </tr>
11. <tr>
12. <td class="tdLabel"><label for="register_email" class="label">Enter Email:</label></td>
13. <td
14. ><input type="email" name="email" value="" id="register_email" style="width:160px"/></td>
15. </tr>
16. <tr>
17. <td class="tdLabel"><label for="register_gender" class="label">Enter Gender:</label></td
>
18. <td>
19. <input type="radio" name="gender" id="register_gendermale" value="male"/>
20. <label for="register_gendermale">male</label>
21. <input type="radio" name="gender" id="register_genderfemale" value="female"/>
22. <label for="register_genderfemale">female</label>
23. </td>
24. </tr>
25. <tr>
26. <td class="tdLabel"><label for="register_country" class="label">Select Country:</label></t
d>
27. <td><select name="country" id="register_country" style="width:160px">
28. <option value="india">india</option>
29. <option value="pakistan">pakistan</option>
30. <option value="africa">africa</option>
31. <option value="china">china</option>
32. <option value="other">other</option>
33. </select>
34. </td>
35. </tr>
36. <tr>
37. <td colspan="2"><div align="right"><input type="submit" id="register_0" value="register"
/>
38. </div></td>
39. </tr>
40. </table>
41. </form>
1. <table border="1">
2. <tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>
3. <tr><td>Sonoo</td><td>Jaiswal</td><td>60</td></tr>
4. <tr><td>James</td><td>William</td><td>80</td></tr>
5. <tr><td>Swati</td><td>Sironi</td><td>82</td></tr>
6. <tr><td>Chetna</td><td>Singh</td><td>72</td></tr>
7. </table>
Parts of a Table
The rest of this document contains a summary of the most common table tags and attributes.
The table itself must be defined using the table tags <table> and </table>. All of the items and
attributes contained within that table must appear between these two tags.
A title or caption may be defined for the table by placing the <CAPTION>...</CAPTION> tag
immediately after the <table> tag.
The next layer down is to define the rows. A table's row is defined with the tags <tr> and </tr>. All
of the items and attributes contained within that row of the table must appear between these two tags.
The lowest level of the table is the table data. Each item of the table is defined between the tags
<td> and </td>. You may place just about any page component within the table data tags, even
another table.
<table border="1">
<caption>Table Caption</caption>
<tr>
<td>
Row 1, col 1 item
</td>
<td>
Row 1, col 2 item
</td>
<td>
Row 1, col 3 item
</td>
</tr>
<tr>
<td>
Row 2, col 1 item
</td>
<td>
Row 2, col 2 item
</td>
<td>
Row 2, col 3 item
</td>
</tr>
</table>
Table Caption
Note that I had to add the "border=1" attribute to define the cells of the table with lines.
Table Attributes
The following is a brief list of the attributes definable for a table. All of these attributes must be
contained between the keyword "table" and the greater than bracket of the <table> tag.
Borders
The border around the outside of the table can be edited by width and color. To change the width of
the table's border, use the attribute border="p" where p = number of pixels wide the border should
be. Note that using this attribute also adds borders to the cells.
The table below has a border of 10 pixels. This is done with the table tag <table border="10">.
Item 1 Item 2
Item 3 Item 4
Item 1 Item 2
Item 3 Item 4
Item 1 Item 2
Item 3 Item 4
To change the background color, use the attribute bgcolor="color". The table below has its
background color set to #00ff00 with a table tag of <table bgcolor="#00ff00">.
Item 1 Item 2
Item 3 Item 4
To set a tiled background for a table, use the background="URL", where filename is the name of
the tiled graphic to be used. For example, in the same directory where these notes are found is a
graphics file [Link]. The table below uses it as a background by using the table tag <table
background="[Link]">
Item 1 Item 2
Item 3 Item 4
Cell Spacing
The spacing between the cells can be increased with the cellspacing="p" attribute where p equals
the number of pixels to put between cells. The example below obtains a cell spacing of 10 pixels with
the table tag <table cellspacing="10">
Item 1 Item 2
Item 3 Item 4
Cell Padding
The spacing around an item within each cell can be increased with the cellpadding="p" attribute
where p equals the number of pixels to put between the item and the end of the cell. The example
below obtains a cell padding of 10 pixels with the table tag <table cellpadding="10">.
Item 1 Item 2
Item 3 Item 4
Table Alignment
You can also specify how the table is placed horizontally within the browser's window
Item 1 Item 2
using the align attribute. Its format is align="alignment" where alignment
equals left, center, or right. If you set the alignment to left or right, text flows around
the table as it does with the table to the right of this paragraph. Center, however, Item 3 Item 4
does not allow text to flow around it resulting in a simple centered table as shown
below.
Item 1 Item 2
Item 3 Item 4
Table Width
Just like horizontal rules, a table's width can be defined in terms of a percentage of the overall
browser window width or as a specific number of pixels. The first table uses WIDTH="50%" to define
its width as 50% of the width of the window. (The resulting table will depend on the width of your
browser window.)
Item 1 Item 2
Item 3 Item 4
The next table is defined as 50 pixels wide using the attribute WIDTH="50".
Item Item
1 2
Item Item
3 4
The table data uses the next three attributes in the same way that the table tag uses them.
To change the background color of a single cell, use the attribute bgcolor="color" inside
the <td> tag.
To add a tiled background image to a single cell, use the
attribute background="URL" inside the <td> tag.
To set the width of a single cell, use the attribute width="w" where w is either a
percentage of the table's width (e.g., "25%") or a fixed number of pixels (e.g., "25").
The cell, however, adds a few additional attributes. First, it allows the user to define the verticle and
horizontal alignment of an item within a cell. The diagram below shows the different attributes for
horizontal and vertical alignment within a cell.
Lastly, you may force a cell of a table to span more than one column or row using the attribute
COLSPAN="n" or ROWSPAN="n" where n=the number of columns or rows to span.
Embedding Tables
As stated earlier, just about any component of a web page may be inserted into a table as table data.
Below is an example of inserting a table within a table.
Each of
these are Each of these
single are single table
table items.
items.
7 8 9
You embed a table just by placing another table within the <td> and </td> tags.
Example
table, th, td {
border: 1px solid black;
}
Try it Yourself »
Collapsed Table Borders
To avoid having double borders like in the example above, set the CSS border-
collapse property to collapse.
Example
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
Try it Yourself »
Example
table, th, td {
border: 1px solid white;
border-collapse: collapse;
}
th, td {
background-color: #96D4D4;
}
Try it Yourself »
Example
table, th, td {
border: 1px solid black;
border-radius: 10px;
}
Try it Yourself »
Skip the border around the table by leaving out table from the css selector:
Example
th, td {
border: 1px solid black;
border-radius: 10px;
}
Try it Yourself »
dotted
dashed
solid
double
groove
ridge
inset
outset
none
hidden
Example
th, td {
border-style: dotted;
}
Try it Yourself »
Border Color
With the border-color property, you can set the color of the border.
Example
th, td {
border-color: #96D4D4;
}
Try it Yourself »