HTML - Getting Started
| | |
What You Need
You don't need any tools to learn HTML at W3Schools.- 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.
Create Your Own Test Web
If you just want to learn HTML, skip the rest of this chapter.If you want to create a test page on your own computer, just copy the 3 files below to your desktop.
(Right click on each link, and select "save target as" or "save link as")
mainpage.htm
page1.htm
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.
Use Your Test Web For Learning
We suggest you experiment with everything you learn at W3Schools by editing your web files with a text editor (like Notepad).Note: If your test web contains HTML markup tags you have not learned, don't panic. You will learn all about it in the next chapters.
.HTM or .HTML File Extension?
When you save an HTML file, you can use either the .htm or the .html file extension. There is no difference, it is entirely up to you.What is HTML?
HTML is a language for describing web pages.
- 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 tags
- HTML uses tags to describe web pages
- HTML is a case independent, it has no fixed number of tags and attributes.
- Attributes are those specific words/letters prescribed for certain tags having certain possible values.
World Wide Web (WWW)
- The World Wide Web (WWW) is a system of interlinked hypertext documents accessed via the internet.
- The WWW is a global information medium which users can read and write via computers connected to the internet.
Uniform Resource Locator (URL)
· URL is pronounced as YU-AHR-EHL or UHRL is the address of a file (resource) accessible on the internet.
· Using the WWW’s protocol, the HTTP, the resource can be an HTML page, an image file or any other file supported by HTTP.
· URL contains the name of the protocol (such as FTP, HTTP, HTTPS etc) required to access the resource, a domain name (e.g. yahoo.com, aup.edu.pk) that identifies a specific computer on the internet.
· E.g. www.ietf.org/rfc/rfc2302.txt , where www.ietf.org specifies the computer name and /rfc/rfc2302.txt specifies the pathname for the specific file in that computer.
Web Site
· A web site is a related collection of World Wide Web (WWW) files that includes a beginning file called a home page.
· From the home page, you can access other webpages on their site.
· For example: the website of Yahoo has the home page address of http://www.yahoo.com and contains thousands of other pages.
HTML Tags
HTML markup tags are usually called HTML tags
- 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 = Web Pages
- 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:
| <html> <body> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html> |
Example Explained
- 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
HTML Basic
HTML Headings
HTML headings are defined with the <h1> to <h6> tags. Example
|
HTML Paragraphs
HTML paragraphs are defined with the <p> tag. Example
|
HTML Links
HTML links are defined with the <a> tag. Example
|
(You will learn about attributes in a later chapter of this tutorial).
HTML Images
HTML images are defined with the <img> tag. Example
|
HTML Images - The <img> Tag and the Src Attribute
In HTML, images are defined with the <img> tag.
The <img> tag is empty, which means that it contains attributes only, and has no closing tag.
To display an image on a page, you need to use the src attribute. Src stands for "source". The value of the src attribute is the URL of the image you want to display.
Syntax for defining an image:
| <img src="url" alt="some_text"/> |
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: http://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.
HTML Images - The Alt Attribute
The required alt attribute specifies an alternate text for an image, if the image cannot be displayed.
| <img src="boat.gif" alt="Big Boat" /> |
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).
HTML Images - Set Height and Width of an Image
The height and width attributes are used to specify the height and width of an image.
The attribute values are specified in pixels by default:
| <img src="pulpit.jpg" alt="Pulpit rock" width="304" height="228" /> |
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).
HTML Hyperlinks (Links)
A hyperlink (or link) is a word, group of words, or image that you can click on to jump to a new document or a new section within the current document.When you move the cursor over a link in a Web page, the arrow will turn into a little hand.
Links are specified in HTML using the <a> tag.
The <a> tag or anchor tag can be used in two ways:
1. To create a link to another document, by using the href attribute
2. To create a bookmark inside a document, by using the name attribute
HTML Link Syntax
The HTML code for a link is simple. It looks like this:| <a href="url">Link text</a> |
Example
| <a href="http://www.w3schools.com/">Visit W3Schools</a> |
Clicking on this hyperlink will send the user to W3Schools' homepage.
Tip: The "Link text" doesn't have to be text. You can link from an image or any other HTML element.
HTML Links - The target Attribute
The target attribute specifies where to open the linked document.The example below will open the linked document in a new browser window or a new tab:
Example
|
HTML Lists
| | |
The most common HTML lists are ordered and unordered lists:
HTML Lists
|
HTML Unordered Lists
An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.The list items are marked with bullets (typically small black circles).
| <ul> <li>Coffee</li> <li>Milk</li> </ul> |
- Coffee
- Milk
HTML Ordered Lists
An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.The list items are marked with numbers.
| <ol> <li>Coffee</li> <li>Milk</li> </ol> |
1. Coffee
2. Milk
HTML Definition Lists
A definition list is a list of items, with a description of each item.The <dl> tag defines a definition list.
The <dl> tag is used in conjunction with <dt> (defines the item in the list) and <dd> (describes the item in the list):
| <dl> <dt>Coffee</dt> <dd>- black hot drink</dd> <dt>Milk</dt> <dd>- white cold drink</dd> </dl> |
Coffee
- black hot drink
Milk
- white cold drink
HTML Tables
| | |
HTML Tables
|
HTML Tables
Tables are defined with the <table> tag.A table is divided into rows (with the <tr> tag), and each row is divided into data cells (with the <td> tag). td stands for "table data," and holds the content of a data cell. A <td> tag can contain text, links, images, lists, forms, other tables, etc.
Table Example
| <table border="1"> <tr> <td>row 1, cell 1</td> <td>row 1, cell 2</td> </tr> <tr> <td>row 2, cell 1</td> <td>row 2, cell 2</td> </tr> </table> |
| row 1, cell 1 | row 1, cell 2 |
| row 2, cell 1 | row 2, cell 2 |
HTML Tables and the Border Attribute
If you do not specify a border attribute, the table will be displayed without borders. Sometimes this can be useful, but most of the time, we want the borders to show.To display a table with borders, specify the border attribute:
| <table border="1"> <tr> <td>Row 1, cell 1</td> <td>Row 1, cell 2</td> </tr> </table> |
HTML Table Headers
Header information in a table are defined with the <th> tag.All major browsers will display the text in the <th> element as bold and centered.
| <table border="1"> <tr> <th>Header 1</th> <th>Header 2</th> </tr> <tr> <td>row 1, cell 1</td> <td>row 1, cell 2</td> </tr> <tr> <td>row 2, cell 1</td> <td>row 2, cell 2</td> </tr> </table> |
| Header 1 | Header 2 |
| row 1, cell 1 | row 1, cell 2 |
| row 2, cell 1 | row 2, cell 2 |
Working with HTML Frames
| | |
With frames, several Web pages can be displayed in the same browser window.
HTML Frames
With frames, you can display more than one HTML document in the same browser window. Each HTML document is called a frame, and each frame is independent of the others.
The disadvantages of using frames are:
- Frames are not expected to be supported in future versions of HTML
- Frames are difficult to use. (Printing the entire page is difficult).
- The web developer must keep track of more HTML documents
The HTML frameset Element
The frameset element holds one or more frame elements. Each frame element can hold a separate document.
The frameset element states HOW MANY columns or rows there will be in the frameset, and HOW MUCH percentage/pixels of space will occupy each of them.
The HTML frame Element
The <frame> tag defines one particular window (frame) within a frameset.
In the example below we have a frameset with two columns.
| <frameset> <a href ="frame_b.htm" target ="showframe">Frame a</a><br> <a href ="frame_b.htm" target ="showframe">Frame b</a><br> <a href ="frame_c.htm" target ="showframe">Frame c</a> </frameset> |
Working with HTML Forms
HTML forms are used to pass data to a server.A form can contain input elements like text fields, checkboxes, radio-buttons, submit buttons and more. A form can also contain select lists, textarea, fieldset, legend, and label elements.
The <form> tag is used to create an HTML form:
| <form> . input elements . </form> |
HTML Forms - The Input Element
The most important form element is the input element.The input element is used to select user information.
An input element can vary in many ways, depending on the type attribute. An input element can be of type text field, checkbox, password, radio button, submit button, and more.
The most used input types are described below.
Text Fields
<input type="text" /> defines a one-line input field that a user can enter text into:| <form> First name: <input type="text" name="firstname" /><br /> Last name: <input type="text" name="lastname" /> </form> |
Note: The form itself is not visible. Also note that the default width of a text field is 20 characters.
Password Field
<input type="password" /> defines a password field:| <form> Password: <input type="password" name="pwd" /> </form> |
Note: The characters in a password field are masked (shown as asterisks or circles).
Radio Buttons
<input type="radio" /> defines a radio button. Radio buttons let a user select ONLY ONE one of a limited number of choices:| <form> <input type="radio" name="sex" value="male" /> Male<br /> <input type="radio" name="sex" value="female" /> Female </form> |
Checkboxes
<input type="checkbox" /> defines a checkbox. Checkboxes let a user select ONE or MORE options of a limited number of choices.| <form> <input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br /> <input type="checkbox" name="vehicle" value="Car" /> I have a car </form> |
Submit Button
<input type="submit" /> defines a submit button.A submit button is used to send form data to a server. The data is sent to the page specified in the form's action attribute. The file defined in the action attribute usually does something with the received input:
| <form name="input" action="html_form_action.asp" method="get"> Username: <input type="text" name="user" /> <input type="submit" value="Submit" /> </form> |
If you type some characters in the text field above, and click the "Submit" button, the browser will send your input to a page called "html_form_action.asp". The page will show you the received input.
Complete Example
<html>
<body>
<form>
First name: <input type="text" name="firstname" /><br />
Last name: <input type="text" name="lastname" /><br />
Password: <input type="password" name="pwd" /><br /><br />
<input type="radio" name="sex" value="male" /> Male<br />
<input type="radio" name="sex" value="female" /> Female<br /><br />
<input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br />
<input type="checkbox" name="vehicle" value="Car" /> I have a car<br />
<form name="input" action="html_form_action.asp" method="get"><br />
Username: <input type="text" name="user" />
<input type="submit" value="Submit" />
</form>
</body>
</html>