CCCC C: CCCCCCCCCCCCCC CCCCCCCCCCCCCCCC CCC
CCCC C: CCCCCCCCCCCCCC CCCCCCCCCCCCCCCC CCC
CCCC C: CCCCCCCCCCCCCC CCCCCCCCCCCCCCCC CCC
HTML stands for Hyper Text Markup Language HTML is not a programming language, it is a markup language A markup language is a set of markup tags HTML uses markup tags to describe web pages
HTML Tags
HTML markup tags are usually called HTML tags
y y y y
HTML tags are keywords 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 Start and end tags are also called opening tags and closing tags
HTML documents describe web pages HTML documents contain HTML tags and plain text HTML documents are also called web pages
The purpose of a web browser (like Internet Explorer or 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:
NOTEPAD
<html> <body> <h1>My First Heading</h1>
Example Explained
y y y y
The text between <html> and </html> describes the web page The text between <body> and </body> is the visible page content The text between <h1> and </h1> is displayed as a heading The text between <p> and </p> is displayed as a paragraph
You don't need an HTML editor You don't need a web server You don't need a web site
Editing HTML
HTML can be written and edited using many different editors like Dreamweaver and Visual Studio. However, in this tutorial we use a plain text editor (like Notepad) to edit HTML. We believe using a plain text editor is the best way to learn HTML.
page2.htm After you have copied the files, you can double-click on the file called "mainpage.htm" and see your first web site in action.
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> Try it yourself
HTML Paragraphs
HTML paragraphs are defined with the <p> tag.
Example
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 Note: The link address is specified in the href attribute. (You will learn about attributes in a later chapter of this tutorial).
HTML Images
HTML images are defined with the <img> tag.
Example
<img src="w3schools.jpg" width="104" height="142" /> Try it yourself Note: The name and the size of the image are provided as attributes.
HTML Elements
An HTML element is everything from the start tag to the end tag:
Element content <p> This is a paragraph <a href="default.htm" > This is a link
Start tag *
<br />
* The start tag is often called the opening tag. The end tag is often called the closing tag.
An HTML element starts with a start tag / opening tag An HTML element ends with an end tag / closing tag The element content is everything between the start and the end tag Some HTML elements have empty content Empty elements are closed in the start tag Most HTML elements can have attributes
Tip: You will learn about attributes in the next chapter of this tutorial.
<p>This is my first paragraph.</p> The <p> element defines a paragraph in the HTML document. The element has a start tag <p> and an end tag </p>. The element content is: This is my first paragraph. The <body> element: <body> <p>This is my first paragraph.</p> </body> The <body> element defines the body of the HTML document. The element has a start tag <body> and an end tag </body>. The element content is another HTML element (a p element). The <html> element: <html> <body> <p>This is my first paragraph.</p> </body> </html> The <html> element defines the whole HTML document. The element has a start tag <html> and an end tag </html>. The element content is another HTML element (the body element).
HTML Attributes
y y y y
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"
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
Attribute values should always be enclosed in quotes. Double style quotes are the most common, but single style quotes are also allowed. Tip: In some rare situations, when the attribute value itself contains quotes, it is necessary to use single quotes: name='John "ShotGun" Nelson'
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> Try it yourself 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> Try it yourself
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 -->
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 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 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 The <br /> element is an empty HTML element. It has no end tag.
More Examples
More paragraphs The default behaviors of paragraphs.
Text Formatting
How to handle long and short quotations. Deleted and inserted text How to mark deleted and inserted text.
Example
<p> <font size="5" face="arial" color="red"> This paragraph is in Arial, size 5, and in red text color. </font> </p> <p> <font size="3" face="verdana" color="blue"> This paragraph is in Verdana, size 3, and in blue text color. </font> </p> Try it yourself
This text is in Verdana and red This text is in Times and blue
in Cascading Style Sheet files (CSS files) in the <style> element in the HTML head section in the style attribute in single HTML elements
Example
<html> <body style="background-color:yellow;"> <h2 style="background-color:red;">This is a heading</h2> <p style="background-color:green;">This is a paragraph.</p> </body> </html>
Try it yourself
The background-color property makes the "old" bgcolor attribute obsolete. Try it yourself: Background color the old way
Example
<html> <body> <h1 style="font-family:verdana;">A heading</h1> <p style="font-family:arial;color:red;font-size:20px;">A paragraph.</p> </body> </html>
Try it yourself
The font-family, color, and font-size properties make the old <font> tag obsolete.
Example
<html> <body> <h1 style="text-align:center;">Center-aligned heading</h1> <p>This is a paragraph.</p> </body> </html>
Try it yourself
The text-align property makes the old <center> tag obsolete. Try it yourself: Centered heading the old way
<font> and <basefont> Deprecated. Defines HTML fonts <s> and <strike> <u> Deprecated. Defines strikethrough text Deprecated. Defines underlined text
Description Deprecated. Defines the alignment of text Deprecated. Defines the background color Deprecated. Defines the text color
HTML Links
Previous Next Chapter
Links are found in nearly all Web pages. Links allow users to click their way from page to page.
Example
<a href="http://www.w3schools.com/">Visit W3Schools</a>
which will display like this: Visit W3Schools Clicking on this hyperlink will send the user to W3Schools' homepage. Tip: The "Link text" doesn't have to be text. It can be an image or any other HTML element.
Example
<a href="http://www.w3schools.com/" target="_blank">Visit W3Schools!</a>
Try it yourself
Example
A named anchor inside an HTML document:
<a name="tips">Useful Tips Section</a>
Create a link to the "Useful Tips Section" inside the same document:
<a href="#tips">Visit the Useful Tips Section</a>
Or, create a link to the "Useful Tips Section" from another page:
<a href="http://www.w3schools.com/html_links.htm#tips"> Visit the Useful Tips Section</a>
More Examples
An image as a link How to use an image as a link. Link to a location on the same page How to link to a bookmark. Break out of a frame How to break out of a frame (if your site is locked in a frame). Create a mailto link How to link to a mail message (will only work if you have mail installed). Create a mailto link 2 Another mailto link.
HTML Images
Previous Next Chapter
v Try it yourself
The URL points to the location where the image is stored. An image named "boat.gif", located in the "images" directory on "www.w3schools.com" has the URL: hvttp://www.w3schools.com/images/boat.gif. The browser displays the image where the <img> tag occurs in the document. If you put an image tag between two paragraphs, the browser shows the first paragraph, then the image, and then the second paragraph.
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).
Tip: It is a good practice to specify both the height and width attributes for an image. If these attributes are set, the space required for the image is reserved when the page is loaded. However, without these attributes, the browser does not know the size of the image. The effect will be that the page layout will change during loading (while the images load).
Note: If an HTML file contains ten images - eleven files are required to display the page right. Loading images takes time, so my best advice is: Use images carefully. Note: When a web page is loaded, it is the browser, at that moment, that actually gets the image from a web server and inserts it into the page. Therefore, make sure that the images actually stay in the same spot in relation to the web page, otherwise your visitors will get a broken link icon. The broken link icon is shown if the browser cannot find the image.
More Examples
Aligning images How to align an image within the text. Let the image float How to let an image float to the left or right of a paragraph. Make a hyperlink of an image How to use an image as a link. Create an image map How to create an image map, with clickable regions. Each of the regions is a hyperlink.
<img /> Defines an image <map> Defines an image-map <area /> Defines a clickable area inside an image-map