Professional Documents
Culture Documents
Core Attributes
ID
The ID attribute uniquely identifies an element within a document. No two elements can have the same ID value in a single document. The attribute's value must begin with a letter in the range A-Z or a-z and may be followed by letters (A-Za-z), digits (0-9), hyphens ("-"), underscores ("_"), colons (":"), and periods ("."). The value is case-sensitive. The following example uses the ID attribute to identify each of the first two paragraphs of a document:
<P ID=firstp>My first paragraph.</P> <P ID=secondp>My second paragaph.</P>
The paragraphs in the example could have style rules associated with them through their ID attributes. The following Cascading Style Sheet defines unique colors for the two paragraphs:
P#firstp { color: navy; background: none } P#secondp { color: black; background: none }
CLASS
The CLASS attribute specifies the element to be a member of one or more classes. Classes allow authors to define specific kinds of a given element. For example, an author could use <CODE CLASS=Java> when giving Java code and <CODE CLASS=Perl> when giving Perl code. Unlike with the ID attribute, any number of elements can share the same class. An element may also belong to multiple classes; the CLASS attribute value is a space-separated list of class names. The value is case-sensitive. The CLASS attribute is particularly useful when combined with style sheets. For example, consider the following navigation bar:
<DIV CLASS=navbar> <P><A HREF="/">Home</A> | <A HREF="./">Index</A> | <A HREF="/search.html">Search</A></P>
This example's use of the CLASS attribute allows style rules to easily be added. The following Cascading Style Sheet suggests a presentation for the preceding example:
.navbar { margin-top: 2em; padding-top: 1em; border-top: solid thin navy } .navbar IMG { float: right } @media print { .navbar { display: none } }
Example
Use of the style attribute in an HTML document: <h1 style="color:blue;text-align:center">This is a header</h1> <p style="color:green">This is a paragraph.</p>
TITLE
The TITLE attribute provides a title for an element and is commonly implemented as a "tooltip" on visual browsers. The attribute is most useful with A, AREA, LINK, and IMG elements, where it provides a title for the linked or embedded resource. Some examples follow:
<A HREF="mailto:liam@htmlhelp.com" TITLE="Feedback on HTML 4 Reference">liam@htmlhelp.com</A> <A HREF="http://stein.cshl.org/WWW/CGI/" TITLE="CGI.pm - a Perl5 CGI Library">CGI.pm</A> <LINK REL=Alternate HREF="index.fr.html" HREFLANG=fr LANG=fr TITLE="Version franaise"> <IMG SRC="wedding.jpg" ALT="[Photo of the bride and groom]" TITLE="The happy couple">
Language Attributes
Description Specifies the text direction for the content in an element Specifies a language code for the content in an element. Language code reference Specifies a language code for the content in an element, in XHTML documents. Language code reference
DIR
The DIR attribute specifies the directionality of text--left-to-right (DIR=ltr, the default) or rightto-left (DIR=rtl). Characters in Unicode are assigned a directionality, left-to-right or right-toleft, to allow the text to be rendered properly.
Lang
The HTML lang attribute can be used to declare the language of a Web page or a portion of a Web page. Declare the primary language for each Web page with the lang attribute inside the <html> tag, like this: <html lang="en"> ... </html>
Xml:lang
In XHTML, the language is declared inside the <html> tag as follows: <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> ... </html>
ISO codes
ar
en hi ja pa
Core Events
The last major aspect of modern markup initially introduced by HTML 4 was the increased possibility of adding scripting to HTML documents. In preparation for a more dynamic Web, a set of core events has been associated with nearly every HTML element. Most of these events are associated with a user doing something. For example, the user clicking an object is associated with an onclick event attribute. So, <p onclick="alert('Ouch!');"> Press this paragraph </p> would associate a small bit of scripting code with the paragraph event, which would be triggered when the user clicks the paragraph. In reality, the event model is not fully supported by all browsers for all tags, so the previous example might not do much of anything. Remember that any tag can have a multitude of events associated with it, paving the way for a much more dynamic Web experience. The common event attributes are device-dependent and largely tailored for the graphical user interface. The available events are as follows:
ONCLICK, when the mouse button is clicked on an element; ONDBLCLICK, when the mouse button is double-clicked on an element; ONMOUSEDOWN, when the mouse button is pressed over an element; ONMOUSEUP, when the mouse button is released over an element; ONMOUSEOVER, when the mouse is moved onto an element; ONMOUSEMOVE, when the mouse is moved while over an element; ONMOUSEOUT, when the mouse is moved away from an element; ONKEYPRESS, when a key is pressed and released over an element; ONKEYDOWN, when a key is pressed down over an element; ONKEYUP, when a key is released over an element.
Link Structure
Like all tags, links follow a structure, and have start tags and end tags. Put this line of code on one of your pages. Very Important <a href="theotherpage.html">The Link</a> Explanation:
a: a stands for Anchor, which means Link. This is the tag that makes it all happen. href: Means Hypertext REFerence. The href part is another attribute, with the location
of the other page as its value. Just change theotherpage.html to the name of the second file. Dont forget the quotation marks! Whatever you put inside the link tags will become a link, coloured blue and underlined. When you rest your mouse on it your cursor will turn into a hand and the URL of the page will appear in your browsers status bar (at the bottom of the window). If you want to make links to other parts of your page (for example a link to the top of the page), set up some internal links. Changing the default colours of the links is dealt with in body attributes.
me</a>
to create this mail me which will open the users email program with your address in the To: box.
Linking to pictures
Linking to a picture file is practically the same as to a html file. Just include the name of the file, and do not forget the correct suffix i.e. if it is a gif or a jpg. For a rundown on the file formats for images on the web, read this. If you want to use a picture as a link, read the next tutorial.
Linking to files
You link to a file just like a picture. The only difference is that it wont open in a browser, but instead will download onto a specified place on the readers hard drive. An example:
<a href="ambient.mp3">download
Embedding a file directly into a page is a different process. We have a page on Internet file formats too.
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.
Internal linking:
The name attribute specifies the name of an anchor. The name attribute is used to create a bookmark inside an HTML document. Note: The upcoming HTML5 standard suggest using the id attribute instead of the name attribute for specifying the name of an anchor. Using the id attribute actually works also for HTML4 in all modern browsers. Bookmarks are not displayed in any special way. They are invisible to the reader.
Example
Create a link to the "Useful Tips Section" inside the same document:
<a href="#tips">Visit the Useful Tips Section</a>
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.
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).
Links
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 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
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.
Link attributes:
Value coordinates URL section_name default rect circle poly _blank _parent _self _top framename
Description Specifies the coordinates of a link Specifies the destination of a link Specifies the name of an anchor
shape
STF
target
TF
Example
<a href="http://www.w3schools.com/" target="_blank">Visit W3Schools!</a>
Note: The upcoming HTML5 standard suggest using the id attribute instead of the name attribute for specifying the name of an anchor. Using the id attribute actually works also for HTML4 in all modern browsers. Bookmarks are not displayed in any special way. They are invisible to the reader.
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>
<map name="Map1"> <a href="sun.htm" shape="rect" coords="0,0,82,126">The Sun</a> <a href="mercur.htm"shape="circle" coords="90,58,3">Mercury</a> <a href="venus.htm" shape="circle" coords="124,58,8">Venus</a> </map> </object>
Required Attributes
Attribute name Value mapname Description Specifies the name for an image-map DTD STF
Standard Attributes
The <map> tag supports the following standard attributes:
Attribute class dir id lang style title xml:lang Value classname rtl ltr id language_code style_definition text language_code Description Specifies a classname for an element DTD STF
Specifies the text direction for the content in an element STF Specifies a unique id for an element STF
Specifies a language code for the content in an element STF Specifies an inline style for an element Specifies extra information about an element STF STF
Specifies a language code for the content in an element, STF in XHTML documents
Image button
The basic syntax of the new <button> tag is like any other containment tag:
<button>.....</button>
IMAGE BUTTON
Image buttons have the same effect as submit buttons. When a visitor clicks an image button the form is sent to the address specified in the action setting of the <form> tag. Since visitors aren't always perfectionists you might consider adding a javascript validation of the content before it is actually sent.
HTML image name= src= align= border= width= height= vspace= hspace= tabindex=
EXPLANATION Submit button Name of the image. Url of the image. Alignment of the image. Border width around the image. Width of the image. Height of the image. Spacing over and under image. Spacing left and right of image. Tab order of the image.
EXAMPLE
The name setting adds an internal name to the image button so the program that handles the form doesn't confuse it with the other fields.
The src setting defines the URL of the image. The align setting defines how the image is aligned. Valid entries are: TOP, MIDDLE, BOTTOM, RIGHT, LEFT, TEXTTOP, BASELINE, ABSMIDDLE, ABSBOTTOM. The alignments are explained in the image section. You can learn about the different alignments here. The border setting defines the width (in pixels) of the border around the image. The width setting defines the width of the image. The height setting defines the height of the image. The vspace setting defines the spacing over and under the image (in pixels). The hspace setting defines the spacing to the left and right of the image (in pixels). The tabindex setting defines in which order the different fields should be activated when the visitor clicks the tab key.
AN EXAMPLE: Look at this HTML example: <html> <head> <title>My Page</title> </head> <body> <form name="myform" action="http://www.mydomain.com/myformhandler.cgi" method="POST"> <div align="center"> <br><br> <input type="text" size="25" value="Enter your name here!"> <br><input type="image" src="rainbow.gif" name="image" width="60"
Html form
HTML
EXPLANATION
EXAMPLE
Text area - several lines Rows in the field. Columns in the field. Name of the field. Control linebreaks. Turns off linebreaks. Shows linebreaks, but sends text as entered. Inserts linebreaks when needed and even sends it. One line text field Characters shown. Max characters allowed. Name of the field. Initial value in the field. Password field. Characters shown. Characters allowed to enter. Name of the field. Initial value in the field. Choose one or more options Name of the field. Initial value in the field. Choose only one option Name of the field. Initial value in the field. Drop-down menu Name of the field. Number of items in list. Allow multiple choice if yes. Individual items in the menu. Make an item default. Value to send if selected.
text size= maxlength= name= value= password size= maxlength= name= value= checkbox name= value= radio name= value= select name= size= multiple= option selected value=
hidden name= value= reset name= value= submit name= value= image name=
Does not show on the form. Name of the field. Value to send. Button to reset all fields Name of the button. Text shown on the button. Button to submit the form Name of the button. Text shown on the button. Image behaving as button Name of the image.
Reset
Submit
Note: This is a quick reference showing the most common settings for each field. For a complete listing and explanation you should follow the link to the relevant field in the menu.
Example
Specify a background image for an HTML document: <html> <body background="bgimage.jpg"> <h1>Hello world!</h1> <p><a href="http://www.w3schools.com">Visit W3Schools.com!</a></p> </body> </html>
Syntax
<body background="value">
Attribute Values
Value Description The URL of the background image. Possible values: URL
An absolute URL - points to another web site (like href="http://www.example.com/bgimage.gif") A relative URL - points to a file within a web site (like href="/images/bgimage.gif")
Example:
<html> <body> <p><b>This text is bold</b></p> <p><strong>This text is strong</strong></p> <p><big>This text is big</big></p> <p><i>This text is italic</i></p> <p><em>This text is emphasized</em></p> <p><code>This is computer output</code></p> <p>This is<sub> subscript</sub> and <sup>superscript</sup></p> </body> </html>
Output:
This text is bold
superscript
Syntax
<font color="value">
Attribute Values
Value color_name
Description Specifies the text color with a color name (like "red")
Example
Specify the color of text:
<font color="red">This is some text!</font>
Example
<html> <body> <table width="500" border="0"> <tr> <td colspan="2" style="background-color:#FFA500;"> <h1>Main Title of Web Page</h1> </td> </tr> <tr valign="top"> <td style="background-color:#FFD700;width:100px;text-align:top;"> <b>Menu</b><br /> HTML<br /> CSS<br /> JavaScript </td> <td style="background-color:#EEEEEE;height:200px;width:400px;textalign:top;"> Content goes here</td> </tr>
<tr> <td colspan="2" style="background-color:#FFA500;text-align:center;"> Copyright 2011 W3Schools.com</td> </tr> </table> </body> </html>
Note: Even though it is possible to create nice layouts with HTML tables, tables were designed for presenting tabular data - NOT as a layout tool!