HTML NOTES
HTML NOTES
What is HTML?
HTML is a language for describing web pages.
HTML Tags
HTML markup tags are usually called HTML tags
The purpose of a web browser (like Internet Explorer or Firefox) is to read HTML documents and
display them as web pages. The browser does not display the HTML tags, but uses the tags to
interpret the content of the page:
<html>
<body>
</body>
</html>
Example Explained
∙ The text between <html> and </html> describes the web page
∙ The text between <body> and </body> is the visible page content
∙ The text between <h1> and </h1> is displayed as a heading
∙ The text between <p> and </p> is displayed as a paragraph
HTML Headings
∙ HTML headings are defined with the <h1> to <h6> tags.
Example
<h1>This is a heading</h1>
<h2>This is a heading</h2>
<h3>This is a heading</h3>
HTML Paragraphs
∙ HTML paragraphs are defined with the <p> tag.
Example
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<html>
<body>
<p>This is my first paragraph.</p>
</body>
</html>
The example above contains 3 HTML elements.
<body>
<p>This is my first paragraph.</p>
</body>
The <body> element defines the body of the HTML document.
The element has a start tag <body> and an end tag </body>.
The element content is another HTML element (a p element).
<html>
<body>
<p>This is my first paragraph.</p>
</body>
</html>
<p>This is a paragraph
<p>This is a paragraph
The example above will work in most browsers, but don't rely on it. Forgetting the end tag can
produce unexpected results or errors.
Note: Future version of HTML will not allow you to skip end tags.
Empty HTML Elements
HTML elements with no content are called empty elements. Empty elements can be closed in the
start tag.
<br> is an empty element without a closing tag (the <br> tag defines a line
break). In XHTML, XML, and future versions of HTML, all elements must be closed.
Adding a slash to the start tag, like <br />, is the proper way of closing empty elements, accepted
by HTML, XHTML and XML.
Even if <br> works in all browsers, writing <br /> instead is more future proof.
HTML Attributes
Attributes provide additional information about HTML elements.
HTML Attributes
∙ HTML elements can have attributes
∙ Attributes provide additional information about an element
∙ Attributes are always specified in the start tag
∙ Attributes come in name/value pairs like: name="value"
Attribute Example
HTML links are defined with the <a> tag. The link address is specified in the href attribute:
Example
Double style quotes are the most common, but single style quotes are also allowed.
Below is a list of some attributes that are standard for most HTML elements:
Attribute Value Description
HTML Headings
Headings are defined with the <h1> to <h6> tags.
<h1> defines the largest heading. <h6> defines the smallest heading.
Example
<h1>This is a heading</h1>
<h2>This is a heading</h2>
<h3>This is a heading</h3>
Try it yourself »
Note: Browsers automatically add an empty line before and after a heading.
Headings Are Important
Use HTML headings for headings only. Don't use headings to make text BIG or bold.
Search engines use your headings to index the structure and content of your web
pages.
Since users may skim your pages by its headings, it is important to use headings to show the
document structure.
H1 headings should be used as main headings, followed by H2 headings, then the less important
H3 headings, and so on.
HTML Lines
The <hr /> tag creates a horizontal line in an HTML page.
Example
<p>This is a paragraph</p>
<hr />
<p>This is a paragraph</p>
<hr />
<p>This is a paragraph</p>
Try it yourself »
HTML Comments
Comments can be inserted into the HTML code to make it more readable and understandable.
Comments are ignored by the browser and are not displayed.
Example
Note: There is an exclamation point after the opening bracket, but not before the closing bracket.
Try this
<html>
<body>
</body>
</html>
<html>
<body>
<p>The hr tag defines a horizontal rule:</p>
<hr />
<p>This is a paragraph</p>
<hr />
<p>This is a paragraph</p>
<hr />
<p>This is a paragraph</p>
</body>
</html>
HTML Paragraphs
HTML Paragraphs
Paragraphs are defined with the <p> tag.
Example
<p>This is a paragraph</p>
<p>This is another paragraph</p>
Note: Browsers automatically add an empty line before and after a paragraph.
Example
<p>This is a paragraph
<p>This is another paragraph
The example above will work in most browsers, but don't rely on it. Forgetting the end tag can
produce unexpected results or errors.
Note: Future version of HTML will not allow you to skip end tags.
The <br /> element is an empty HTML element. It has no end tag.
Even if <br> works in all browsers, writing <br /> instead is more future proof.
superscript
This is subscript and
These HTML tags are called formatting tags (look at the bottom of this page for a complete
reference).
Often <strong> renders as <b>, and <em> renders as <i>.
<strong> or <em> means that you want the text to be rendered in a way that the
user understands as "important". Today, all major browsers render strong as bold
and em as italics. However, if a browser one day wants to make a text highlighted
with the strong feature, it might be cursive for example and not bold!
HTML Styles
Styles was introduced with HTML 4, as the new and preferred way to style HTML elements. With
HTML styles, styles can be added to HTML elements directly by using the style attribute, or
indirectly in separate style sheets (CSS files).
Example
<html>
<body style="background-color:yellow">
<h2 style="background-color:red">This is a heading</h2>
<p style="background-color:green">This is a paragraph.</p>
</body>
</html>
<html>
<body>
<h1 style="font-family:verdana">water</h1>
<p style="font-size:30px;"> The two elements which make up water are Hydrogen
and Oxygen. </p>
<h2 style="color:blue"> boiling point of water </h2>
</body>
</html>
Example
<html>
<body>
<h1 style="text-align:center">This is a heading</h1>
<p>The heading above is aligned to the center of this page.</p>
</body>
</html>
HTML Tables
HTML Tables
Apples 44%
Bananas 23%
Oranges 13%
Other 10%
<html>
<body>
<p>
Each table starts with a table tag.
Each table row starts with a tr tag.
Each table data starts with a td tag.
</p>
<h4>One column:</h4>
<table border="1">
<tr>
<td>100</td>
</tr>
</table>
HTML Tables
Tables are defined with the <table> tag.
A table is divided into rows (with the <tr> tag), and each row is divided into data cells (with the
<td> tag). td stands for "table data," and holds the content of a data cell. A <td> tag can contain
text, links, images, lists, forms, other tables, etc.
Table Example
<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
<table border="1">
<tr>
<td>Row 1, cell 1</td>
<td>Row 1, cell 2</td>
</tr>
</table>
<table border="1">
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
Header 1 Header 2
row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2
More Examples
<html>
<body>
<table border="1">
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$50</td>
</tr>
</table>
</body>
</html>
<col /> Defines attribute values for one or more columns in a table
HTML Lists
The most common HTML lists are ordered and unordered lists:
HTML Lists
An unordered list:
An ordered list:
∙ List item
1. The first list item
∙ List item
2. The second list item
3. The third list item
∙ List item
Try-It-Yourself Examples
How to create an unordered list in an HTML document.
<html>
<body>
<h4>An Unordered List:</h4>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html
<html>
<body>
<h4>An Ordered List:</h4>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
The list items are marked with bullets (typically small black circles).
<ul>
<li>Coffee</li>
<li>Milk</li>
</ul>
∙ Coffee
∙ Milk
<ol>
<li>Coffee</li>
<li>Milk</li>
</ol>
The <dl> tag is used in conjunction with <dt> (defines the item in the list) and <dd> (describes
the item in the list):
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
Coffee
- black hot drink
Milk
- white cold drink
More Examples
Demonstrates different types of ordered lists.
<html>
<body>
<h4>Numbered list:</h4>
<ol>
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
</ol>
<h4>Letters list:</h4>
<ol type="A">
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
</ol>
<h4>Lowercase letters list:</h4>
<ol type="a">
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
</ol>
</body>
</html>
Demonstrates different types of unordered
lists. <html>
<body>
</body>
</html>
<html>
<body>
<h4>A nested List:</h4>
<ul>
<li>Coffee</li>
<li>Tea
<ul>
<li>Black tea</li>
<li>Green tea</li>
</ul>
</li>
<li>Milk</li>
</ul>
</body>
</html>
HTML Images
Example
<html>
<body>
<p>
An image:
<img src="smiley.gif" alt="Smiley face" width="32" height="32" />
</p>
<p>
A moving image:
<img src="hackanm.gif" alt="Computer man" width="48" height="48" />
</p>
<p>
Note that the syntax of inserting a moving image is no different from a non-moving
image. </p>
</body>
</html>
The <img> tag is empty, which means that it contains attributes only, and has no closing tag.
To display an image on a page, you need to use the src attribute. Src stands for "source". The
value of the src attribute is the URL of the image you want to display.
The URL points to the location where the image is stored. An image named "boat.gif", located in
the "images" directory on "www.w3schools.com" has the URL:
http://www.w3schools.com/images/boat.gif.
The browser displays the image where the <img> tag occurs in the document. If you put an image
tag between two paragraphs, the browser shows the first paragraph, then the image, and then the
second paragraph.
HTML Links
Links are found in nearly all Web pages. Links allow users to click their way from
page to page.
Examples
<html>
<body>
<p>
<a href="default.asp">HTML Tutorial</a> This is a link to a page on this website.
</p>
<p>
<a href="http://www.google.com/">Google</a> This is a link to a website on the World Wide Web.
</p>
</body>
</html>
Example
Tip: The "Link text" doesn't have to be text. You can link from an image or any other HTML
element.
The example below will open the linked document in a new browser window:
Example
Bookmarks are not displayed in any special way. They are invisible to the reader.
Example
A named anchor inside an HTML document:
Create a link to the "Useful Tips Section" inside the same document:
Or, create a link to the "Useful Tips Section" from another page:
<a href="http://www.w3schools.com/html_links.htm#tips">
Visit the Useful Tips Section</a>