HTML5 Part1
HTML5 Part1
Print Page
HTML(5) Tutorial
« W3Schools Home (/[Link]) Next Chapter » (html_intro.asp)
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>
HTML Examples
At the end of the HTML tutorial, you can find more than 200 examples.
[Link] 1/3
9/2/2015 HTML Tutorial
With our online editor, you can edit and test each example yourself.
HTML References
At W3Schools you will find complete references about tags, attributes, events, color names, entities,
charactersets, URL encoding, language codes, HTTP messages, and more.
W3Schools' Online
Certification
The perfect solution for professionals who need to balance
work, family, and career building.
The JavaScript Certificate (/cert/[Link]) documents your knowledge of JavaScript and HTML
DOM.
The PHP Certificate (/cert/[Link]) documents your knowledge of PHP and SQL (MySQL).
The XML Certificate (/cert/[Link]) documents your knowledge of XML, XML DOM and XSLT.
[Link] 3/3
9/2/2015 Introduction to HTML
Print Page
HTML Introduction
« Previous ([Link]) Next Chapter » (html_editors.asp)
What is HTML?
HTML is a markup language for describing web documents (web pages).
HTML Example
A small HTML document:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
</body>
</html>
Example Explained
The DOCTYPE declaration defines the document type to be HTML
The text between <html> and </html> describes an HTML document
The text between <head> and </head> provides information about the document
The text between <title> and </title> provides a title for the document
The text between <body> and </body> describes the visible page content
The text between <h1> and </h1> describes a heading
The text between <p> and </p> describes a paragraph
[Link] 1/4
9/2/2015 Introduction to HTML
Using this description, a web browser can display a document with a heading and a paragraph.
HTML Tags
HTML tags are keywords (tag names) surrounded by angle brackets:
<tagname>content</tagname>
The start tag is often called the opening tag. The end tag is often called 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:
[Link] 2/4
9/2/2015 Introduction to HTML
<html>
<head>
<title>Page title</title>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Only the <body> area (the white area) is displayed by the browser.
To display a document correctly, the browser must know both type and version.
The doctype declaration is not case sensitive. All cases are acceptable:
<!DOCTYPE html>
<!DOCTYPE HTML>
<!doctype html>
<!Doctype Html>
Common Declarations
[Link] 3/4
9/2/2015 Introduction to HTML
HTML5
<!DOCTYPE html>
HTML 4.01
<!DOCTYPE HTML PUBLIC "‐//W3C//DTD HTML 4.01 Transitional//EN"
"[Link]
XHTML 1.0
<!DOCTYPE html PUBLIC "‐//W3C//DTD XHTML 1.0 Transitional//EN"
"[Link]
HTML Versions
Since the early days of the web, there have been many versions of HTML:
Version Year
HTML 1991
XHTML 2000
HTML5 2014
[Link] 4/4
9/2/2015 HTML Editors
Print Page
HTML Editors
« Previous (html_intro.asp) Next Chapter » (html_basic.asp)
Microsoft WebMatrix
Sublime Text
However, for learning HTML we recommend a text editor like Notepad (PC) or TextEdit (Mac).
Follow the 4 steps below to create your first web page with Notepad.
Click Start (bottom left on your screen). Click All Programs. Click Accessories. Click Notepad.
Open the Start Screen (the window symbol at the bottom left on your screen). Type Notepad.
<!DOCTYPE html>
<html>
<body>
</body>
</html>
[Link] 1/3
9/2/2015 HTML Editors
Name the file "[Link]" or any other name ending with html or htm.
You can use either .htm or .html as file extension. There is no difference, it is up to
you.
[Link] 2/3
9/2/2015 HTML Editors
To open a file in a browser, double click on the file, or rightclick, and choose open
with.
[Link] 3/3
9/2/2015 HTML Basic
Print Page
Don't worry if these examples use tags you have not learned.
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>
</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>
[Link] 1/3
9/2/2015 HTML Basic
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="[Link] 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="[Link]" alt="[Link]" width="104" height="142">
[Link] 2/3
9/2/2015 HTML Basic
[Link] 3/3
9/2/2015 HTML Elements
Print Page
HTML Elements
« Previous (html_basic.asp) Next Chapter » (html_attributes.asp)
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:
<br>
Example
<!DOCTYPE html>
<html>
<body>
[Link] 1/4
9/2/2015 HTML Elements
</body>
</html>
<html>
<body>
</body>
</html>
The element content is two other HTML elements (<h1> and <p>).
<body>
</body>
[Link] 2/4
9/2/2015 HTML Elements
Example
<html>
<body>
<p>This is a paragraph
<p>This is a paragraph
</body>
</html>
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 you need
to make your document readable by XML parsers, you should close all HTML elements.
The HTML5 standard does not require lowercase tags, but W3C recommends lowercase in HTML4,
and demands lowercase for stricter document types like XHTML.
[Link] 3/4
9/2/2015 HTML Elements
[Link] 4/4
9/2/2015 HTML Attributes
Print Page
HTML Attributes
« Previous (html_elements.asp) Next Chapter » (html_headings.asp)
HTML Attributes
HTML elements can have attributes
Attributes provide additional information about an element
Attributes are always specified in the start tag
Attributes come in name/value pairs like: name="value"
Declaring a language is important for accessibility applications (screen readers) and search engines:
<!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).
In this example, the <p> element has a title attribute. The value of the attribute is "About
W3Schools":
Example
[Link] 1/5
9/2/2015 HTML Attributes
When you move the mouse over the element, the title will be displayed as a tooltip.
Example
<a href="[Link] is a link</a>
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="[Link]" 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.
The alt attribute specifies an alternative text to be used, when an HTML element cannot be
displayed.
The value of the attribute can be read by "screen readers". This way, someone "listening" to the
webpage, i.e. a blind person, can "hear" the element.
Example
<img src="[Link]" alt="[Link]" width="104" height="142">
The title attribute can be written with upper or lower case like Title and/or TITLE.
W3C recommends lowercase in HTML4, and demands lowercase for stricter document types like
XHTML.
Example
<a href=[Link]
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.
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 HTML title attribute provides additional "tooltip" information
The HTML href attribute provides address information for links
The HTML width and height attributes provide size information for images
The HTML alt attribute provides text for screen readers
At W3Schools we always use lowercase HTML attribute names
At W3Schools we always quote attributes with double quotes
Exercise 2 » ([Link]?filename=exercise_attributes2)
Exercise 3 » ([Link]?filename=exercise_attributes3)
Exercise 4 » ([Link]?filename=exercise_attributes4)
Exercise 5 » ([Link]?filename=exercise_attributes5)
[Link] 4/5
9/2/2015 HTML Attributes
HTML Attributes
Below is an alphabetical list of some attributes often used in HTML:
Attribute Description
A complete list of all attributes for each HTML element, is listed in our: HTML Tag Reference
(/tags/[Link]).
[Link] 5/5
9/2/2015 Exercise v1.3
Exercise:
Add a tooltip to the paragraph below with the text "About W3Schools".
Hint
<!DOCTYPE html>
<html> W3Schools is a web developer's site.
<body>
</body>
</html>
Exercise © [Link]
[Link] 1/1
9/2/2015 Exercise v1.3
Exercise:
Change the size of the image to 250 pixels wide and 400 pixels tall.
Hint
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Exercise © [Link]
[Link] 1/1
9/2/2015 Exercise v1.3
Exercise:
Transform the text below into a link that goes to "[Link]".
Hint
This is a link
</body>
</html>
Exercise © [Link]
[Link] 1/1
9/2/2015 Exercise v1.3
Exercise:
Change the destination of the link below to "[Link]".
Hint
<a href="[Link] is
a link</a>
</body>
</html>
Exercise © [Link]
[Link] 1/1
9/2/2015 Exercise v1.3
Exercise:
The image below is unavailable on purpose. Specify an alternate text of "[Link]" to
be used,
so it can be read by "screen readers".
Hint
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Exercise © [Link]
[Link] 1/1
9/2/2015 HTML Headings
Print Page
HTML Headings
« Previous (html_attributes.asp) Next Chapter » (html_paragraphs.asp)
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.
Search engines use your 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 main headings, followed by h2 headings, then the less important h3, and so
on.
Example
[Link] 1/4
9/2/2015 HTML Headings
<p>This is a paragraph.</p>
<hr>
<p>This is a paragraph.</p>
<hr>
<p>This is a paragraph.</p>
The HTML <head> element contains meta data. Meta data are not displayed.
The HTML <head> element is placed between the <html> tag and the <body> tag:
Example
<!DOCTYPE html>
<html>
<head>
<title>My First HTML</title>
<meta charset="UTF‐8">
</head>
<body>
.
.
.
Meta data means data about data. HTML meta data is data about the HTML
document.
The title will not be displayed in the document, but might be displayed in the browser tab.
[Link] 2/4
9/2/2015 HTML Headings
It can be used to define the character set, and other information about the HTML document.
The HTML <style> element is used to define internal CSS style sheets.
The HTML <link> element is used to define external CSS style sheets.
To find out, rightclick 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.
Exercise 2 » ([Link]?filename=exercise_headings2)
Exercise 3 » ([Link]?filename=exercise_headings3)
Exercise 4 » ([Link]?filename=exercise_headings4)
You will learn more about HTML tags and attributes in the next chapters of this tutorial.
Tag Description
[Link] 3/4
9/2/2015 HTML Headings
[Link] 4/4
9/2/2015 Exercise v1.3
Exercise:
Add a horizontal rule between the heading and the paragraph.
Hint
<!DOCTYPE html>
<html>
<body> London
<h1>London</h1>
London is the capital city of England. It is the
<p>London is the capital city of England. most populous city in the United Kingdom, with
It is the most populous city in the United a metropolitan area of over 13 million
Kingdom, with a metropolitan area of over inhabitants.
13 million inhabitants.</p>
</body>
</html>
Exercise © [Link]
[Link] 1/1
9/2/2015 Exercise v1.3
Exercise:
Add six headings to the document with the text "Hello".
Start with the most important heading and end with the least important heading.
Hint
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Exercise © [Link]
[Link] 1/1
9/2/2015 Exercise v1.3
Exercise:
Mark up the following text with appropriate tags:
"Universal Studios" is the most important content.
"Jurassic Park" is the next most important content.
"About" is of lesser importance than Jurassic Park.
The last sentence is just a paragraph.
Hint
Jurassic Park
About
</body>
</html>
Exercise © [Link]
[Link] 1/1
9/2/2015 HTML Paragraphs
Print Page
HTML Paragraphs
« Previous (html_headings.asp) Next Chapter » (html_styles.asp)
HTML Paragraphs
The HTML <p> element defines a paragraph.
Example
<p>This is a paragraph</p>
<p>This is another paragraph</p>
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>
[Link] 1/4
9/2/2015 HTML Paragraphs
This paragraph
contains a lot of spaces
in the source code,
but the browser
ignores it.
</p>
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.
Stricter versions of HTML, like XHTML, do not allow you to skip the end tag.
Use <br> if you want a line break (a new line) without starting a new paragraph:
Example
<p>This is<br>a para<br>graph with line breaks</p>
Example
<p>This poem will display as one line:</p>
<p>
My Bonnie lies over the ocean.
The text inside a <pre> element is displayed in a fixedwidth font (usually Courier), and it preserves
both spaces and line breaks:
Example
<pre>
My Bonnie lies over the ocean.
Exercise 2 » ([Link]?filename=exercise_paragraphs1)
Exercise 3 » ([Link]?filename=exercise_paragraphs2)
Exercise 4 » ([Link]?filename=exercise_paragraphs3)
[Link] 3/4
9/2/2015 HTML Paragraphs
Tag Description
[Link] 4/4
9/2/2015 Exercise v1.3
Exercise:
Add a paragraph to this document with the text "Hello World!".
Hint
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Exercise © [Link]
[Link] 1/1
9/2/2015 Exercise v1.3
Exercise:
Fix the display of the poem below. Display the poem over 4 lines.
Hint
<!DOCTYPE html>
<html> My Bonnie lies over the ocean. My Bonnie lies
<body> over the sea. My Bonnie lies over the ocean. Oh,
bring back my Bonnie to me.
<p>
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.
</p>
</body>
</html>
Exercise © [Link]
[Link] 1/1
Print Page
HTML Styles
« Previous (html_paragraphs.asp) Next Chapter » (html_formatting.asp)
I am Red
I am Blue
Try it Yourself » ([Link]?filename=tryhtml_styles_intro)
HTML Styling
Every HTML element has a default style (background color is white and text color is black).
Changing the default style of an HTML element, can be done with the style attribute.
This example changes the default background color from white to lightgrey:
Example
<body style="background‐color:lightgrey">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
The bgcolor attribute, supported in older versions of HTML, is not valid in HTML5.
Example
<h1 style="color:blue">This is a heading</h1>
<p style="color:red">This is a paragraph.</p>
HTML Fonts
The fontfamily 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>
The <font> tag, supported in older versions of HTML, is not valid in HTML5.
Example
<h1 style="font‐size:300%">This is a heading</h1>
<p style="font‐size:160%">This is a paragraph.</p>
Try it Yourself » ([Link]?filename=tryhtml_styles_fontsize)
Example
<h1 style="text‐align:center">Centered Heading</h1>
<p>This is a paragraph.</p>
The <center> tag, supported in older versions of HTML, is not valid in HTML5.
Chapter Summary
Use the style attribute for styling HTML elements
Use backgroundcolor for background color
Use color for text colors
Use fontfamily for text fonts
Use fontsize for text sizes
Use textalign for text alignment
Exercise 2 » ([Link]?filename=exercise_styles2)
Exercise 3 » ([Link]?filename=exercise_styles3)
Exercise 4 » ([Link]?filename=exercise_styles4)
Exercise 5 » ([Link]?filename=exercise_styles5)
Exercise 6 » ([Link]?filename=exercise_styles6)
Hint
<!DOCTYPE html>
<html> This is a paragraph.
<body>
</body>
</html>
Exercise © [Link]
Exercise:
Change the font of the paragraph to "courier".
Hint
<!DOCTYPE html>
<html> This is a paragraph.
<body>
<p>This is a paragraph.</p>
</body>
</html>
Exercise © [Link]
Exercise:
Center align the paragraph.
Hint
<!DOCTYPE html>
<html> This is a paragraph.
<body>
<p>This is a paragraph.</p>
</body>
</html>
Exercise © [Link]
Exercise:
Change the text size of the paragraph to 200%.
Hint
<!DOCTYPE html>
<html>
<body>
This is a paragraph.
<p style="font‐size:200%">This is a
paragraph.</p>
</body>
</html>
Exercise © [Link]
Exercise:
Change the background color of the page below to yellow.
Hint
<!DOCTYPE html>
<html>
<body> This is a heading
<h1>This is a heading</h1>
This is a paragraph.
<p>This is a paragraph.</p>
</body>
</html>
Exercise © [Link]
Exercise:
Center align all content on the page.
Hint
<!DOCTYPE html>
<html>
<body> This is a heading
<h1>This is a heading</h1>
This is also a heading
<h2>This is also a heading</h2>
This is a paragraph.
<p>This is a paragraph.</p>
This is also paragraph.
<p>This is also paragraph.</p>
</body>
</html>
Exercise © [Link]
Print Page
Text Formatting
This text is bold
This text is italic
This is superscript
HTML also defines special elements, for defining text with a special meaning.
HTML uses elements like <b> and <i> for formatting output, like bold or italic text.
Bold text
Important text
Italic text
Emphasized text
Marked text
Small text
Deleted text
Inserted text
Subscripts
Superscripts
Example
<p>This text is normal.</p>
The HTML <strong> element defines strong text, with added semantic "strong" importance.
Example
<p>This text is normal.</p>
Example
<p>This text is normal.</p>
The HTML <em> element defines emphasized text, with added semantic importance.
Example
<p>This text is normal.</p>
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
<h2>HTML <mark>Marked</mark> Formatting</h2>
Example
<p>My favorite color is <del>blue</del> red.</p>
Example
<p>My favorite <ins>color</ins> is red.</p>
Example
<p>This is <sub>subscripted</sub> text.</p>
Example
<p>This is <sup>superscripted</sup> text.</p>
Exercise 2 » ([Link]?filename=exercise_formatting2)
Exercise 3 » ([Link]?filename=exercise_formatting3)
Exercise 4 » ([Link]?filename=exercise_formatting4)
Exercise 5 » ([Link]?filename=exercise_formatting5)
Hint
<!DOCTYPE html>
<html>
<body> What Does WWF Do?
<h1>What Does WWF Do?</h1>
WWF's mission is to stop the degradation of our
<p>WWF's mission is to stop the planet's natural environment.
degradation of our planet's natural
environment.</p>
</body>
</html>
Exercise © [Link]
Exercise:
Emphasize the word "metropolitan" in the text below.
Hint
<!DOCTYPE html>
<html>
<body> Tokyo
<h1>Tokyo</h1>
Tokyo is the capital of Japan, the center of the
<p>Tokyo is the capital of Japan, the Greater Tokyo Area, and the most populous
center of the Greater Tokyo Area, and the metropolitan area in the world.
most populous metropolitan area in the
world.</p>
</body>
</html>
Exercise © [Link]
Exercise:
Highlight the word "FUN!" in the text below.
Hint
<!DOCTYPE html>
<html> HTML is FUN to learn!
<body>
</body>
</html>
Exercise © [Link]
Hiring 50 Java Architects
Earn $100k USD & Work From Home! Apply now through Crossover.
Exercise:
Apply subscript formatting to the number "2" in the text below.
Hint
<!DOCTYPE html>
<html> H2O is the scientific term for water.
<body>
</body>
</html>
Exercise © [Link]
Senior Frontend Developer
Earn $60k USD & Work From Home! Apply now through Crossover.
Exercise:
Add a line through (strikeout) the letters "blue" in the text below.
Hint
<!DOCTYPE html>
<html> My favorite color is blue red.
<body>
</body>
</html>
Exercise © [Link]
Print Page
Quotation
Example
<p>WWF's goal is to: <q>Build a future where people live in harmony with
nature.</q></p>
Example
<p>Here is a quote from WWF's website:</p>
<blockquote cite="[Link]
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.
</blockquote>
Try it Yourself » ([Link]?filename=tryhtml_formatting_blockquote)
Marking abbreviations can give useful information to browsers, translation systems and search
engines.
Example
<p>The <abbr title="World Health Organization">WHO</abbr> was founded in
1948.</p>
The <address> element is usually displayed in italic. Most browsers will add a line break before and
after the element.
Example
<address>
Written by Jon Doe.<br>
Visit us at:<br>
[Link]<br>
Box 564, Disneyland<br>
USA
</address>
Example
<p><cite>The Scream</cite> by Edward Munch. Painted in 1893.</p>
Example
<bdo dir="rtl">This text will be written from right to left</bdo>
Exercise 2 » ([Link]?filename=exercise_quotations2)
Exercise 3 » ([Link]?filename=exercise_quotations3)
Exercise 4 » ([Link]?filename=exercise_quotations4)
Hint
<!DOCTYPE html>
<html> I am so cool.
<body>
<p>I am so cool.</p>
</body>
</html>
Exercise © [Link]
Exercise:
The text below should be a quoted section.
Add the proper HTML element to it, and specify that it is quoted from the following URL:
[Link]
Hint
</body>
</html>
Exercise © [Link]
Exercise:
Make the text below go righttoleft.
Hint
</body>
</html>
Exercise © [Link]
Exercise:
The letters "WHO" in the text below is an abbreviation of "World Health Organization".
Use an HTML element to provide the specified abbreviation of "WHO".
Hint
<!DOCTYPE html>
<html> The WHO was founded in 1948.
<body>
</body>
</html>
Exercise © [Link]
Print Page
Computer Code
var person = {
firstName:"John",
lastName:"Doe",
age:50,
eyeColor:"blue"
}
The <kbd>, <samp>, and <code> elements all support fixed letter size and spacing.
Example
<p>To open a file, select:</p>
<p><kbd>File | Open...</kbd></p>
Example
<samp>
[Link] login: Apr 12 09:10:17
Linux 2.6.10‐grsec+gg3+e+fhs6b+nfs+gr0501+++p3+c4a+gr2b‐reslog‐v6.189
</samp>
Example
<code>
var person = { firstName:"John", lastName:"Doe", age:50, eyeColor:"blue" }
</code>
The <code> element does not preserve extra whitespace and linebreaks:
Example
<p>Coding Example:</p>
<code>
var person = {
firstName:"John",
lastName:"Doe",
age:50,
eyeColor:"blue"
}
</code>
Example
<p>Coding Example:</p>
<code>
<pre>
var person = {
firstName:"John",
lastName:"Doe",
age:50,
eyeColor:"blue"
}
</pre>
</code>
Example
<p>Einstein wrote:</p>
<p><var>E = m c<sup>2</sup></var></p>
Exercise 2 » ([Link]?filename=exercise_computercode_elements2)
Exercise 3 » ([Link]?filename=exercise_computercode_elements3)
« Previous (html_quotation_elements.asp)
Next Chapter » (html_comments.asp)
HTML Comments
« Previous (html_computercode_elements.asp)
Next Chapter » (html_css.asp)
Comment tags <! and > are used to insert comments in HTML.
Note: There is an exclamation point (!) in the opening tag, but not in the closing tag.
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">
‐‐>
<!‐‐[if IE 8]>
.... some HTML here ....
<![endif]‐‐>
For example <!webbot bot> tags wrapped inside HTML comments by FrontPage and Expression
Web.
As a rule, let these tags stay, to help support the software that created them.
Exercise 2 » ([Link]?filename=exercise_comments2)
« Previous (html_computercode_elements.asp)
Next Chapter » (html_css.asp)