HTML
HTML
• 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
What is HTML? • The text between <p> and </p> is displayed as a paragraph
HTML is a language for describing web pages.
Editing HTML
• HTML stands for Hyper Text Markup Language
HTML can be written and edited using many different editors like Dreamweaver and
• HTML is not a programming language, it is a markup language
Visual Studio.
• A markup language is a set of markup tags
• HTML uses markup tags to describe web pages
However, in this tutorial we use a plain text editor (like Notepad) to edit HTML. We
believe using a plain text editor is the best way to learn HTML.
HTML Tags
.HTM or .HTML File Extension?
HTML markup tags are usually called HTML tags
When you save an HTML file, you can use either the .htm or the .html file extension.
• HTML tags are keywords surrounded by angle brackets like <html>
There is no difference; it is entirely up to you.
• HTML tags normally come in pairs like <b> and </b>
• The first tag in a pair is the start tag, the second tag is the end tag
• Start and end tags are also called opening tags and closing tags HTML Headings
<html>
<body>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
HTML Links
HTML Elements
HTML links are defined with the <a> tag.
An HTML element is everything from the start tag to the end tag:
Example
Start tag * Element content End tag *
<a href="[Link] is a link</a> <p> This is a paragraph </p>
Note: The link address is specified in the href attribute. <a href="[Link]" > This is a link </a>
<br />
(You will learn about attributes in a later chapter of this tutorial).
* The start tag is often called the opening tag. The end tag is often called the closing tag.
HTML Images
HTML Element Syntax
HTML images are defined with the <img> tag.
• An HTML element starts with a start tag / opening tag
Example • An HTML element ends with an end tag / closing tag
• The element content is everything between the start and the end tag
<img src="[Link]" width="104" height="142" /> • Some HTML elements have empty content
• Empty elements are closed in the start tag
Note: The name and the size of the image are provided as attributes. • Most HTML elements can have attributes
Tip: You will learn about attributes in the next chapter of this tutorial.
Most HTML elements can be nested (can contain other HTML elements).
<html>
<body>
<p>This is my first paragraph.</p>
</body>
</html>
The example above contains 3 HTML elements. The example above works in most browsers, because the closing tag is considered
optional.
Never rely on this. Many HTML elements will produce unexpected results and/or errors
HTML Example Explained if you forget the end tag .
The <p> element defines a paragraph in the HTML document. HTML elements with no content are called empty elements.
The element has a start tag <p> and an end tag </p>.
The element content is: This is my first paragraph. <br> is an empty element without a closing tag (the <br> tag defines a line break).
The <body> element: Tip: In XHTML, all elements must be closed. Adding a slash inside the start tag, like <br
/>, is the proper way of closing empty elements in XHTML (and XML).
<body>
<p>This is my first paragraph.</p>
</body>
HTML Tip: Use Lowercase Tags
The <body> element defines the body of the HTML document.
The element has a start tag <body> and an end tag </body>. HTML tags are not case sensitive: <P> means the same as <p>. Many web sites use
The element content is another HTML element (a p element). uppercase HTML tags.
</html>
Example
Don't Forget the End Tag
<a href="[Link] [Link]">This is a link</a>
Some HTML elements might display correctly even if you forget the end tag:
<p>This is a paragraph
<p>This is a paragraph
Always Quote Attribute Values
Tip: In some rare situations, when the attribute value itself contains quotes, it is
necessary to use single quotes: name='John "ShotGun" Nelson'
Headings Are Important
Use HTML headings for headings only. Don't use headings to make text BIG or bold.
HTML Tip: Use Lowercase Attributes
Search engines use your headings to index the structure and content of your web pages.
Attribute names and attribute values are case-insensitive.
Since users may skim your pages by its headings, it is important to use headings to show
Newer versions of (X)HTML will demand lowercase attributes. 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 Attributes Reference
A complete list of legal attributes for each HTML element is listed in our:
HTML Lines
Below is a list of some attributes that are standard for most HTML elements:
The <hr /> tag creates a horizontal line in an HTML page.
Attribute Value Description
class classname Specifies a classname for an element The hr element can be used to separate content:
id id Specifies a unique id for an element
Example
style style_definition Specifies an inline style for an element
Specifies extra information about an element <p>This is a paragraph</p>
title tooltip_text
(displayed as a tool tip) <hr />
<p>This is a paragraph</p>
For more information about standard attributes: <hr />
<p>This is a paragraph</p>
HTML Headings
<h1> defines the most important heading. <h6> defines the least important heading.
Example Most browsers will display HTML correctly even if you forget the end tag:
<p>This is a paragraph
<p>This is another paragraph
Note: There is an exclamation point after the opening bracket, but not before the closing
bracket.
The example above will work in most browsers, but don't rely on it. Forgetting the end
tag can produce unexpected results or errors.
HTML Tip - How to View HTML Source
Note: Future version of HTML will not allow you to skip end tags.
Have you ever seen a Web page and wondered "Hey! How did they do that?"
To find out, right-click in the page and select "View Source" (IE) or "View Page Source"
(Firefox), or similar for other browsers. This will open a window containing the HTML HTML Line Breaks
code of the page.
Use the <br /> tag if you want a line break (a new line) without starting a new paragraph:
HTML Tag Reference
Example
You will learn more about HTML tags and attributes in the next chapters of this tutorial.
<p>This is<br />a para<br />graph with line breaks</p>
Tag Description
<html> Defines an HTML document The <br /> element is an empty HTML element. It has no end tag.
<body> Defines the document's body <br> or <br />
<h1> to <h6> Defines HTML headings
<hr /> Defines a horizontal line In XHTML, XML, elements with no end tag (closing tag) are not allowed.
<!--> Defines a comment
Even if <br> works in all browsers, writing <br /> instead works better in XHTML and
XML applications.
HTML Paragraphs
<p>This is a paragraph</p> You cannot be sure how HTML will be displayed. Large or small screens, and resized
<p>This is another paragraph</p> windows will create different results.
With HTML, you cannot change the output by adding extra spaces or extra lines in your
HTML code.
Note: Browsers automatically add an empty line before and after a paragraph.
The browser will remove extra spaces and extra lines when the page is displayed. Any
number of lines count as one line, and any number of spaces count as one space. HTML Text Formatting
HTML uses tags like <b> and <i> for formatting output, like bold or italic text.
These HTML tags are called formatting tags (look at the bottom of this page for a
complete reference).
<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!
Tag Description
<b> Defines bold text
<big> Defines big text
<em> Defines emphasized text
<i> Defines italic text
<small> Defines small text
<strong> Defines strong text
<sub> Defines subscripted text
<sup> Defines superscripted text
<ins> Defines inserted text
<del> Defines deleted text
HTML "Computer Output" Tags HTML Styles - CSS
The example below shows how the HTML could look by using the <font> tag:
Using the HTML Style Attribute
Example
It is time consuming and not very practical to style HTML elements using the style
<p> attribute.
<font size="5" face="arial" color="red">
This paragraph is in Arial, size 5, and in red text color. The preferred way to add CSS to HTML, is to put CSS syntax in separate CSS files.
</font>
</p> However, in this HTML tutorial we will introduce you to CSS using the style attribute.
This is done to simplify the examples. It also makes it easier for you to edit the code and
<p> try it yourself.
<font size="3" face="verdana" color="blue">
This paragraph is in Verdana, size 3, and in blue text color.
</font>
</p>
HTML Style Example - Background Color HTML Style Example - Text Alignment
The background-color property defines the background color for an element: The text-align property specifies the horizontal alignment of text in an element:
Example Example
<html> <html>
</html> </html>
The background-color property makes the "old" bgcolor attribute obsolete. The text-align property makes the old <center> tag obsolete.
Links are found in nearly all Web pages. Links allow users to click their way from page <a href="[Link] [Link]/" target="_blank">Visit Xitec Solutions!</a>
to page.
When you move the cursor over a link in a Web page, the arrow will turn into a little The name attribute is used to create a bookmark inside an HTML document.
hand.
Note: The upcoming HTML5 standard suggest using the id attribute instead of the name
Links are specified in HTML using the <a> tag. attribute for specifying the name of an anchor. Using the id attribute actually works also
for HTML4 in all modern browsers.
The <a> tag can be used in two ways:
Bookmarks are not displayed in any special way. They are invisible to the reader.
1. To create a link to another document, by using the href attribute
2. To create a bookmark inside a document, by using the name attribute Example
The HTML code for a link is simple. It looks like this: <a name="tips">Useful Tips Section</a>
<a href="url">Link text</a> Create a link to the "Useful Tips Section" inside the same document:
The href attribute specifies the destination of a link. <a href="#tips">Visit the Useful Tips Section</a>
Example Or, create a link to the "Useful Tips Section" from another page:
<a href="[Link] Xitec Solutions</a> which will display <a href="[Link] [Link]/html_links.htm#tips">
like this: Visit Xitec Solutions Visit the Useful Tips Section</a>
Clicking on this hyperlink will send the user to Xitec Solutions homepage.
Tip: The "Link text" doesn't have to be text. It can be an image or any other HTML HTML Link Tags
element.
Tag Description
<a> Defines an anchor
HTML Links - The target Attribute
The example below will open the linked document in a new browser window or a new
tab:
HTML Images
HTML Images - Set Height and Width of an Image
Example
The height and width attributes are used to specify the height and width of an image.
Tip: It is a good practice to specify both the height and width attributes for an image. If
these attributes are set, the space required for the image is reserved when the page is
loaded. However, without these attributes, the browser does not know the size of the
image. The effect will be that the page layout will change during loading (while the
images load).
In HTML, images are defined with the <img> tag. Tag Description
<img /> Defines an image
The <img> tag is empty, which means that it contains attributes only, and has no closing <map> Defines an image-map
tag. <area /> Defines a clickable area inside an image-map
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 required alt attribute specifies an alternate text for an image, if the image cannot be
displayed.
The alt attribute provides alternative information for an image if a 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).
<td>Row 1, cell 1</td>
HTML Tables <td>Row 1, cell 2</td>
</tr>
Apples 44% </table>
Bananas 23%
Oranges 13%
Other 10% HTML Table Headers
Notes:
HTML Tables and the Border Attribute
Tables without borders
If you do not specify a border attribute, the table will be displayed without borders. How to create tables without borders.
Sometimes this can be useful, but most of the time, we want the borders to show.
Table headers
To display a table with borders, specify the border attribute: How to create table headers.
<table border="1"> Table with a caption
<tr> How to add a caption to a table.
Table cells that span more than one row/column
How to define table cells that span more than one row or one column. An ordered list: An unordered list:
Tag Description An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.
<table> Defines a table
<th> Defines a table header The list items are marked with bullets (typically small black circles).
<tr> Defines a table row
<ul>
<td> Defines a table cell <li>Coffee</li>
<caption> Defines a table caption <li>Milk</li>
<colgroup> Defines a group of columns in a table, for formatting </ul>
<col /> Defines attribute values for one or more columns in a table
How the HTML code above looks in a browser:
<thead> Groups the header content in a table
<tbody> Groups the body content in a table • Coffee
<tfoot> Groups the footer content in a table • Milk
An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.
<ol>
<li>Coffee</li>
<li>Milk</li>
</ol>
HTML Lists How the HTML code above looks in a browser:
The most common HTML lists are ordered and unordered lists: 1. Coffee
2. Milk HTML List Tags
Tag Description
<ol> Defines an ordered list
HTML Definition Lists
<ul> Defines an unordered list
A definition list is a list of items, with a description of each item. <li> Defines a list item
<dl> Defines a definition list
The <dl> tag defines a definition list. <dt> Defines an item in a definition list
<dd> Defines a description of an item in a definition list
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> HTML Forms and Input
<dd>- black hot drink</dd>
<dt>Milk</dt> HTML Forms are used to select different kinds of user input.
<dd>- white cold drink</dd>
</dl> HTML forms are used to pass data to a server.
How the HTML code above looks in a browser: A form can contain input elements like text fields, checkboxes, radio-buttons, submit
buttons and more. A form can also contain select lists, textarea, fieldset, legend, and label
Coffee elements.
- black hot drink
Milk The <form> tag is used to create an HTML form:
- white cold drink
<form>
Nested list 2 An input element can vary in many ways, depending on the type attribute. An input
Demonstrates a more complicated nested list. element can be of type text field, checkbox, password, radio button, submit button, and
more.
Definition list
Demonstrates a definition list. The most used input types are described below.
Text Fields
<input type="text" /> defines a one-line input field that a user can enter text into: Checkboxes
<form> <input type="checkbox" /> defines a checkbox. Checkboxes let a user select ONE or
First name: <input type="text" name="firstname" /><br /> MORE options of a limited number of choices.
Last name: <input type="text" name="lastname" />
</form> <form>
<input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br />
How the HTML code above looks in a browser: <input type="checkbox" name="vehicle" value="Car" /> I have a car
</form>
First name:
How the HTML code above looks in a browser:
Last name:
I have a bike
Note: The form itself is not visible. Also note that the default width of a text field is 20
characters. I have a car
Password Field
Submit Button
<input type="password" /> defines a password field:
<input type="submit" /> defines a submit button.
<form>
Password: <input type="password" name="pwd" /> A submit button is used to send form data to a server. The data is sent to the page
</form> specified in the form's action attribute. The file defined in the action attribute usually
does something with the received input:
How the HTML code above looks in a browser:
<form name="input" action="html_form_action.asp" method="get">
Username: <input type="text" name="user" />
Password:
<input type="submit" value="Submit" />
</form>
Note: The characters in a password field are masked (shown as asterisks or circles).
How the HTML code above looks in a browser:
Radio Buttons
Submit
<input type="radio" /> defines a radio button. Radio buttons let a user select ONLY ONE Username:
of a limited number of choices:
If you type some characters in the text field above, and click the "Submit" button, the
<form> browser will send your input to a page called "html_form_action.asp". The page will
<input type="radio" name="sex" value="male" /> Male<br /> show you the received input.
<input type="radio" name="sex" value="female" /> Female
</form> HTML Form Tags
How the HTML code above looks in a browser:
Tag Description
<form> Defines an HTML form for user input
Male <input /> Defines an input control
Female <textarea> Defines a multi-line text input control
<label> Defines a label for an input element <frameset cols="25%,75%">
<fieldset> Defines a border around elements in a form <frame src="frame_a.htm" />
<frame src="frame_b.htm" />
<legend> Defines a caption for a fieldset element
</frameset>
<select> Defines a select list (drop-down list)
<optgroup> Defines a group of related options in a select list Note: The frameset column size can also be set in pixels (cols="200,500"), and one of the
<option> Defines an option in a select list columns can be set to use the remaining space, with an asterisk (cols="25%,*").
<button> Defines a push button
Basic Notes - Useful Tips
Tip: If a frame has visible borders, the user can resize it by dragging the border. To
prevent a user from doing this, you can add noresize="noresize" to the <frame> tag.
HTML Frames Note: Add the <noframes> tag for browsers that do not support frames.
With frames, you can display more than one HTML document in the same browser
Important: You cannot use the <body></body> tags together with the
window. Each HTML document is called a frame, and each frame is independent of the
<frameset></frameset> tags! However, if you add a <noframes> tag containing some text
others.
for browsers that do not support frames, you will have to enclose the text in
<body></body> tags! See how it is done in the first example below.
The disadvantages of using frames are:
The frameset element states HOW MANY columns or rows there will be in the frameset,
and HOW MUCH percentage/pixels of space will occupy each of them.
The <frame> tag defines one particular window (frame) within a frameset.
The first column is set to 25% of the width of the browser window. The second column is
set to 75% of the width of the browser window. The document "frame_a.htm" is put into
the first column, and the document "frame_b.htm" is put into the second column:
Ivory #FFFFF0 Shades Mix
HTML Iframes
White #FFFFFF Shades Mix
An iframe is used to display a web page within a web page.
<iframe src="URL"></iframe>
The URL points to the location of the separate page. HTML 4.01 Quick List
Iframe - Set Height and Width HTML Basic Document
The height and width attributes are used to specify the height and width of the iframe. <html>
<head>
The attribute values are specified in pixels by default, but they can also be in percent (like <title>Title of document goes here</title>
"80%"). </head>
Example <body>
Visible text goes here...
<iframe src="demo_iframe.htm" width="200" height="200"></iframe> </body>
</html>
The frameborder attribute specifies whether or not to display a border around the iframe. <h1>Largest Heading</h1>
Set the attribute value to "0" to remove the border: <h2> . . . </h2>
<h3> . . . </h3>
Example <h4> . . . </h4>
<h5> . . . </h5>
<iframe src="demo_iframe.htm" frameborder="0"></iframe>
<h6>Smallest Heading</h6>
Text Elements
Use iframe as a Target for a Link
<p>This is a paragraph</p>
An iframe can be used as the target frame for a link. <br /> (line break)
<hr /> (horizontal rule)
The target attribute of a link must refer to the name attribute of the iframe: <pre>This text is preformatted</pre>
</form>
Tables Entities
Symbol Description Entity Name Number Code « angle quotation mark left « «
Ý capital y, acute accent Ý Ý Other Entities Supported by HTML Browsers
Þ capital THORN, Icelandic Þ Þ
Result Description Entity Name Number Code
ß small sharp s, German ß ß
Œ capital ligature OE Œ Œ
à small a, grave accent à à
œ small ligature oe œ œ
á small a, acute accent á á
â small a, circumflex accent â â Š capital S with caron Š Š
š small S with caron š š
“ left double quotation mark “ “ Lists: ordered list (ol) unordered list (ul)
<ol>
” right double quotation mark ” ” <li>Apple</li>
<li>Mango</li>
„ double low-9 quotation mark „ „
<li>Banana</li>
† dagger † † </ol>
Select :
<label for="cars">Choose a car:</label>
</textarea>