Pages

HTML - XHTML

XHTML is HTML written as XML.

What Is XHTML?

  • XHTML stands for EXtensible HyperText Markup Language
  • XHTML is almost identical to HTML 4.01
  • XHTML is a stricter and cleaner version of HTML 4.01
  • XHTML is HTML defined as an XML application
  • XHTML is supported by all major browsers.

Why XHTML?

Many pages on the internet contain "bad" HTML.
The following HTML code will work fine if you view it in a browser (even if it does NOT follow the HTML rules):
<html>
<head>
<title>This is bad HTML</title>
<body>
<h1>Bad HTML
<p>This is a paragraph
</body>
XML is a markup language where documents must be marked up correctly and "well-formed".
If you want to study XML, please read our XML tutorial.
Today's market consists of different browser technologies. Some browsers run on computers, and some browsers run on mobile phones or other small devices. Smaller devices often lack the resources or power to interpret a "bad" markup language.
Therefore - by combining the strengths of HTML and XML, XHTML was developed. XHTML is HTML redesigned as XML.

The Most Important Differences from HTML:

Document Structure

  • XHTML DOCTYPE is mandatory
  • The XML namespace attribute in <html> is mandatory
  • <html>, <head>, <title>, and <body> is mandatory

XHTML Elements

  • XHTML elements must be properly nested
  • XHTML elements must always be closed
  • XHTML elements must be in lowercase
  • XHTML documents must have one root element

XHTML Attributes

  • Attribute names must be in lower case
  • Attribute values must be quoted
  • Attribute minimization is forbidden

<!DOCTYPE ....> Is Mandatory

An XHTML document must have an XHTML DOCTYPE declaration.
A complete list of all the XHTML Doctypes is found in our HTML Tags Reference.
The <html>, <head>, <title>, and <body> elements must also be present, and the xmlns attribute in <html>, must specify the xml namespace for the document.
The example below shows an XHTML document with a minimum of required tags:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Title of document</title>
</head>

<body>
......
</body>

</html>


XHTML Elements Must Be Properly Nested

In HTML, some elements can be improperly nested within each other, like this:
<b><i>This text is bold and italic</b></i>
In XHTML, all elements must be properly nested within each other, like this:
<b><i>This text is bold and italic</i></b>


XHTML Elements Must Always Be Closed

This is wrong:
<p>This is a paragraph
<p>This is another paragraph
This is correct:
<p>This is a paragraph</p>
<p>This is another paragraph</p>


Empty Elements Must Also Be Closed

This is wrong:
A break: <br>
A horizontal rule: <hr>
An image: <img src="happy.gif" alt="Happy face">
This is correct:
A break: <br />
A horizontal rule: <hr />
An image: <img src="happy.gif" alt="Happy face" />


XHTML Elements Must Be In Lower Case

This is wrong:
<BODY>
<P>This is a paragraph</P>
</BODY>
This is correct:
<body>
<p>This is a paragraph</p>
</body>


Attribute Names Must Be In Lower Case

This is wrong:
<table WIDTH="100%">
This is correct:
<table width="100%">


Attribute Values Must Be Quoted

This is wrong:
<table width=100%>
This is correct:
<table width="100%">


Attribute Minimization Is Forbidden

This is wrong:
<input checked>
<input readonly>
<input disabled>
<option selected>
This is correct:
<input checked="checked">
<input readonly="readonly">
<input disabled="disabled">
<option selected="selected">


How to Convert from HTML to XHTML

  1. Add an XHTML <!DOCTYPE> to the first line of every page
  2. Add an xmlns attribute to the html element of every page
  3. Change all element names to lowercase
  4. Close all empty elements
  5. Change all attribute names to lowercase
  6. Quote all attribute values

Read Users' Comments (0)

You Have Learned HTML, Now What?

HTML Summary

This tutorial has taught you how to use HTML to create your own web site.
HTML is the universal markup language for the Web. HTML lets you format text, add graphics, create links, input forms, frames and tables, etc., and save it all in a text file that any browser can read and display.
The key to HTML is the tags, which indicates what content is coming up.

Now You Know HTML, What's Next?


Learn CSS

CSS is used to control the style and layout of multiple Web pages all at once.
With CSS, all formatting can be removed from the HTML document and stored in a separate file.
CSS gives you total control of the layout, without messing up the document content.
To learn how to create style sheets, please visit our CSS tutorial.

Learn JavaScript

JavaScript can make your web site more dynamic.
A static web site is nice when you just want to show flat content, but a dynamic web site can react to events and allow user interaction.
JavaScript is the most popular scripting language on the internet and it works with all major browsers.
If you want to learn more about JavaScript, please visit our JavaScript tutorial.

Hosting your own Web site

Hosting your web site on your own server is always an option. Here are some points to consider:

Hardware Expenses

To run a "real" web site, you will have to buy some powerful server hardware. Don't expect that a low cost PC will do the job. You will also need a permanent (24 hours a day ) high-speed connection.

Software Expenses

Remember that server-licenses often are higher than client-licenses. Also note that server-licenses might have limits on number of users.

Labor Expenses

Don't expect low labor expenses. You have to install your own hardware and software. You also have to deal with bugs and viruses, and keep your server constantly running in an environment where "everything could happen".

Using an Internet Service Provider

Renting a server from an Internet Service Provider (ISP) is a common option.
Most small companies store their web site on a server provided by an ISP. Here are some advantages:

Connection Speed

Most ISPs have very fast connections to the Internet.

Powerful Hardware

ISPs often have powerful web servers that can be shared by several companies. You can also expect them to have an effective load balancing, and necessary backup servers.

Security and Stability

ISPs are specialists on web hosting. Expect their servers to have more than 99% up time, the latest software patches, and the best virus protection.

Things to Consider with an ISP

24-hour support

Make sure your ISP offers 24-hours support. Don't put yourself in a situation where you cannot fix critical problems without having to wait until the next working day. Toll-free phone could be vital if you don't want to pay for long distance calls.

Daily Backup

Make sure your ISP runs a daily backup routine, otherwise you may lose some valuable data.

Traffic Volume

Study the ISP's traffic volume restrictions. Make sure that you don't have to pay a fortune for unexpected high traffic if your web site becomes popular.

Bandwidth or Content Restrictions

Study the ISP's bandwidth and content restrictions. If you plan to publish pictures or broadcast video or sound, make sure that you can.

E-mail Capabilities

Make sure your ISP supports the e-mail capabilities you need.

Database Access

If you plan to use data from databases on your web site, make sure your ISP supports the database access you need.

Read Users' Comments (0)

HTML Quick List

HTML Quick List from W3Schools. Print it, fold it, and put it in your pocket.

HTML Basic Document

<!DOCTYPE html>
<html>
<head>
<title>Title of document goes here</title>
</head>
<body>
Visible text goes here...
</body>
</html>

Basic Tags

<h1>Largest Heading</h1>
<h2> . . . </h2>
<h3> . . . </h3>
<h4> . . . </h4>
<h5> . . . </h5>
<h6>Smallest Heading</h6>

<p>This is a paragraph.</p>
<br> (line break)
<hr> (horizontal rule)
<!-- This is a comment -->

Formatting

<b>Bold text</b>
<code>Computer code</code>
<em>Emphasized text</em>
<i>Italic text</i>
<kbd>Keyboard input</kbd> 
<pre>Preformatted text</pre>
<small>Smaller text</small>
<strong>Important text</strong>

<abbr> (abbreviation)
<address> (contact information)
<bdo> (text direction)
<blockquote> (a section quoted from another source)
<cite> (title of a work)
<del> (deleted text)
<ins> (inserted text)
<sub> (subscripted text)
<sup> (superscripted text)

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:webmaster@example.com">Send e-mail</a>
Bookmark:
<a id="tips">Tips Section</a>
<a href="#tips">Jump to the Tips Section</a>

Images

<img src="URL" alt="Alternate Text" height="42" width="42">

Styles/Sections

<style type="text/css">
  h1 {color:red;}
  p {color:blue;}
</style>

<div>A block-level section in a document</div>
<span>An inline section in a document</span>

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>Item 1</dt>
    <dd>Describe item 1</dd>
  <dt>Item 2</dt>
    <dd>Describe item 2</dd>
</dl>

Tables

<table border="1">
  <tr>
    <th>table header</th>
    <th>table header</th>
  </tr>
  <tr>
    <td>table data</td>
    <td>table data</td>
  </tr>
</table>

Iframe

<iframe src="demo_iframe.htm"></iframe>

Forms

<form action="demo_form.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

&lt; is the same as <
&gt; is the same as >
&#169; is the same as

http//:www.4wschools.blogspot.com

Read Users' Comments (0)

HTML Uniform Resource Locators

A URL is another word for a web address.
A URL can be composed of words, such as "w3schools.com", or an Internet Protocol (IP) address: 192.68.20.50. Most people enter the name of the website when surfing, because names are easier to remember than numbers.

URL - Uniform Resource Locator

Web browsers request pages from web servers by using a URL.
When you click on a link in an HTML page, an underlying <a> tag points to an address on the world wide web.
A Uniform Resource Locator (URL) is used to address a document (or other data) on the world wide web.
A web address, like this: http://www.4wschools.blogspot.com follows these syntax rules:

scheme://host.domain:port/path/filename

Explanation:
  • scheme - defines the type of Internet service. The most common type is http
  • host - defines the domain host (the default host for http is www)
  • domain - defines the Internet domain name, like 4wschools.blogspot.com
  • port - defines the port number at the host (the default port number for http is 80
  • path - defines a path at the server (If omitted, the document must be stored at the root directory of the web site)
  • filename - defines the name of a document/resource


Common URL Schemes

The table below lists some common schemes:
SchemeShort for....Which pages will the scheme be used for...
httpHyperText Transfer ProtocolCommon web pages starts with http://. Not encrypted
httpsSecure HyperText Transfer ProtocolSecure web pages. All information exchanged are encrypted
ftpFile Transfer ProtocolFor downloading or uploading files to a website. Useful for domain maintenance
file A file on your computer

URL Encoding

URLs can only be sent over the Internet using the ASCII character-set.
Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format.
URL encoding converts characters into a format that can be transmitted over the Internet.
URL encoding replaces non ASCII characters with a "%" followed by two hexadecimal digits.
URLs cannot contain spaces. URL encoding normally replaces a space with a + sign.

Read Users' Comments (0)

HTML Entities

Reserved characters in HTML must be replaced with character entities.

HTML Entities

Some characters are reserved in HTML.
It is not possible to use the less than (<) or greater than (>) signs in your text, because the browser will mix them with tags.
To actually display reserved characters, we must use character entities in the HTML source code.
A character entity looks like this:

entity_name;
OR
&#entity_number;

o display a less than sign we must write: &lt; or &#60;
RemarkTip: The advantage of using an entity name, instead of a number, is that the name is easier to remember. However, the disadvantage is that browsers may not support all entity names (the support for entity numbers is very good).

Non-breaking Space

A common character entity used in HTML is the non-breaking space (&nbsp;).
Browsers will always truncate spaces in HTML pages. If you write 10 spaces in your text, the browser will remove 9 of them, before displaying the page. To add spaces to your text, you can use the &nbsp; character entity.

HTML Useful Character Entities

Note: Entity names are case sensitive!
ResultDescriptionEntity NameEntity Number
 non-breaking space&nbsp;&#160;
<less than&lt;&#60;
>greater than&gt;&#62;
&ampersand&amp;&#38;
¢cent&cent;&#162;
£pound&pound;&#163;
¥yen&yen;&#165;
euro&euro;&#8364;
§section&sect;&#167;
©copyright&copy;&#169;
®registered trademark&reg;&#174;
trademark&trade;&#8482;

Read Users' Comments (0)

HTML Scripts

JavaScripts make HTML pages more dynamic and interactive.

The HTML <script> Tag

The <script> tag is used to define a client-side script, such as a JavaScript.
The <script> element either contains scripting statements or it points to an external script file through the src attribute.
Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content.
The script below writes Hello World! to the HTML output:

Example

<script>
document.write("Hello World!")
</script>

The HTML <noscript> Tag

The <noscript> tag is used to provide an alternate content for users that have disabled scripts in their browser or have a browser that doesn’t support client-side scripting.
The <noscript> element can contain all the elements that you can find inside the <body> element of a normal HTML page.
The content inside the <noscript> element will only be displayed if scripts are not supported, or are disabled in the user’s browser:

Example

<script>
document.write("Hello World!")
</script>
<noscript>Sorry, your browser does not support JavaScript!</noscript>

HTML Script Tags

TagDescription
<script>Defines a client-side script
<noscript>Defines an alternate content for users that do not support client-side scripts

Read Users' Comments (0)

HTML Color Values

Sorted by Hex Value

Color NameHEXColorShadesMix
Black #000000 ShadesMix
Navy #000080 ShadesMix
DarkBlue #00008B ShadesMix
MediumBlue #0000CD ShadesMix
Blue #0000FF ShadesMix
DarkGreen #006400 ShadesMix
Green #008000 ShadesMix
Teal #008080 ShadesMix
DarkCyan #008B8B ShadesMix
DeepSkyBlue #00BFFF ShadesMix
DarkTurquoise #00CED1 ShadesMix
MediumSpringGreen #00FA9A ShadesMix
Lime #00FF00 ShadesMix
SpringGreen #00FF7F ShadesMix
Aqua #00FFFF ShadesMix
Cyan #00FFFF ShadesMix
MidnightBlue #191970 ShadesMix
DodgerBlue #1E90FF ShadesMix
LightSeaGreen #20B2AA ShadesMix
ForestGreen #228B22 ShadesMix
SeaGreen #2E8B57 ShadesMix
DarkSlateGray #2F4F4F ShadesMix
LimeGreen #32CD32 ShadesMix
MediumSeaGreen #3CB371 ShadesMix
Turquoise #40E0D0 ShadesMix
RoyalBlue #4169E1 ShadesMix
SteelBlue #4682B4 ShadesMix
DarkSlateBlue #483D8B ShadesMix
MediumTurquoise #48D1CC ShadesMix
Indigo  #4B0082 ShadesMix
DarkOliveGreen #556B2F ShadesMix
CadetBlue #5F9EA0 ShadesMix
CornflowerBlue #6495ED ShadesMix
MediumAquaMarine #66CDAA ShadesMix
DimGray #696969 ShadesMix
SlateBlue #6A5ACD ShadesMix
OliveDrab #6B8E23 ShadesMix
SlateGray #708090 ShadesMix
LightSlateGray #778899 ShadesMix
MediumSlateBlue #7B68EE ShadesMix
LawnGreen #7CFC00 ShadesMix
Chartreuse #7FFF00 ShadesMix
Aquamarine #7FFFD4 ShadesMix
Maroon #800000 ShadesMix
Purple #800080 ShadesMix
Olive #808000 ShadesMix
Gray #808080 ShadesMix
SkyBlue #87CEEB ShadesMix
LightSkyBlue #87CEFA ShadesMix
BlueViolet #8A2BE2 ShadesMix
DarkRed #8B0000 ShadesMix
DarkMagenta #8B008B ShadesMix
SaddleBrown #8B4513 ShadesMix
DarkSeaGreen #8FBC8F ShadesMix
LightGreen #90EE90 ShadesMix
MediumPurple #9370DB ShadesMix
DarkViolet #9400D3 ShadesMix
PaleGreen #98FB98 ShadesMix
DarkOrchid #9932CC ShadesMix
YellowGreen #9ACD32 ShadesMix
Sienna #A0522D ShadesMix
Brown #A52A2A ShadesMix
DarkGray #A9A9A9 ShadesMix
LightBlue #ADD8E6 ShadesMix
GreenYellow #ADFF2F ShadesMix
PaleTurquoise #AFEEEE ShadesMix
LightSteelBlue #B0C4DE ShadesMix
PowderBlue #B0E0E6 ShadesMix
FireBrick #B22222 ShadesMix
DarkGoldenRod #B8860B ShadesMix
MediumOrchid #BA55D3 ShadesMix
RosyBrown #BC8F8F ShadesMix
DarkKhaki #BDB76B ShadesMix
Silver #C0C0C0 ShadesMix
MediumVioletRed #C71585 ShadesMix
IndianRed  #CD5C5C ShadesMix
Peru #CD853F ShadesMix
Chocolate #D2691E ShadesMix
Tan #D2B48C ShadesMix
LightGray #D3D3D3 ShadesMix
Thistle #D8BFD8 ShadesMix
Orchid #DA70D6 ShadesMix
GoldenRod #DAA520 ShadesMix
PaleVioletRed #DB7093 ShadesMix
Crimson #DC143C ShadesMix
Gainsboro #DCDCDC ShadesMix
Plum #DDA0DD ShadesMix
BurlyWood #DEB887 ShadesMix
LightCyan #E0FFFF ShadesMix
Lavender #E6E6FA ShadesMix
DarkSalmon #E9967A ShadesMix
Violet #EE82EE ShadesMix
PaleGoldenRod #EEE8AA ShadesMix
LightCoral #F08080 ShadesMix
Khaki #F0E68C ShadesMix
AliceBlue #F0F8FF ShadesMix
HoneyDew #F0FFF0 ShadesMix
Azure #F0FFFF ShadesMix
SandyBrown #F4A460 ShadesMix
Wheat #F5DEB3 ShadesMix
Beige #F5F5DC ShadesMix
WhiteSmoke #F5F5F5 ShadesMix
MintCream #F5FFFA ShadesMix
GhostWhite #F8F8FF ShadesMix
Salmon #FA8072 ShadesMix
AntiqueWhite #FAEBD7 ShadesMix
Linen #FAF0E6 ShadesMix
LightGoldenRodYellow #FAFAD2 ShadesMix
OldLace #FDF5E6 ShadesMix
Red #FF0000 ShadesMix
Fuchsia #FF00FF ShadesMix
Magenta #FF00FF ShadesMix
DeepPink #FF1493 ShadesMix
OrangeRed #FF4500 ShadesMix
Tomato #FF6347 ShadesMix
HotPink #FF69B4 ShadesMix
Coral #FF7F50 ShadesMix
DarkOrange #FF8C00 ShadesMix
LightSalmon #FFA07A ShadesMix
Orange #FFA500 ShadesMix
LightPink #FFB6C1 ShadesMix
Pink #FFC0CB ShadesMix
Gold #FFD700 ShadesMix
PeachPuff #FFDAB9 ShadesMix
NavajoWhite #FFDEAD ShadesMix
Moccasin #FFE4B5 ShadesMix
Bisque #FFE4C4 ShadesMix
MistyRose #FFE4E1 ShadesMix
BlanchedAlmond #FFEBCD ShadesMix
PapayaWhip #FFEFD5 ShadesMix
LavenderBlush #FFF0F5 ShadesMix
SeaShell #FFF5EE ShadesMix
Cornsilk #FFF8DC ShadesMix
LemonChiffon #FFFACD ShadesMix
FloralWhite #FFFAF0 ShadesMix
Snow #FFFAFA ShadesMix
Yellow #FFFF00 ShadesMix
LightYellow #FFFFE0 ShadesMix
Ivory #FFFFF0 ShadesMix
White #FFFFFF ShadesMix

Read Users' Comments (0)