HTML Attributes
HTML Attributes
HTML Attributes
HTML HOME
HTML Introduction
HTML Get Started
HTML Basic
HTML Elements
HTML Attributes
HTML Headings
HTML Paragraphs
HTML Formatting
HTML Styles
HTML Links
HTML Images
HTML Tables
HTML Lists
HTML Forms
HTML Frames
HTML Colors
HTML Colornames
HTML Colorvalues
HTML Quick List
HTML Advanced
HTML 4.0 Why
HTML CSS
HTML Head
HTML Meta
HTML Scripts
HTML Entities
HTML URLs
HTML URL Encode
HTML Webserver
HTML Summary
HTML Examples
HTML Examples
HTML Quiz
HTML Certificate
HTML References
HTML Tag List
HTML Attributes
HTML Events
HTML Colornames
HTML Colorpicker
HTML Character Sets
HTML ASCII
HTML ISO-8859-1
HTML Symbols
HTML URL Encode
HTML Lang Codes
HTML Status Codes
HTML Tutorial
« W3Schools Home Next Chapter »
With our HTML editor, you can edit the HTML, and click on a button to view the result.
Example
<html>
<body>
</body>
</html>
Try it yourself »
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 ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
HTML Introduction
« Previous Next Chapter »
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
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
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
In this tutorial we use a plain text editor (like Notepad) to edit HTML. We believe this is the best
way to learn HTML.
However, professional web developers often prefer HTML editors like FrontPage or
Dreamweaver, instead of writing plain text.
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.
.HTM or .HTML File Extension?
When you save an HTML file, you can use either the .htm or the .html file extension. We use
.htm in our examples. It is a habit from the past, when the software only allowed three letters in
file extensions.
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
<a href="http://www.w3schools.com">This is a link</a>
Try it yourself »
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 Elements
« Previous Next Chapter »
HTML documents are defined by HTML elements.
HTML Elements
An HTML element is everything from the start tag to the end tag:
* 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.
</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 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.
<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.
W3Schools use lowercase tags because the World Wide Web Consortium (W3C) recommends
lowercase in HTML 4, and demands lowercase tags in future versions of (X)HTML.
HTML Attributes
« Previous Next Chapter »
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
<a href="http://www.w3schools.com">This is a link</a>
Try it yourself »
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.
Newer versions of (X)HTML will demand lowercase attributes.
Below is a list of some attributes that are standard for most HTML elements:
HTML Headings
« Previous Next Chapter »
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.
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
<!-- This is a comment -->
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
HTML Paragraphs
« Previous Next Chapter »
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.
Even if <br> works in all browsers, writing <br /> instead is more future proof.
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
(The example demonstrates some HTML formatting problems)
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).
<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.
Text direction
How to change the text direction.
Quotations
How to handle long and short quotations.
HTML Styles
« Previous Next Chapter »
You can learn everything about styles and CSS in our CSS Tutorial.
In our HTML tutorial we will use the style attribute to introduce you to HTML styles.
Tags Description
<center> Defines centered content
<font> and <basefont> Defines HTML fonts
<s> and <strike> Defines strikethrough text
<u> Defines underlined text
Attributes Description
align Defines the alignment of text
bgcolor Defines the background color
color Defines the text color
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 »
HTML Links
« Previous Next Chapter »
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. 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
<a href="http://www.w3schools.com/" target="_blank">Visit W3Schools!</a>
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.
Tip: If a browser does not find the named anchor specified, it goes to the top of the document.
No error occurs.
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.
HTML Images
« Previous Next Chapter »
Example
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 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.
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.
Your browser does not support inline frames or is currently configured not to display inline
frames.
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Top 10 Web Hosting
UK Reseller Hosting
Cloud Hosting
$0 PHP Hosting
WEB BUILDING
XML Editor – Free Trial!
FREE Flash Website
6,000+ HTML Templates
Download now (FREE)
Free SEO
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE
HTML Tables
« Previous Next Chapter »
HTML Tables
Apples 44%
Bananas 23%
Oranges 13%
Other 10%
Table borders
How to specify different table borders.
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>
<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
Table headers
How to create table headers.
Table with a caption
How to add a caption to a table.
Cell padding
How to use cellpadding to create more white space between the cell content and its borders.
Cell spacing
How to use cellspacing to increase the distance between the cells.
HTML Lists
« Previous Next Chapter »
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
HTML Ordered Lists
An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.
<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
More Examples
Nested list
Demonstrates how you can nest lists.
Nested list 2
Demonstrates a more complicated nested list.
Definition list
Demonstrates a definition list.
Try-It-Yourself Examples
Create text fields
How to create text fields. The user can write text in a text field.
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>
HTML Forms - The Input Element
The most important form element is the input element.
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>
How the HTML code above looks in a browser:
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>
How the HTML code above looks in a browser:
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>
How the HTML code above looks in a browser:
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>
How the HTML code above looks in a browser:
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:
<form name="input" action="html_form_action.asp" method="get">
Username: <input type="text" name="user" />
<input type="submit" value="Submit" />
</form>
How the HTML code above looks in a browser:
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.
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.
HTML Frames
« Previous Next Chapter »
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.
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:
<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
How to use the <noframes> tag
How to use the <noframes> tag (for browsers that do not support frames).
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.
Inline frame
How to create an inline frame (a frame inside an HTML page).
HTML Colors
« Previous Next Chapter »
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 »
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:
000000 000033 000066 000099 0000CC 0000FF
003300 003333 003366 003399 0033CC 0033FF
006600 006633 006666 006699 0066CC 0066FF
009900 009933 009966 009999 0099CC 0099FF
00CC00 00CC33 00CC66 00CC99 00CCCC 00CCFF
00FF00 00FF33 00FF66 00FF99 00FFCC 00FFFF
330000 330033 330066 330099 3300CC 3300FF
333300 333333 333366 333399 3333CC 3333FF
336600 336633 336666 336699 3366CC 3366FF
339900 339933 339966 339999 3399CC 3399FF
33CC00 33CC33 33CC66 33CC99 33CCCC 33CCFF
33FF00 33FF33 33FF66 33FF99 33FFCC 33FFFF
660000 660033 660066 660099 6600CC 6600FF
663300 663333 663366 663399 6633CC 6633FF
666600 666633 666666 666699 6666CC 6666FF
669900 669933 669966 669999 6699CC 6699FF
66CC00 66CC33 66CC66 66CC99 66CCCC 66CCFF
66FF00 66FF33 66FF66 66FF99 66FFCC 66FFFF
990000 990033 990066 990099 9900CC 9900FF
993300 993333 993366 993399 9933CC 9933FF
996600 996633 996666 996699 9966CC 9966FF
999900 999933 999966 999999 9999CC 9999FF
99CC00 99CC33 99CC66 99CC99 99CCCC 99CCFF
99FF00 99FF33 99FF66 99FF99 99FFCC 99FFFF
CC0000 CC0033 CC0066 CC0099 CC00CC CC00FF
CC3300 CC3333 CC3366 CC3399 CC33CC CC33FF
CC6600 CC6633 CC6666 CC6699 CC66CC CC66FF
CC9900 CC9933 CC9966 CC9999 CC99CC CC99FF
CCCC00 CCCC33 CCCC66 CCCC99 CCCCCC CCCCFF
CCFF00 CCFF33 CCFF66 CCFF99 CCFFCC CCFFFF
FF0000 FF0033 FF0066 FF0099 FF00CC FF00FF
FF3300 FF3333 FF3366 FF3399 FF33CC FF33FF
FF6600 FF6633 FF6666 FF6699 FF66CC FF66FF
FF9900 FF9933 FF9966 FF9999 FF99CC FF99FF
FFCC00 FFCC33 FFCC66 FFCC99 FFCCCC FFCCFF
FFFF00 FFFF33 FFFF66 FFFF99 FFFFCC FFFFFF
Tip: The 17 standard colors are: aqua, black, blue, fuchsia, gray, grey, green, lime,
maroon, navy, olive, purple, red, silver, teal, white, and yellow.
Click on a color name (or a hex value) to view the color as the background-color along
with different text colors: