Basic HTML: Created By-: Satish Chaudhary For Sweet
Basic HTML: Created By-: Satish Chaudhary For Sweet
BASIC HTML
Created By-: Satish Chaudhary for Sweet
---------------------------------------------------------
Basic HTML
---------------------------------------------------------
1.HTML Tutorial
With HTML you can create your own Web site.
With our online HTML editor, you can edit the HTML, and click on a button to view the result.
Example
<html>
<body>
</body>
</html>
Try it yourself »
Click on the "Try it yourself" button to see how it works
HTML Examples
At the end of the HTML tutorial you will find more than 100 examples you can edit and test yourself.
HTML References
At W3Schools you will find complete references about tags, standard attributes, standard events,
colornames, entities, character-sets, URL encoding, language codes, HTTP messages, and more.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
2.HTML Introduction
Example
<html>
<body>
</body>
</html>
Try it yourself »
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
Editing HTML
HTML can be written and edited using many different editors like Dreamweaver and Visual Studio.
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.
If you want to create a test page on your own computer, just copy the 3 files below to your desktop.
(Right click on each link, and select "save target as" or "save link as")
mainpage.htm
page1.htm
page2.htm
After you have copied the files, you can double-click on the file called "mainpage.htm" and see your
first web site in action.
Note: If your test web contains HTML markup tags you have not learned, don't panic. You will learn all
about it in the next chapters.
Don't worry if the examples use tags you have not learned.
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>
Try it yourself »
HTML Paragraphs
HTML paragraphs are defined with the <p> tag.
Example
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
Try it yourself »
HTML Links
HTML links are defined with the <a> tag.
Example
Try it yourself »
HTML Images
HTML images are defined with the <img> tag.
Example
Try it yourself »
Note: The name and the size of the image are provided as attributes.
5.HTML Elements
* The start tag is often called the opening tag. The end tag is often called the closing tag.
Tip: You will learn about attributes in the next chapter of this tutorial.
<body>
<p>This is my first paragraph.</p>
</body>
</html>
<body>
<p>This is my first paragraph.</p>
</body>
<html>
<body>
<p>This is my first paragraph.</p>
</body>
</html>
<p>This is a paragraph
<p>This is a paragraph
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 if you forget
the end tag .
Empty HTML Elements
HTML elements with no content are called empty elements.
<br> is an empty element without a closing tag (the <br> tag defines a line break).
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).
W3Schools use lowercase tags because the World Wide Web Consortium
(W3C) recommendslowercase in HTML 4, and demands lowercase tags in XHTML.
6.HTML Attributes
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
Try it yourself »
Always Quote Attribute Values
Attribute values should always be enclosed in quotes.
Double style quotes are the most common, but single style quotes are also allowed.
Tip: In some rare situations, when the attribute value itself contains quotes, it is necessary to use
single quotes: name='John "ShotGun" Nelson'
However, the World Wide Web Consortium (W3C) recommends lowercase attributes/attribute values
in their HTML 4 recommendation.
Below is a list of some attributes that are standard for most HTML elements:
7.HTML Headings
Headings are important in HTML documents.
HTML Headings
Headings are defined with the <h1> to <h6> tags.
<h1> defines the most important heading. <h6> defines the least important 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 some empty space (a margin) before and after each heading.
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
Try it yourself »
Note: There is an exclamation point after the opening bracket, but not before the closing bracket.
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 code of the page.
Headings
How to display headings in an HTML document.
Hidden comments
How to insert comments in the HTML source code.
Horizontal lines
How to insert a horizontal line.
You will learn more about HTML tags and attributes in the next chapters of this tutorial.
Tag Description
<html> Defines an HTML document
<body> Defines the document's body
<h1> to <h6> Defines HTML headings
<hr /> Defines a horizontal line
<!--> Defines a comment
8.HTML Paragraphs
HTML Paragraphs
Paragraphs are defined with the <p> tag.
Example
<p>This is a paragraph</p>
<p>This is another paragraph</p>
Try it yourself »
Note: Browsers automatically add an empty line before and after a paragraph.
Example
<p>This is a paragraph
<p>This is another paragraph
Try it yourself »
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.
Example
Try it yourself »
The <br /> element is an empty HTML element. It has no end tag.
Even if <br> works in all browsers, writing <br /> instead works better in XHTML and XML
applications.
With HTML, you cannot change the output by adding extra spaces or extra lines in your HTML code.
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.
Try it yourself
HTML paragraphs
How HTML paragraphs are displayed in a browser.
Line breaks
The use of line breaks in an HTML document.
Poem problems
Some problems with HTML formatting.
More Examples
More paragraphs
The default behaviors of paragraphs.
Tag Description
<p> Defines a paragraph
<br /> Inserts a single line break
superscript
This is subscript and
Try it yourself »
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!
Text formatting
How to format text in an HTML document.
Preformatted text
How to control the line breaks and spaces with the pre tag.
Address
How to define contact information for the author/owner of an HTML document.
Text direction
How to change the text direction.
Quotations
How to handle long and short quotations.
10.HTML Fonts
The World Wide Web Consortium (W3C) has removed the <font> tag from its recommendations.
In HTML 4, style sheets (CSS) should be used to define the layout and display properties for many
HTML elements.
The example below shows how the HTML could look by using the <font> tag:
Example
<p>
<font size="5" face="arial" color="red">
This paragraph is in Arial, size 5, and in red text color.
</font>
</p>
<p>
<font size="3" face="verdana" color="blue">
This paragraph is in Verdana, size 3, and in blue text color.
</font>
</p>
Try it yourself »
The preferred way to add CSS to HTML, is to put CSS syntax in separate CSS files.
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 try it yourself.
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>
Try it yourself »
Example
<html>
<body>
<h1 style="font-family:verdana;">A heading</h1>
<p style="font-family:arial;color:red;font-size:20px;">A paragraph.</p>
</body>
</html>
Try it yourself »
The font-family, color, and font-size properties make the old <font> tag obsolete.
Example
<html>
<body>
<h1 style="text-align:center;">Center-aligned heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Try it yourself »
Tags Description
<center> Deprecated. Defines centered content
<font> and <basefont> Deprecated. Defines HTML fonts
<s> and <strike> Deprecated. Defines strikethrough text
<u> Deprecated. Defines underlined text
Attributes Description
align Deprecated. Defines the alignment of text
bgcolor Deprecated. Defines the background color
color Deprecated. Defines the text color
12.HTML Links
Links are found in nearly all Web pages. Links allow users to click their way from page
to page.
HTML links
How to create links in an HTML document.
When you move the cursor over a link in a Web page, the arrow will turn into a little hand.
Example
<a href="http://www.w3schools.com/">Visit W3Schools</a>
Tip: The "Link text" doesn't have to be text. It can be an image or any other HTML element.
The example below will open the linked document in a new browser window or a new tab:
Example
Try it yourself »
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>
Tip: Named anchors are often used to create "table of contents" at the beginning of a large document.
Each chapter within the document is given a named anchor, and links to each of these anchors are put
at the top of the document.
More Examples
An image as a link
How to use an image as a link.
13.HTML Images
Example
Try it yourself »
Insert images
How to insert images into an HTML document.
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.
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).
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).
Note: When a web page is loaded, it is the browser, at that moment, that actually gets the image
from a web server and inserts it into the page. Therefore, make sure that the images actually stay in
the same spot in relation to the web page, otherwise your visitors will get a broken link icon. The
broken link icon is shown if the browser cannot find the image.
More Examples
Aligning images
How to align an image within the text.
14.HTML Lists
The most common HTML lists are ordered and unordered lists:
HTML Lists
Try-It-Yourself Examples
Unordered list
How to create an unordered list in an HTML document.
Ordered list
How to create an ordered list in an HTML document.
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>
1. Coffee
2. Milk
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
Milk
Nested list
Demonstrates how you can nest lists.
Nested list 2
Demonstrates a more complicated nested list.
Definition list
Demonstrates a definition list.
HTML Forms
HTML forms are used to pass data to a server.
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 elements.
<form>
.
input elements
.
</form>
An input element can vary in many ways, depending on the type attribute. An input element can be
of type text field, checkbox, password, radio button, submit button, and more.
Text Fields
<input type="text" /> defines a one-line input field that a user can enter text into:
<form>
First name: <input type="text" name="firstname" /><br />
Last name: <input type="text" name="lastname" />
</form>
First name:
Last name:
Note: The form itself is not visible. Also note that the default width of a text field is 20 characters.
Password Field
<input type="password" /> defines a password field:
<form>
Password: <input type="password" name="pwd" />
</form>
Password:
Note: The characters in a password field are masked (shown as asterisks or circles).
Radio Buttons
<input type="radio" /> defines a radio button. Radio buttons let a user select ONLY ONE one of a
limited number of choices:
<form>
<input type="radio" name="sex" value="male" /> Male<br />
<input type="radio" name="sex" value="female" /> Female
</form>
Male
Female
Checkboxes
<input type="checkbox" /> defines a checkbox. Checkboxes let a user select ONE or MORE options
of a limited number of choices.
<form>
<input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br />
<input type="checkbox" name="vehicle" value="Car" /> I have a car
</form>
I have a bike
I have a car
Submit Button
<input type="submit" /> defines a submit button.
A submit button is used to send form data to a server. The data is sent to the page specified in the
form's action attribute. The file defined in the action attribute usually does something with the
received input:
Submit
Username:
If you type some characters in the text field above, and click the "Submit" button, the browser will
send your input to a page called "html_form_action.asp". The page will show you the received input.
Checkboxes
How to create checkboxes. A user can select or unselect a checkbox.
Simple drop-down list
How to create a simple drop-down list.
Textarea
How to create a multi-line text input control. In a text-area the user can write an unlimited number
of characters.
Create a button
How to create a button.
Form Examples
Fieldset around form-data
How to create a border around elements in a form.
With frames, several Web pages can be displayed in the same browser window.
Try-It-Yourself Examples
Vertical frameset
How to make a vertical frameset with three different documents.
Horizontal frameset
How to make a horizontal frameset with three different documents.
HTML Frames
With frames, you can display more than one HTML document in the same browser window. Each
HTML document is called a frame, and each frame is independent of the others.
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.
<frameset cols="25%,75%">
<frame src="frame_a.htm" />
<frame src="frame_b.htm" />
</frameset>
Note: The frameset column size can also be set in pixels (cols="200,500"), and one of the columns
can be set to use the remaining space, with an asterisk (cols="25%,*").
Note: Add the <noframes> tag for browsers that do not support frames.
Important: You cannot use the <body></body> tags together with the <frameset></frameset>
tags! However, if you add a <noframes> tag containing some text 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.
More Examples
Nested framesets
How to create a frameset with three documents, and how to mix them in rows and columns.
Navigation frame
How to make a navigation frame. The navigation frame contains a list of links with the second
frame as the target. The file called "tryhtml_contents.htm" contains three links. The source code of
the links:
<a href ="frame_a.htm" target ="showframe">Frame a</a><br>
<a href ="frame_b.htm" target ="showframe">Frame b</a><br>
<a href ="frame_c.htm" target ="showframe">Frame c</a>
The second frame will show the linked document.
17.HTML Iframes
<iframe src="URL"></iframe>
The attribute values are specified in pixels by default, but they can also be in percent (like "80%").
Example
Try it yourself »
Iframe - Remove the Border
The frameborder attribute specifies whether or not to display a border around the iframe.
Example
Try it yourself »
The target attribute of a link must refer to the name attribute of the iframe:
Example
Try it yourself »
18.HTML Colors
Color Values
HTML colors are defined using a hexadecimal notation (HEX) for the combination of Red, Green, and
Blue color values (RGB).
The lowest value that can be given to one of the light sources is 0 (in HEX: 00). The highest value is
255 (in HEX: FF).
HEX values are specified as 3 pairs of two-digit numbers, starting with a # sign.
Color Values
Try it yourself »
If you look at the color table below, you will see the result of varying the red light from 0 to 255, while
keeping the green and blue light at zero.
To see the full list of color mixes when RED varies from 0 to 255, click on one of the HEX or RGB
values below.
Shades of Gray
Gray colors are created by using an equal amount of power to all of the light sources.
To make it easier for you to select the correct shade, we have created a table of gray shades for you:
The 216 cross-browser color palette was created to ensure that all computers would display the colors
correctly when running a 256 color palette.
This is not important today, since most computers can display millions of different colors. Anyway,
here is the list:
Click on a color name (or a hex value) to view the color as the background-color along with different
text colors:
HTML Quick List from W3Schools. Print it, fold it, and put it in your pocket.
<body>
Visible text goes here...
</body>
</html>
Heading Elements
<h1>Largest Heading</h1>
<h2> . . . </h2>
<h3> . . . </h3>
<h4> . . . </h4>
<h5> . . . </h5>
<h6>Smallest Heading</h6>
Text Elements
<p>This is a paragraph</p>
<br /> (line break)
<hr /> (horizontal rule)
<pre>This text is preformatted</pre>
Logical Styles
<em>This text is emphasized</em>
<strong>This text is strong</strong>
<code>This is some computer code</code>
Physical Styles
<b>This text is bold</b>
<i>This text is italic</i>
Links
Ordinary link: <a href="http://www.example.com/">Link-text goes here</a>
Image-link: <a href="http://www.example.com/"><img src="URL" alt="Alternate Text" /></a>
Mailto link: <a href="mailto:[email protected]">Send e-mail</a>
A named anchor:
<a name="tips">Tips Section</a>
<a href="#tips">Jump to the Tips Section</a>
Unordered list
<ul>
<li>Item</li>
<li>Item</li>
</ul>
Ordered list
<ol>
<li>First item</li>
<li>Second item</li>
</ol>
Definition list
<dl>
<dt>First term</dt>
<dd>Definition</dd>
<dt>Next term</dt>
<dd>Definition</dd>
</dl>
Tables
<table border="1">
<tr>
<th>Tableheader</th>
<th>Tableheader</th>
</tr>
<tr>
<td>sometext</td>
<td>sometext</td>
</tr>
</table>
Iframe
<iframe src="demo_iframe.htm"></iframe>
Frames
<frameset cols="25%,75%">
<frame src="page1.htm" />
<frame src="page2.htm" />
</frameset>
Forms
<form action="http://www.example.com/test.asp" method="post/get">
<select>
<option>Apples</option>
<option selected="selected">Bananas</option>
<option>Cherries</option>
</select>
</form>
Entities
< is the same as <
> is the same as >
© is the same as ©
Other Elements
<!-- This is a comment -->
<blockquote>
Text quoted from a source.
</blockquote>
<address>
Written by W3Schools.com<br />
<a href="mailto:[email protected]">Email us</a><br />
Address: Box 564, Disneyland<br />
Phone: +12 34 56 78
</address>Source : http://www.w3schools.com/html/html_quick.asp
END