HTML Tutorial: Examples in Each Chapter
HTML Tutorial: Examples in Each Chapter
HTML Tutorial: Examples in Each Chapter
W3Schools Home
Next Chapter
Example
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
Try it yourself
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Result
My First Heading
My first paragraph.
HTML Introduction
Previous
Next Chapter
Example
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
Try it yourself
Example Explained
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 (tag names) 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
The end tag is written like the start tag, with a forward slash before the tag name
Start and end tags are also called opening tags and closing tags
<tagname>content</tagname>
HTML Elements
"HTML tags" and "HTML elements" are often used to describe the same thing.
But strictly speaking, an HTML element is everything between the start tag and the end tag,
including the tags:
HTML Element:
<p>This is a paragraph.</p>
Web Browsers
The purpose of a web browser (Chrome, Internet Explorer, 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:
Don't worry if the examples use tags you have not learned.
You will learn about them in the next chapters.
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>
<!DOCTYPE html>
<html>
<body>
</body>
</html>
result
This is heading 1
This is heading 2
This is heading 3
This is heading 4
This is heading 5
This is heading 6
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
<!DOCTYPE html>
<html>
<body>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
result
This is a paragraph.
This is a paragraph.
This is a paragraph.
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
<!DOCTYPE html>
<html>
<body>
<a href="http://www.w3schools.com">
This is a link</a>
</body>
</html>
result
this is a link
HTML Images
HTML images are defined with the <img> tag.
Example
<img src="w3schools.jpg" width="104" height="142" />
Try it yourself
<!DOCTYPE html>
<html>
<body>
</body>
</html>
result
Note: The name and the size of the image are provided as attributes.
HTML Elements
Previous
Next Chapter
HTML Elements
An HTML element is everything from the start tag to the end tag:
Start tag *
Element content
<p>
This is a paragraph
<a href="default.htm"> This is a link
<br />
End tag *
</p>
</a>
* 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 Attributes
Previous
Next Chapter
HTML Attributes
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
!DOCTYPE html>
<html>
<body>
<a href="http://www.w3schools.com">
This is a link</a>
</body>
</html>
result
This is a link
Attribute
class
id
style
Value
classname
id
style_definition
title
tooltip_text
Description
Specifies a classname for an element
Specifies a unique id for an element
Specifies an inline style for an element
Specifies extra information about an element (displayed
as a tool tip)
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>
<!DOCTYPE html>
<html>
<body>
</body>
</html>
result
This is heading 1
This is heading 2
This is heading 3
This is heading 4
This is heading 5
This is heading 6
Note: Browsers automatically add some empty space (a margin) before and after each heading.
HTML Lines
The <hr /> tag creates a horizontal line in an HTML page.
The hr element can be used to separate content:
Example
<p>This is a paragraph</p>
<hr />
<p>This is a paragraph</p>
<hr />
<p>This is a paragraph</p>
<!DOCTYPE html>
<html>
<body>
<p>The hr tag defines a horizontal rule:</p>
<hr />
<p>This is a paragraph</p>
<hr />
<p>This is a paragraph</p>
<hr />
<p>This is a paragraph</p>
</body>
This is a paragraph
This is a paragraph
This is a paragraph
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 -->
<!DOCTYPE html>
<html>
<body>
</body>
</html>
result
This is a regular paragraph
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
<!DOCTYPE html>
<html>
<body>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
result
This is a paragraph.
This is a paragraph.
This is a paragraph.
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
<!DOCTYPE html>
<html>
<body>
<p>This is a paragraph.
<p>This is a paragraph.
<p>This is a paragraph.
</body>
</html>
This is a paragraph.
This is a paragraph.
This is a paragraph.
Don't forget to close your HTML tags!
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
<!DOCTYPE html>
<html>
<body>
</body>
</html>
result
This is
a para
graph with line breaks
<p>
My Bonnie lies over the ocean.
</body>
</html>
My Bonnie lies over the ocean. My Bonnie lies over the sea. My Bonnie lies over the ocean. Oh,
bring back my Bonnie to me.
Note that your browser ignores the layout!