Beruflich Dokumente
Kultur Dokumente
Microsoft WebMatrix
Sublime Text
However, for learning HTML we recommend a text editor like Notepad (PC) or TextEdit (Mac).
We believe using a simple text editor is a good way to learn HTML.
Follow the 4 steps below to create your first web page with Notepad.
You can use either .htm or .html as file extension. There is no difference, it is up to you.
To open a file in a browser, double click on the file, or right-click, and choose open with.
Next Chapter
Don't worry if these examples use tags you have not learned.
You will learn about them in the next chapters.
HTML Documents
All HTML documents must start with a type declaration: <!DOCTYPE html>.
The HTML document itself begins with <html> and ends with </html>.
The visible part of the HTML document is between <body> and </body>.
Example
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
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>
HTML Paragraphs
HTML paragraphs are defined with the <p> tag:
Example
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
HTML Links
HTML links are defined with the <a> tag:
Example
<a href="http://www.w3schools.com">This is a link</a>
HTML Images
HTML images are defined with the <img> tag.
The source file (src), alternative text (alt), and size (width and height) are provided as
attributes:
Example
<img src="w3schools.jpg" alt="W3Schools.com" width="104" height="142">
HTML Elements
Previous
Next Chapter
HTML Elements
HTML elements are written with a start tag, with an end tag, with the content in between:
<tagname>content</tagname>
The HTML element is everything from the start tag to the end tag:
Element content
End tag
<h1>
My First Heading
</h1>
<p>
<br>
Some HTML elements do not have an end tag.
The example above works in all browsers, because the closing tag is considered optional.
Never rely on this. It might produce unexpected results and/or errors if you forget the end tag.
HTML Attributes
Previous
Next Chapter
HTML Attributes
The first two letters specify the language (en). If there is a dialect, use two more letters (US).
You will learn more about links and the <a> tag later in this tutorial.
Size Attributes
HTML images are defined with the <img> tag.
The filename of the source (src), and the size of the image (width and height) are all provided as
attributes:
Example
<img src="w3schools.jpg" width="104" height="142">
The image size is specified in pixels: width="104" means 104 screen pixels wide.
You will learn more about images and the <img> tag later in this tutorial.
W3C recommends quotes in HTML4, and demands quotes for stricter document types like
XHTML.
Sometimes it is necessary to use quotes. This will not display correctly, because it contains a
space:
Example
<p title=About W3Schools>
Using quotes are the most common. Omitting quotes can produce errors.
At W3Schools we always use quotes around attribute values.
Or vice versa:
<p title="John 'ShotGun' Nelson">
Chapter Summary
HTML Attributes
Below is an alphabetical list of some attributes often used in HTML:
Attribute
Description
alt
disabled
href
id
src
style
title
HTML Headings
Previous
Next Chapter
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>
Note: Browsers automatically add some empty space (a margin) before and after each heading.
<meta charset="UTF-8">
</head>
<body>
.
.
.
Meta data means data about data. HTML meta data is data about the HTML document.
To find out, right-click in the page and select "View Page Source" (in Chrome) or "View Source"
(in IE), or similar in another browser. This will open a window containing the HTML code of the
page.
Description
<html>
<body>
<head>
HTML Paragraphs
Previous
Next Chapter
HTML Paragraphs
HTML Display
You cannot be sure how HTML will be displayed.
Large or small screens, and resized windows will create different results.
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 spaces, and any number of new lines, count as only one space.
Example
<p>
This paragraph
contains a lot of lines
in the source code,
but the browser
ignores it.
</p>
<p>
This paragraph
contains
a lot of spaces
in the source
code,
but the
browser
ignores it.
</p>
Most browsers will display HTML correctly even if you forget the end tag:
Example
<p>This is a paragraph
<p>This is another paragraph
The example above will work in most browsers, but do not rely on it.
Forgetting the end tag can produce unexpected results or errors.
Stricter versions of HTML, like XHTML, do not allow you to skip the end tag.
Description
Defines a paragraph
HTML Styles
Previous
Next Chapter
HTML Styles
I am red
I am blue
The color property defines the text color for an HTML element:
Example
<h1 style="color:blue;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
HTML Fonts
The font-family property defines the font to be used for an HTML element:
Example
<h1 style="font-family:verdana;">This is a heading</h1>
<p style="font-family:courier;">This is a paragraph.</p>
Chapter Summary
Bold text
Important text
Italic text
Emphasized text
Marked text
Small text
Deleted text
Inserted text
Subscripts
Superscripts
The HTML <b> element defines bold text, without any extra importance.
Example
<p>This text is normal.</p>
<p><b>This text is bold</b>.</p>
The HTML <strong> element defines strong text, with added semantic "strong" importance.
Example
<p>This text is normal.</p>
<p><strong>This text is strong</strong>.</p>
The HTML <em> element defines emphasized text, with added semantic importance.
Example
<p>This text is normal.</p>
<p><em>This text is emphasized</em>.</p>
Browsers display <strong> as <b>, and <em> as <i>.
However, there is a difference in the meaning of these tags: <b> and <i> defines bold and italic
text,
but <strong> and <em> means that the text is "important".
Example
<h2>HTML <small>Small</small> Formatting</h2>
Example
<p>This is <sup>superscripted</sup> text.</p>
Description
<b>
<em>
<i>
<sup>
<ins>
<del>
For 50 years, WWF has been protecting the future of nature. The world's leading
conservation organization, WWF works in 100 countries and is supported by 1.2 million
members in the United States and close to 5 million globally.
Description
<abbr>
<address>
<bdo>
<blockquote>
<cite>
<q>
The <kbd>, <samp>, and <code> elements all support fixed letter size and spacing.
Result:
File | Open...
Result:
demo.example.com login: Apr 12 09:10:17 Linux 2.6.10grsec+gg3+e+fhs6b+nfs+gr0501+++p3+c4a+gr2b-reslog-v6.189
Result:
var x = 5; var y = 6; document.getElementById("demo").innerHTML = x + y;
Notice that the <code> element does not preserve extra whitespace and line-breaks.
To fix this, you can put the <code> element inside a <pre> element:
Example
<pre>
<code>
var x = 5;
var y = 6;
document.getElementById("demo").innerHTML = x + y;
</code>
</pre>
Result:
var x = 5;
var y = 6;
document.getElementById("demo").innerHTML = x + y;
Result:
Einstein wrote: E = mc2.
Description
Defines a variable
<pre>
HTML Comments
Previous
Next Chapter
Comment tags <!-- and --> are used to insert comments in HTML.
Comments are not displayed by the browser, but they can help document your HTML.
With comments you can place notifications and reminders in your HTML:
Example
<!-- This is a comment -->
<p>This is a paragraph.</p>
Comments are also great for debugging HTML, because you can comment out HTML lines of
code, one at a time, to search for errors:
Example
<!-- Do not display this at the moment
<img border="0" src="pic_mountain.jpg" alt="Mountain">
-->
Conditional Comments
You might stumble upon conditional comments in HTML:
<!--[if IE 8]>
.... some HTML here ....
<![endif]-->
HTML Colors
Previous
Next Chapter
TVs and computer screens display colors by combining Red, Green, and Blue light.
Color Names
With CSS, colors can be set by using color names:
Example
Color Name
Red
Orange
Yellow
Cyan
Blue
rgb(255, 0, 0)
Green
0
Blue
0
Example
Color
RGB
rgb(255,0,0)
rgb(255,255,0)
rgb(0,255,0)
rgb(0,255,255)
rgb(0,0,255)
Shades of gray are often defined using equal values for all the 3 light sources:
Example
Color
RGB
rgb(0,0,0)
rgb(128,128,128)
rgb(255,255,255)
Hexadecimal Colors
With HTML, RGB values can also be specified using hexadecimal color values in the form:
#RRGGBB, where RR (red), GG (green) and BB (blue) are hexadecimal values between 00 and
FF (same as decimal 0-255).
For example, #FF0000 is displayed as red, because red is set to its highest value (FF) and the
others are set to the lowest value (00).
Example
Color
HEX
#FF0000
#FFFF00
#00FF00
#00FFFF
#0000FF
Shades of gray are often defined using equal values for all the 3 light sources:
Example
Color
HEX
#000000 Black
#808080 Light
Black
#FFFFFF
T e x t
B o x e s
The most common way to add styling, is to keep the styles in separate CSS files. But, in this
tutorial, we use internal styling, because it is easier to demonstrate, and easier for you to try it
yourself.
You can learn much more about CSS in our CSS Tutorial.
<p>This is a paragraph.</p>
</body>
</html>
An external style sheet can be written in any text editor. The file should not contain any html
tags. The style sheet file must be saved with a .css extension.
Here is how the "styles.css" looks:
body {
background-color: lightgrey;
}
h1 {
color: blue;
}
p{
color:green;
}
CSS Fonts
The CSS color property defines the text color to be used for the HTML element.
The CSS font-family property defines the font to be used for the HTML element.
The CSS font-size property defines the text size to be used for the HTML element.
Example
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: blue;
font-family: verdana;
font-size: 300%;
}
p {
color: red;
font-family: courier;
font-size: 160%;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
The CSS border property defines a visible border around an HTML element:
Example
p{
border: 1px solid black;
}
The CSS padding property defines a padding (space) inside the border:
Example
p{
border: 1px solid black;
padding: 10px;
}
The CSS margin property defines a margin (space) outside the border:
Example
p{
border: 1px solid black;
padding: 10px;
margin: 30px;
}
The CSS examples above use px to define sizes in pixels.
The id Attribute
All the examples above use CSS to style HTML elements in a general way.
To define a special style for one special element, first add an id attribute to the element:
<p id="p01">I am different</p>
then define a style for the element with the specific id:
Example
#p01 {
color: blue;
}
Now you can define a different style for elements with the specific class:
Example
p.error {
color: red;
}
Use id to address a single element. Use class to address groups of elements.
Chapter Summary
Tag
Description
HTML Links
Previous
Next Chapter
Links are found in nearly all web pages. Links allow users to click their way from page to page.
Without a trailing slash on subfolder addresses, you might generate two requests to the server.
Many servers will automatically add a trailing slash to the address, and then create a new request.
Local Links
The example above used an absolute URL (A full web address).
A local link (link to the same web site) is specified with a relative URL (without http://www....).
Example
<a href="html_images.asp">HTML Images</a>
This example will open the linked document in a new browser window or in a new tab:
Example
<a href="http://www.w3schools.com/" target="_blank">Visit W3Schools!</a>
Target Value
Description
_blank
_self
Opens the linked document in the same frame as it was clicked (this is default)
_parent
_top
framename
If your webpage is locked in a frame, you can use target="_top" to break out of the frame:
Example
<a href="http://www.w3schools.com/html/" target="_top">HTML5 tutorial!</a>
To make a bookmark, you must first create the bookmark, and then add a link to it.
When the link is clicked, the page will scroll to the location with the bookmark.
Example
First, create a bookmark with the id attribute:
<h2 id="tips">Useful Tips Section</h2>
Then, add a link to the bookmark ("Useful Tips Section"), from within the same page:
<a href="#tips">Visit the Useful Tips Section</a>
Or, add a link to the bookmark ("Useful Tips Section"), from another page:
Example
<a href="html_tips.html#tips">Visit the Useful Tips Section</a>
Chapter Summary
Description
Defines a hyperlink
HTML Images
Previous
Next Chapter
JPG Images
GIF Images
PNG Images
Example
<!DOCTYPE html>
<html>
<body>
<h2>Spectacular Mountain</h2>
<img src="pic_mountain.jpg" alt="Mountain View" style="width:304px;height:228px;">
</body>
</html>
Always specify the width and height of an image. If width and height are not specified, the page
will flicker while the image loads.
The 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).
If a browser cannot find an image, it will display the alt text:
Example
<img src="wrongname.gif" alt="HTML5 Icon" style="width:128px;height:128px;">
The alt attribute is required. A web page will not validate correctly without it.
Alternatively, you can use width and height attributes. Here, the values are specified in pixels by
default:
Example
<img src="html5.gif" alt="HTML5 Icon" width="128" height="128">
Both the width, height, and style attributes are valid in the latest HTML5 standard.
We suggest you use the style attribute. It prevents styles sheets from changing the original size of
images:
Example
<!DOCTYPE html>
<html>
<head>
<style>
img {
width:100%;
}
</style>
</head>
<body>
<img src="html5.gif" alt="HTML5 Icon" style="width:128px;height:128px;">
<img src="html5.gif" alt="HTML5 Icon" width="128" height="128">
</body>
</html>
Example
<img src="http://www.w3schools.com/images/w3schools_green.jpg" alt="W3Schools.com">
Animated Images
The GIF standard allows animated images:
Example
<img src="programming.gif" alt="Computer Man" style="width:48px;height:48px;">
Note that the syntax of inserting animated images is no different from non-animated images.
Image Floating
Use the CSS float property to let the image float.
The image can float to the right or to the left of a text:
Example
<p>
<img src="smiley.gif" alt="Smiley face" style="float:right;width:42px;height:42px;">
The image will float to the right of the text.
</p>
<p>
<img src="smiley.gif" alt="Smiley face" style="float:left;width:42px;height:42px;">
Image Maps
Use the <map> tag to define an image-map. An image-map is an image with clickable areas.
The name attribute of the <map> tag is associated with the <img>'s usemap attribute and creates
a relationship between the image and the map.
The <map> tag contains a number of <area> tags, that defines the clickable areas in the imagemap:
Example
<img src="planets.gif" alt="Planets" usemap="#planetmap" style="width:145px;height:126px;">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm">
<area shape="circle" coords="90,58,3" alt="Mercury" href="mercur.htm">
<area shape="circle" coords="124,58,8" alt="Venus" href="venus.htm">
</map>
Chapter Summary
Description
HTML Tables
Previous
Next Chapter
First Name
Last Name
Points
Eve
Jackson
94
John
Doe
80
Adam
Johnson
67
Jill
Smith
50
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
Example explained:
Tables are defined with the <table> tag.
Tables are divided into table rows with the <tr> tag.
Table rows are divided into table data with the <td> tag.
A table row can also be divided into table headings with the <th> tag.
Table data <td> are the data containers of the table.
They can contain all sorts of HTML elements like text, images, lists, other tables, etc.
The border attribute is on its way out of the HTML standard! It is better to use CSS.
Remember to define borders for both the table and the table cells.
</tr>
</table>
Now you can define a special style for this table:
table#t01 {
width: 100%;
background-color: #f1f1c1;
}
And add more styles:
table#t01 tr:nth-child(even) {
background-color: #eee;
}
table#t01 tr:nth-child(odd) {
background-color: #fff;
}
table#t01 th {
color: white;
background-color: black;
}
Chapter Summary
Description
<table>
Defines a table
<th>
<tr>
<td>
<thead>
<tbody>
<tfoot>
HTML Lists
Previous
Next Chapter
Example of an unordered list and an ordered list in HTML:
Unordered List:
Item
Item
Item
Item
Ordered List:
1. First item
2. Second item
3. Third item
4. Fourth item
Description
The list items will be marked with bullets (default)
Circle:
<ul style="list-style-type:circle">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Square:
<ul style="list-style-type:square">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
None:
<ul style="list-style-type:none">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Type
Description
<li>Tea</li>
<li>Milk</li>
</ol>
Horizontal Lists
HTML lists can be styled in many different ways with CSS.
One popular way, is to style a list to be displayed horizontally:
Example
<!DOCTYPE html>
<html>
<head>
<style>
ul#menu li {
display:inline;
}
</style>
</head>
<body>
<h2>Horizontal List</h2>
<ul id="menu">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>PHP</li>
</ul>
</body>
</html>
With a little extra style, you can make it look like a menu:
Example
ul#menu {
padding: 0;
}
ul#menu li {
display: inline;
}
ul#menu li a {
background-color: black;
color: white;
padding: 10px 20px;
text-decoration: none;
border-radius: 4px 4px 0 0;
}
ul#menu li a:hover {
background-color: orange;
}
Chapter Summary
Description
Every HTML element has a default display value depending on what type of element it is. The
default display value for most elements is block or inline.
Block-level Elements
A block-level element always starts on a new line and takes up the full width available (stretches
out to the left and right as far as it can).
The <div> element is a block-level element.
<div>
<h1> - <h6>
<p>
<form>
Inline Elements
An inline element does not start on a new line and only takes up as much width as necessary.
This is an inline <span> element inside a paragraph.
Examples of inline elements:
<span>
<a>
<img>
Description