HTML5 Tutorial
HTML5 Tutorial
❮ HomeNext ❯
With our online HTML editor, you can edit the HTML, and click on a button to view the result.
Example
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Try it Yourself »
HTML Examples
At the end of the HTML tutorial, you can find more than 200 examples.
With our online editor, you can edit and test each example yourself.
Go to HTML Examples!
HTML References
At W3Schools you will find complete references about tags, attributes, events, color names, entities,
character-sets, URL encoding, language codes, HTTP messages, and more.
The perfect solution for professionals who need to balance work, family, and career building.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
❮ PreviousNext ❯
What is HTML?
HTML tags label pieces of content such as "heading", "paragraph", "table", and so on
Browsers do not display the HTML tags, but use them to render the content of the page
Example
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
</html>
Try it Yourself »
Example Explained
HTML Tags
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, but with a forward slash inserted before the tag name
Tip: The start tag is also called the opening tag, and the end tag the closing tag.
Web Browsers
The purpose of a web browser (Chrome, IE, Firefox, Safari) is to read HTML documents and display them.
The browser does not display the HTML tags, but uses them to determine how to display the document:
HTML Page Structure
<html>
<head>
<title>Page title</title>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Note: Only the content inside the <body> section (the white area above) is displayed in a browser.
The <!DOCTYPE> declaration represents the document type, and helps browsers to display web pages
correctly.
It must only appear once, at the top of the page (before any HTML tags).
<!DOCTYPE html>
HTML Versions
Since the early days of the web, there have been many versions of HTML:
Version Year
HTML 1991
XHTML 2000
HTML5 2014
HTML Editors
❮ PreviousNext ❯
Web pages can be created and modified by using professional HTML editors.
However, for learning HTML we recommend a simple text editor like Notepad (PC) or TextEdit (Mac).
Follow the four steps below to create your first web page with Notepad or TextEdit.
Windows 8 or later:
Open the Start Screen (the window symbol at the bottom left on your screen). Type Notepad.
Windows 7 or earlier:
Also change some preferences to get the application to save files correctly. In Preferences > Format >
choose "Plain Text"
Then under "Open and Save", check the box that says "Ignore rich text commands in HTML files".
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Save the file on your computer. Select File > Save as in the Notepad menu.
Name the file "index.htm" and set the encoding to UTF-8 (which is the preferred encoding for HTML
files).
You can use either .htm or .html as file extension. There is no difference, it is up to you.
Open the saved HTML file in your favorite browser (double click on the file, or right-click - and choose
"Open with").
❮ PreviousNext ❯
Don't worry if these examples use tags you have not learned.
HTML Documents
All HTML documents must start with a document 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>
</html>
Try it Yourself »
HTML Headings
<h1> defines the most important heading. <h6> defines the least important heading:
Example
Try it Yourself »
HTML Paragraphs
Example
<p>This is a paragraph.</p>
Try it Yourself »
HTML Links
Example
<a href="https://www.w3schools.com">This is a link</a>
Try it Yourself »
HTML Images
The source file (src), alternative text (alt), width, and height are provided as attributes:
Example
❮ PreviousNext ❯
HTML Elements
An HTML element usually consists of a start tag and end tag, with the content inserted in between:
The HTML element is everything from the start tag to the end tag:
<br>
HTML elements with no content are called empty elements. Empty elements do not have an end tag,
such as the <br> element (which indicates a line break).
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Try it Yourself »
Example Explained
<html>
<body>
<h1>My First Heading</h1>
</body>
</html>
The element content is two other HTML elements (<h1> and <p>).
<body>
</body>
Some HTML elements will display correctly, even if you forget the end tag:
Example
<html>
<body>
<p>This is a paragraph
<p>This is a paragraph
</body>
</html>
Try it Yourself »
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.
<br> is an empty element without a closing tag (the <br> tag defines a line break).
Empty elements can be "closed" in the opening tag like this: <br />.
HTML5 does not require empty elements to be closed. But if you want stricter validation, or if you need
to make your document readable by XML parsers, you must close all HTML elements properly.
HTML tags are not case sensitive: <P> means the same as <p>.
The HTML5 standard does not require lowercase tags, but W3C recommends lowercase in HTML, and
demands lowercase for stricter document types like XHTML.
❮ PreviousNext ❯
HTML Attributes
<!DOCTYPE html>
<html lang="en-US">
<body>
...
</body>
</html>
The first two letters specify the language (en). If there is a dialect, use two more letters (US).
Here, a title attribute is added to the <p> element. The value of the title attribute will be displayed as a
tooltip when you mouse over the paragraph:
Example
This is a paragraph.
</p>
Try it Yourself »
HTML links are defined with the <a> tag. The link address is specified in the href attribute:
Example
You will learn more about links and the <a> tag later in this tutorial.
Size Attributes
The filename of the source (src), and the size of the image (width and height) are all provided as
attributes:
Example
Try it Yourself »
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.
The alt attribute specifies an alternative text to be used, when an image cannot be displayed.
The value of the attribute can be read by screen readers. This way, someone "listening" to the webpage,
e.g. a blind person, can "hear" the element.
Example
Try it Yourself »
The title attribute can be written with uppercase or lowercase like title or TITLE.
W3C recommends lowercase in HTML, and demands lowercase for stricter document types like XHTML.
The HTML5 standard does not require quotes around attribute values.
Example
<a href=https://www.w3schools.com>
Try it Yourself »
W3C recommends quotes in HTML, and demands quotes for stricter document types like XHTML.
Sometimes it is necessary to use quotes. This example will not display the title attribute correctly,
because it contains a space:
Example
Try it Yourself »
Using quotes are the most common. Omitting quotes can produce errors.
Double quotes around attribute values are the most common in HTML, but single quotes can also be
used.
In some situations, when the attribute value itself contains double quotes, it is necessary to use single
quotes:
Or vice versa:
Chapter Summary
The width and height attributes provide size information for images
HTML Attributes
alt Specifies an alternative text for an image, when the image cannot be d
HTML Headings
❮ PreviousNext ❯
HTML Headings
<h1> defines the most important heading. <h6> defines the least important heading.
Example
Try it Yourself »
Note: Browsers automatically add some white space (a margin) before and after a heading.
Search engines use the headings to index the structure and content of your web pages.
Users skim your pages by its headings. It is important to use headings to show the document structure.
<h1> headings should be used for main headings, followed by <h2> headings, then the less important
<h3>, and so on.
Note: Use HTML headings for headings only. Don't use headings to make text BIG or bold.
The <hr> tag defines a thematic break in an HTML page, and is most often displayed as a horizontal rule.
The <hr> element is used to separate content (or define a change) in an HTML page:
Example
<hr>
<h2>This is heading 2</h2>
<hr>
Try it Yourself »
The <head> element is a container for metadata. HTML metadata is data about the HTML document.
Metadata is not displayed.
The <head> element is placed between the <html> tag and the <body> tag:
Example
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
Try it Yourself »
Note: Metadata typically define the document title, character set, styles, links, scripts, and other meta
information.
Have you ever seen a Web page and wondered "Hey! How did they do that?"
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.
W3Schools' tag reference contains additional information about these tags and their attributes.
You will learn more about HTML tags and attributes in the next chapters of this tutorial.
Tag Description
<head> A container for all the head elements (title, scripts, styles, meta information, and more)
❮ PreviousNext ❯
HTML Paragraphs
Example
<p>This is a paragraph.</p>
Try it Yourself »
Note: Browsers automatically add some white space (a margin) before and after a paragraph.
HTML Display
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 any extra spaces and extra lines when the page is displayed:
Example
<p>
This paragraph
ignores it.
</p>
<p>
This paragraph
ignores it.
</p>
Try it Yourself »
Most browsers will display HTML correctly even if you forget the end tag:
Example
<p>This is a paragraph.
Try it Yourself »
The example above will work in most browsers, but do not rely on it.
Note: Dropping the end tag can produce unexpected results or errors.
Use <br> if you want a line break (a new line) without starting a new paragraph:
Example
Try it Yourself »
The <br> tag is an empty tag, which means that it has no end tag.
<p>
</p>
Try it Yourself »
The text inside a <pre> element is displayed in a fixed-width font (usually Courier), and it preserves both
spaces and line breaks:
Example
<pre>
Try it Yourself »
W3Schools' tag reference contains additional information about HTML elements and their attributes.
Tag Description