Attributes always come in name/value pairs like this: name="value".
Attributes are always specified in the start tag of an HTML element.
Attributes and attribute values are also case-insensitive. However, the World Wide Web Consortium (W3C) recommends lowercase attributes/attribute values in their HTML 4 recommendation, and XHTML demands lowercase attributes/attribute values.
Always Quote Attribute Values
Attribute values should always be enclosed in quotes. Double style quotes are the most common, but single style quotes are also allowed.
In some rare situations, like when the attribute value itself contains quotes, it is necessary to use single quotes:
name='John "ShotGun" Nelson'
The most important tags in HTML are tags that define headings, paragraphs and line breaks.
The best way to learn HTML is to work with examples. We have created a very nice HTML editor for you. With this editor, you can edit the HTML source code if you like, and click on a test button to view the result.
Headings
Headings are defined with the to tags. defines the largest heading. defines the smallest heading.
This is a heading
This is a heading
This is a heading
This is a heading
This is a heading
This is a heading
|
HTML automatically adds an extra blank line before and after a heading.
Paragraphs
Paragraphs are defined with the tag.
This is a paragraph
This is another paragraph
|
HTML automatically adds an extra blank line before and after a paragraph.
Line Breaks
The
tag is used when you want to end a line, but don't want to start a new paragraph. The
tag forces a line break wherever you place it.
This is a para graph with line breaks
|
The
tag is an empty tag. It has no closing tag.
Comments in HTML
The comment tag is used to insert a comment in the HTML source code. A comment will be ignored by the browser. You can use comments to explain your code, which can help you when you edit the source code at a later date.
Note that you need an exclamation point after the opening bracket, but not before the closing bracket.
Basic Notes - Useful Tips
When you write HTML text, you can never be sure how the text is displayed in another browser. Some people have large computer displays, some have small. The text will be reformatted every time the user resizes his window. Never try to format the text in your editor by adding empty lines and spaces to the text.
HTML will truncate the spaces in your text. Any number of spaces count as one. Some extra information: In HTML a new line counts as one space.
Using empty paragraphs to insert blank lines is a bad habit. Use the
tag instead. (But don't use the
tag to create lists. Wait until you have learned about HTML lists.)
You might have noticed that paragraphs can be written without the closing tag
. Don't rely on it. The next version of HTML will not allow you to skip ANY closing tags. HTML automatically adds an extra blank line before and after some elements, like before and after a paragraph, and before and after a heading.
We use a horizontal rule (the
tag), to separate the sections in our tutorials.
Basic HTML Tags
Tag | Description |
| Defines an HTML document |
| Defines the document's body |
to | Defines header 1 to header 6 |
| Defines a paragraph |
| Inserts a single line break |
| Defines a horizontal rule |
| Defines a comment |
HTML defines a lot of elements for formatting output, like bold or italic text.
Below are a lot of examples that you can try out yourself:
How to View HTML Source
Have you ever seen a Web page and wondered "Hey! How did they do that?"
To find out, click the VIEW option in your browser's toolbar and select SOURCE or PAGE SOURCE. This will open a window that shows you the HTML code of the page.
Text Formatting Tags
Tag | Description |
| Defines bold text |
| Defines big text |
| Defines emphasized text |
| Defines italic text |
| Defines small text |
| Defines strong text |
| Defines subscripted text |
| Defines superscripted text |
| Defines inserted text |
| Defines deleted text |
| Deprecated. Use <del> instead |
| Deprecated. Use <del> instead |
| Deprecated. Use styles instead |
"Computer Output" Tags
Tag | Description |
| Defines computer code text |
| Defines keyboard text |
| Defines sample computer code |
| Defines teletype text |
| Defines a variable |
| Defines preformatted text |
| Deprecated. Use instead |
| Deprecated. Use instead |
| Deprecated. Use instead |
Citations, Quotations, and Definition Tags
Tag | Description |
| Defines an abbreviation |
| Defines an acronym |
| Defines an address element |
| Defines the text direction |
| Defines a long quotation |
| Defines a short quotation |
| Defines a citation |
| Defines a definition term |
Some characters like the <>
To display a less than sign (<) in HTML, we have to use a character entity.
Character Entities
Some characters have a special meaning in HTML, like the less than sign (<) that defines the start of an HTML tag. If we want the browser to actually display these characters we must insert character entities in the HTML source.
A character entity has three parts: an ampersand (&), an entity name or a # and an entity number, and finally a semicolon (;).
To display a less than sign in an HTML document we must write: < or <
The advantage of using a name instead of a number is that a name is easier to remember. The disadvantage is that not all browsers support the newest entity names, while the support for entity numbers is very good in almost all browsers.
Note that the entities are case sensitive.
This example lets you experiment with character entities: Character Entities IE only
Non-breaking Space
The most common character entity in HTML is the non-breaking space.
Normally HTML will truncate spaces in your text. If you write 10 spaces in your text HTML will remove 9 of them. To add spaces to your text, use the character entity.
The Most Common Character Entities:
Result | Description | Entity Name | Entity Number |
| non-breaking space | | |
< | less than | < | < |
> | greater than | > | > |
& | ampersand | & | & |
" | quotation mark | " | " |
' | apostrophe | ' (does not work in IE) | ' |
Some Other Commonly Used Character Entities:
Result | Description | Entity Name | Entity Number |
¢ | cent | ¢ | ¢ |
£ | pound | £ | £ |
¥ | yen | ¥ | ¥ |
§ | section | § | § |
© | copyright | © | © |
® | registered trademark | ® | ® |
× | multiplication | × | × |
÷ | division | ÷ | ÷ |
To see a full list of HTML character entities go to our HTML Entities Reference.
HTML uses a hyperlink to link to another document on the Web.
The Anchor Tag and the Href Attribute
HTML uses the (anchor) tag to create a link to another document.
An anchor can point to any resource on the Web: an HTML page, an image, a sound file, a movie, etc.
The syntax of creating an anchor:
The tag is used to create an anchor to link from, the href attribute is used to address the document to link to, and the words between the open and close of the anchor tag will be displayed as a hyperlink.
This anchor defines a link to W3Schools:
The line above will look like this in a browser:
Visit W3Schools!
The Target Attribute
With the target attribute, you can define where the linked document will be opened.
The line below will open the document in a new browser window:
target="_blank">Visit W3Schools! |
The Anchor Tag and the Name Attribute
The name attribute is used to create a named anchor. When using named anchors we can create links that can jump directly into a specific section on a page, instead of letting the user scroll around to find what he/she is looking for.
Below is the syntax of a named anchor:
The name attribute is used to create a named anchor. The name of the anchor can be any text you care to use.
The line below defines a named anchor:
You should notice that a named anchor is not displayed in a special way.
To link directly to the "tips" section, add a # sign and the name of the anchor to the end of a URL, like this:
Jump to the Useful Tips Section |
A hyperlink to the Useful Tips Section from WITHIN the file "html_links.asp" will look like this:
Basic Notes - Useful Tips
Always add a trailing slash to subfolder references. If you link like this: href="http://www.w3schools.com/html", you will generate two HTTP requests to the server, because the server will add a slash to the address and create a new request like this: href="http://www.w3schools.com/html/"
Named anchors are often used to create "table of contents" at the beginning of a large document. Each chapter within the document is given a named anchor, and links to each of these anchors are put at the top of the document.
If a browser cannot find a named anchor that has been specified, it goes to the top of the document. No error occurs.
Link Tags
Tag | Description |
| Defines an anchor |
With frames, you can display more than one Web page in the same browser window.
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:
- The web developer must keep track of more HTML documents
- It is difficult to print the entire page
The Frameset Tag
- The
- Each frameset defines a set of rows or columns
- The values of the rows/columns indicate the amount of screen area each row/column will occupy
The Frame Tag
- The tag defines what HTML document to put into each frame
In the example below we have a frameset with two columns. The first column is set to 25% of the width of the browser window. The second column is set to 75% of the width of the browser window. The HTML document "frame_a.htm" is put into the first column, and the HTML document "frame_b.htm" is put into the second column:
Basic Notes - Useful Tips
If a frame has visible borders, the user can resize it by dragging the border. To prevent a user from doing this, you can add noresize="noresize" to the tag.
Add the tag for browsers that do not support frames.
Important: You cannot use the tags together with the tags! However, if you add a tag containing some text for browsers that do not support frames, you will have to enclose the text in tags! See how it is done in the first example below.
Frame Tags
Tag | Description |
| Defines a set of frames |
| Defines a sub window (a frame) |
| Defines a noframe section for browsers that do not handle frames |
| Defines an inline sub window (frame) |
With HTML you can create tables.
Tables
Tables are defined with the tag. A table is divided into rows (with the tag), and each row is divided into data cells (with the tag). The letters td stands for "table data," which is the content of a data cell. A data cell can contain text, images, lists, paragraphs, forms, horizontal rules, tables, etc. row 1, cell 1 |
row 1, cell 2 |
row 2, cell 1 |
row 2, cell 2 |
| How it looks in a browser: row 1, cell 1 | row 1, cell 2 | row 2, cell 1 | row 2, cell 2 | Tables and the Border Attribute If you do not specify a border attribute the table will be displayed without any borders. Sometimes this can be useful, but most of the time, you want the borders to show. To display a table with borders, you will have to use the border attribute: Row 1, cell 1 |
Row 1, cell 2 |
| Headings in a Table Headings in a table are defined with the | tag. Heading |
Another Heading |
row 1, cell 1 |
row 1, cell 2 |
row 2, cell 1 |
row 2, cell 2 |
| How it looks in a browser: Heading | Another Heading | row 1, cell 1 | row 1, cell 2 | row 2, cell 1 | row 2, cell 2 | Empty Cells in a Table Table cells with no content are not displayed very well in most browsers. row 1, cell 1 |
row 1, cell 2 |
row 2, cell 1 |
|
| How it looks in a browser: row 1, cell 1 | row 1, cell 2 | row 2, cell 1 | | Note that the borders around the empty table cell are missing (NB! Mozilla Firefox displays the border). To avoid this, add a non-breaking space ( ) to empty data cells, to make the borders visible: row 1, cell 1 |
row 1, cell 2 |
row 2, cell 1 |
|
| How it looks in a browser: row 1, cell 1 | row 1, cell 2 | row 2, cell 1 | | Basic Notes - Useful Tips The , and elements are seldom used, because of bad browser support. Expect this to change in future versions of XHTML. If you have Internet Explorer 5.0 or newer, you can view a working example in our XML tutorial. Table Tags Tag | Description | HTML Lists HTML supports ordered, unordered and definition lists. Unordered Lists An unordered list is a list of items. The list items are marked with bullets (typically small black circles). An unordered list starts with the tag. Each list item starts with the - tag.
Here is how it looks in a browser: Inside a list item you can put paragraphs, line breaks, images, links, other lists, etc. Ordered Lists An ordered list is also a list of items. The list items are marked with numbers. An ordered list starts with the tag. Each list item starts with the - tag.
Here is how it looks in a browser: 1. Coffee 2. Milk Inside a list item you can put paragraphs, line breaks, images, links, other lists, etc. Definition Lists A definition list is not a list of items. This is a list of terms and explanation of the terms. A definition list starts with the tag. Each definition-list term starts with the - tag. Each definition-list definition starts with the
- tag.
Coffee Black hot drink Milk White cold drink
| Here is how it looks in a browser: Coffee Black hot drink Milk White cold drink Inside a definition-list definition (the tag) you can put paragraphs, line breaks, images, links, other lists, etc. List Tags Tag | Description |
| Defines an ordered list | | Defines an unordered list | | Defines a list item |
| Defines a definition list | | Defines a definition term | | Defines a definition description | | Deprecated. Use | | Deprecated. Use |
| |
No comments:
Post a Comment