Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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 Explained
The <!DOCTYPE html> declaration defines this document to be HTML5
HTML Tags
HTML tags are element names surrounded by angle brackets:
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, Edge, 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:
Note: Only the content inside the <body> section (the white area above) is displayed in a browser.
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:
HTML Editor
Write HTML Using Notepad or TextEdit
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 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 "Display HTML files as HTML code instead of formatted
text".
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
It is the perfect tool when you want to test code fast. It also has color coding and the ability to save and share
code with others:
Example
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 RESULT:
HTML Headings
HTML headings are defined with the <h1> to <h6> tags.
<h1> defines the most important heading. <h6> defines the least important heading:
Example
HTML Paragraphs
HTML paragraphs are defined with the <p> tag:
Example
HTML Links
HTML links are defined with the <a> tag:
Example
HTML Images
HTML images are defined with the <img> tag.
The source file (src), alternative text (alt), width, and height are provided as attributes:
Example
HTML Elements
An HTML element usually consists of a start tag and an end tag, with the content inserted in between:
The HTML element is everything from the start tag to the end tag:
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
Example Explained
Inside the <body> element is two other HTML elements: <h1> and <p>.
Example
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):
Example
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.
The HTML5 standard does not require lowercase tags, but W3C recommends lowercase in HTML, and demands
lowercase for stricter document types like XHTML.
HTML Attributes
Attributes provide additional information about HTML elements.
HTML Attributes
All HTML elements can have attributes
Example
You will learn more about links and the <a> tag later in this tutorial.
Example
Example
The width and height are is specified in pixels by default; so width="500" means 500 pixels wide.
You will learn more about images in our HTML Images chapter.
The value of the alt attribute can be read by screen readers. This way, someone "listening" to the webpage, e.g. a
vision impaired person, can "hear" the element.
Example
The alt attribute is also useful if the image cannot be displayed (e.g. if it does not exist):
Example
See what happens if we try to display an image that does not exist:
Example:
The title Attribute
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
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.
BAD
GOOD
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
Using quotes are the most common. Omitting quotes can produce errors.
At W3Schools we always use quotes around attribute values.
In some situations, when the attribute value itself contains double quotes, it is necessary to use single quotes:
Or vice versa:
Chapter Summary
All HTML elements can have attributes
The width and height attributes provide size information for images
Exercise1:
Add a "tooltip" to the paragraph below with the text "About W3Schools".
Exercise3:
Make a link that goes to "https://www.google.com".
Exercise4:
Insert an image and specify an alternate text for the image.
Alternate text is useful when the image cannot be displayed, like when
the page is read by a screen reader.
HTML Headings
HTML Headings
Headings are defined with the <h1> to <h6> tags.
<h1> defines the most important heading. <h6> defines the least important heading.
Example
Note: Browsers automatically add some white space (a margin) before and after a heading.
Users often skim a page 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.
Bigger Headings
Each HTML heading has a default size. However, you can specify the size for any heading with the style attribute,
using the CSS font-size property:
Example
The <hr> element is used to separate content (or define a change) in an HTML page:
Example
Example
Note: Metadata typically define the document title, character set, styles, scripts, and other meta information.
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)
Exercise1:
Use the correct HTML tag to add a heading with the text "London".
____ ___________________ _____
<p>London is the capital city of England. It is the most populous city in the United Kingdom, with a
metropolitan area of over 13 million inhabitants.</p>
Exercise2:
Add a horizontal rule between the heading and the paragraph.
London
_____
<p>London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan
area of over 13 million inhabitants.</p>
Exercise3:
Add six headings to the document with the text "Hello".
Start with the most important heading (the largest) and end with the least important heading (the smallest).
<html>
<body>
</body>
</html>
Exercise4:
Mark up the text with appropriate tags:
Start with the most important heading (the largest) and end with the least important heading (the smallest).
__ On the Island of Isla Nublar, a new park has been built: Jurassic Park is a theme park of cloned dinosaurs!! __
HTML Paragraphs
The HTML <p> element defines a paragraph:
Example
Note: Browsers automatically add some white space (a margin) before and after a paragraph.
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 any extra spaces and extra lines when the page is displayed:
Example
Example
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.
Example
The <br> tag is an empty tag, which means that it has no end tag.
Example
The text inside a <pre> element is displayed in a fixed-width font (usually Courier), and it preserves both spaces
and line breaks:
Example
<html>
<body>
Exercise2:
Clean up this document with proper end tags.
<h1>This is a Heading
<p>This is a paragraph.
Exercise3:
Add a line break in the middle of the paragraph:
Exercise4:
Wrap this poem around HTML tags that will preserve all spaces and line breaks when the element is displayed.