What Is HTML?
What Is HTML?
What Is HTML?
HTML Tags
HTML markup tags are usually called HTML tags
• HTML tags are keywords surrounded by angle brackets like <html>
• 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
</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 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
<a href="http://www.w3schools.com">This is a link</a>
Try it yourself »
Note: The link address is specified in the href attribute.
(You will learn about attributes in a later chapter of this tutorial).
HTML Images
HTML images are defined with the <img> tag.
Example
<img src="w3schools.jpg" width="104" height="142" />
Try it yourself »
Note: The name and the size of the image are provided as attributes.
HTML documents are defined by HTML elements.
HTML Elements
An HTML element is everything from the start tag to the end tag:
Start tag * Element content End tag *
<p> This is a paragraph </p>
<a href="default.htm" > This is a link </a>
<br />
* The start tag is often called the opening tag. The end tag is often called the closing tag.
<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>
</html>
The <html> element defines the whole HTML document.
The element has a start tag <html> and an end tag </html>.
The element content is another HTML element (the body element).
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
<a href="http://www.w3schools.com">This is a link</a>
Try it yourself »
Tip: In some rare situations, when the attribute value itself contains quotes, it is necessary to
use single quotes: name='John "ShotGun" Nelson'
The attributes listed below are standard, and are supported by all HTML and XHTML tags, with
a few exceptions.
Core Attributes
Not valid in base, head, html, meta, param, script, style, and title elements.
Attribute Value Description
class classname Specifies a classname for an element
id id Specifies a unique id for an element
style style_definition Specifies an inline style for an element
title text Specifies extra information about an element
Language Attributes
Not valid in base, br, frame, frameset, hr, iframe, param, and script elements.
Attribute Value Description
ltr
dir Specifies the text direction for the content in an element
rtl
Specifies a language code for the content in an element.
lang language_code
Language code reference
Specifies a language code for the content in an element, in
xml:lang language_code
XHTML documents. Language code reference
Keyboard Attributes
Attribute Value Description
accesskey character Specifies a keyboard shortcut to access an element
tabindex number Specifies the tab order of an element
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.
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.
Comments are written like this:
Example
<!-- This is a comment -->
Try it yourself »
Note: There is an exclamation point after the opening bracket, but not before the closing bracket.
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
<p>This is<br />a para<br />graph with line breaks</p>
Try it yourself »
The <br /> element is an empty HTML element. It has no end tag.
superscript
This is subscript and
Try it yourself »
<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.
"Computer output" tags
How different "computer output" tags will be displayed.
Address
How to define contact information for the author/owner of an HTML document.
Abbreviations and acronyms
How to handle abbreviations and acronyms.
Text direction
How to change the text direction.
Quotations
How to handle long and short quotations.
Deleted and inserted text
How to mark deleted and inserted text.
Attributes Description
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 »
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>
Try it yourself »
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.
(You can find more examples at the bottom of this page)
HTML Hyperlinks (Links)
A hyperlink (or link) is a word, group of words, or image that you can click on to jump to a new
document or a new section within the current document.
When you move the cursor over a link in a Web page, the arrow will turn into a little hand.
Links are specified in HTML using the <a> tag.
The <a> tag can be used in two ways:
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
<a href="http://www.w3schools.com/" target="_blank">Visit W3Schools!</a>
Try it yourself »
Create a link to the "Useful Tips Section" inside the same document:
<a href="#tips">Visit the Useful Tips Section</a>
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>
More Examples
An image as a link
How to use an image as a link.
Link to a location on the same page
How to link to a bookmark.
Break out of a frame
How to break out of a frame (if your site is locked in a frame).
Create a mailto link
How to link to a mail message (will only work if you have mail installed).
Create a mailto link 2
Another mailto link.
Example
Norwegian Mountain Trip
Try it yourself »
Insert images
How to insert images into an HTML document.
Insert images from different locations
How to insert an image from another folder or another server.
(You can find more examples at the bottom of this page).
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).
Aligning images
How to align an image within the text.
Let the image float
How to let an image float to the left or right of a paragraph.
Make a hyperlink of an image
How to use an image as a link.
Create an image map
How to create an image map, with clickable regions. Each of the regions is a hyperlink.
HTML Tables
Apples 44%
Bananas 23%
Oranges 13%
Other 10%
Tables
How to create tables in an HTML document.
Table borders
How to specify different table borders.
(You can find more examples at the bottom of this page).
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>
More Examples
<col /> Defines attribute values for one or more columns in a table
HTML Lists
An ordered list: An unordered list:
1. The first list item • List item
2. The second list item • List item
3. The third list item • List item
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.
(You can find more examples at the bottom of this page).
Milk
More Examples
Try-It-Yourself Examples
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.
The <form> tag is used to create an HTML form:
<form>
.
input elements
.
</form>
First name:
Last name:
Bottom of Form
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:
Bottom of Form
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>
How the HTML code above looks in a browser:
Top of Form
Male
Female
Bottom of Form
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
Bottom of Form
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:
<form name="input" action="html_form_action.asp" method="get">
Username: <input type="text" name="user" />
<input type="submit" value="Submit" />
</form>
Username:
Bottom of Form
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.
Form Examples
Fieldset around form-data
How to create a border around elements in a form.
Form with text fields and a submit button
How to create a form with two text fields and a submit button.
Form with checkboxes
How to create a form with three checkboxes and a submit button.
Form with radio buttons
How to create a form with two radio buttons, and a submit button.
Send e-mail from a form
How to send e-mail from 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.
(You can find more examples at the bottom of this page)
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 disadvantages of using frames are:
• The web developer must keep track of more HTML documents
• It is difficult to print the entire page
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%,*").
More Examples
<noframes> Defines a noframe section for browsers that do not handle frames
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
Color Color HEX Color RGB
#000000 rgb(0,0,0)
#FF0000 rgb(255,0,0)
#00FF00 rgb(0,255,0)
#0000FF rgb(0,0,255)
#FFFF00 rgb(255,255,0)
#00FFFF rgb(0,255,255)
#FF00FF rgb(255,0,255)
#C0C0C0 rgb(192,192,192)
#FFFFFF rgb(255,255,255)
Try it yourself »
#000000 rgb(0,0,0)
#080000 rgb(8,0,0)
#100000 rgb(16,0,0)
#180000 rgb(24,0,0)
#200000 rgb(32,0,0)
#280000 rgb(40,0,0)
#300000 rgb(48,0,0)
#380000 rgb(56,0,0)
#400000 rgb(64,0,0)
#480000 rgb(72,0,0)
#500000 rgb(80,0,0)
#580000 rgb(88,0,0)
#600000 rgb(96,0,0)
#680000 rgb(104,0,0)
#700000 rgb(112,0,0)
#780000 rgb(120,0,0)
#800000 rgb(128,0,0)
#880000 rgb(136,0,0)
#900000 rgb(144,0,0)
#980000 rgb(152,0,0)
#A00000 rgb(160,0,0)
#A80000 rgb(168,0,0)
#B00000 rgb(176,0,0)
#B80000 rgb(184,0,0)
#C00000 rgb(192,0,0)
#C80000 rgb(200,0,0)
#D00000 rgb(208,0,0)
#D80000 rgb(216,0,0)
#E00000 rgb(224,0,0)
#E80000 rgb(232,0,0)
#F00000 rgb(240,0,0)
#F80000 rgb(248,0,0)
#FF0000 rgb(255,0,0)
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:
Gray Shades Color HEX Color RGB
#000000 rgb(0,0,0)
#080808 rgb(8,8,8)
#101010 rgb(16,16,16)
#181818 rgb(24,24,24)
#202020 rgb(32,32,32)
#282828 rgb(40,40,40)
#303030 rgb(48,48,48)
#383838 rgb(56,56,56)
#404040 rgb(64,64,64)
#484848 rgb(72,72,72)
#505050 rgb(80,80,80)
#585858 rgb(88,88,88)
#606060 rgb(96,96,96)
#686868 rgb(104,104,104)
#707070 rgb(112,112,112)
#787878 rgb(120,120,120)
#808080 rgb(128,128,128)
#888888 rgb(136,136,136)
#909090 rgb(144,144,144)
#989898 rgb(152,152,152)
#A0A0A0 rgb(160,160,160)
#A8A8A8 rgb(168,168,168)
#B0B0B0 rgb(176,176,176)
#B8B8B8 rgb(184,184,184)
#C0C0C0 rgb(192,192,192)
#C8C8C8 rgb(200,200,200)
#D0D0D0 rgb(208,208,208)
#D8D8D8 rgb(216,216,216)
#E0E0E0 rgb(224,224,224)
#E8E8E8 rgb(232,232,232)
#F0F0F0 rgb(240,240,240)
#F8F8F8 rgb(248,248,248)
#FFFFFF rgb(255,255,255)
Note: Different browsers may display different colors for the same color name. "Green" can
be lighter in one browser than another. To achieve the same result in all browsers, always use the
HEX notation.
Web Safe Colors?
Some years ago, when computers supported max 256 different colors, a list of 216 "Web Safe
Colors" was suggested as a Web standard, reserving 40 fixed system colors.
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:
000000 000033 000066 000099 0000CC 0000FF
Note: Different browsers may display different colors for the same color name. "Green" can
be lighter in one browser than another. To achieve the same result in all browsers, always use the
HEX notation.
Sorted by Names
Link: Same list sorted by values
Color Name HEX Color Shades Mix
Note: The names above are not a part of the W3C web standard.
W3C have listed only 17 valid color names:
aqua, black, blue, fuchsia, gray, grey, green, lime, maroon, navy, olive, purple, red, silver, teal,
white, and yellow.
If you want valid HTML or CSS, use the HEX values instead.
HTML Quick List from W3Schools. Print it, fold it, and put it in your pocket.
</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>
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">
<input type="text" name="email" size="40" maxlength="50" />
<input type="password" />
<input type="checkbox" checked="checked" />
<input type="radio" checked="checked" />
<input type="submit" value="Send" />
<input type="reset" />
<input type="hidden" />
<select>
<option>Apples</option>
<option selected="selected">Bananas</option>
<option>Cherries</option>
</select>
<textarea name="comment" rows="60" cols="20"></textarea>
</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
Top of Form
Bottom of Form
HTML DOCTYPE Element
Tag Description
In HTML 4.0, all formatting can be removed from the HTML document, and stored in a style
sheet.
Try-It-Yourself Examples
Inline Styles
An inline style can be used if a unique style is to be applied to one single occurrence of an
element.
To use inline styles, use the style attribute in the relevant tag. The style attribute can contain any
CSS property. The example below shows how to change the text color and the left margin of a
paragraph:
<p style="color:blue;margin-left:20px">This is a paragraph.</p>
<link /> Defines the relationship between a document and an external resource
Try-It-Yourself Examples
The title of a document
The <title> tag defines the title of the document.
One target for all links
How to use the base tag to let all the links on a page open in a new window.
The HTML head Element
The head element is a container for all the head elements. Elements inside <head> can include
scripts, instruct the browser where to find style sheets, provide meta information, and more.
The following tags can be added to the head section: <title>, <base>, <link>, <meta>, <script>,
and <style>.
<body>
The content of the document......
</body>
</html>
Note: A lot of webmasters have used <meta> tags for spamming, like repeating keywords (or
using wrong keywords) for higher ranking. Therefore, most search engines have stopped using
<meta> tags to index/rank pages.
Try-It-Yourself Examples
Insert a script
How to insert a script into an HTML document.
Use of the <noscript> tag
How to handle browsers that do not support scripting, or have scripting disabled.
Example
<script type="text/javascript">
document.write("Hello World!")
</script>
Try it yourself »
Example
<script type="text/javascript">
document.write("Hello World!")
</script>
<noscript>Sorry, your browser does not support JavaScript!</noscript>
Try it yourself »
<noscript Defines an alternate content for users that do not support client-side
> scripts
Example
Insert a JavaScript in an HTML page:
<script type="text/javascript">
document.write("Hello World!")
</script>
Try it yourself »
Browser Support
The <script> tag is supported in all major browsers.
Required Attributes
DTD indicates in which HTML 4.01/XHTML 1.0 DTD the attribute is allowed. S=Strict,
T=Transitional, and F=Frameset.
DT
Attribute Value Description
D
Optional Attributes
DT
Attribute Value Description
D
Standard Attributes
The <script> tag does not support any standard attributes.
More information about Standard Attributes.
Event Attributes
The <script> tag does not support any event attributes.
More information about Event Attributes.