Guide To XHTML
Guide To XHTML
Markup languages are used to tell a web browser how to format and display a web page. Most common language used for web publishing is HTML (Hyper Text Markup Language) HTML can be viewed as a subset of SGML (Standard Generalized Markup Language), which is a markup language that defines standard document format. Basic idea - using pre-defined tags to add structure to content of the document, which is then formatted for display by browsers parser.
Dept of I.T., NITK Surathkal
Based on XML (eXtensible Markup Language) XML is a markup language designed for describing data.
XHTML is a stricter and cleaner version of HTML XHTML is HTML redefined as an XML application XHTML is set to replace HTML
1/21/2013
A DTD, or Document Type Definition describes the syntax to use for the current document. These DTDs are public and on the web. An XHTML document always contains a reference to one of these DTDs. There are four different DTDs for XHTML.
XHTML 1.0. Strict XHTML 1.0. Transitional XHTML 1.0. Frame Set XHTML 1.1
DOCTYPE declaration
XHTML 1.0 Strict Use for really clean markup, with no display information. (no font, color, or size information) Use CSS (Cascading Style Sheets) if you want to define how the document should be displayed. XHTML 1.0 Transitional Use with standard HTML and/or with CSS. Allows deprecated HTML elements. XHTML 1.0 Frameset Use if your document uses HTML frames. XHTML 1.1 Like 1.0 Strict, but with added support for Chinese.
Dept of I.T., NITK Surathkal
Every XHTML document must begin with one of the DOCTYPE declarations (DTDs):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
1/21/2013
Markup Validation
is an online tool for checking (but not fixing) HTML and XHTML documents.
File Extension: A file containing an HTML page should have the extension .html According to W3C, an XHTML page should have the extension .xhtml
background - specifies URL of background image. bgcolor - specifies background color. text - default color of text on webpage. Link - color of hyperlinks not yet visited. alink - color of active hyperlinks. vlink - color of visited hyperlinks.
Six levels of headings. <h1>, <h2> up to <h6> <h1>, <h2> ,<h3> are for larger fonts. <h4> is normal size font. (as defined by browser settings.) <h5> and <h6> are smaller than normal fonts. Attributes include align (values center, left, right and justify) Default alignment is left. For e.g
<h1 align=center> Hello World</h1>
Colors are represented by hexadecimal codes. (64,456 colors) For e.g. #000000 - Black; #ffffff - White
Dept of I.T., NITK Surathkal
1/21/2013
<p> </p> Attributes include align (values center, left, right and justify) Default alignment is left.
For e.g
<p align=justify> my first XHTML document </p>
To set off a block of text within a paragraph from the normal flow of text in a document. Different browsers handle the <blockquote> tag in different ways. (e.g. by indenting or by italizing) For e.g.
<p> Quote for the day <blockquote> Work is Worship </blockquote> .. </p>
Note : Multiple spaces in the source paragraph are replaced by a single space in the displayed text. To preserve spaces, use <pre> tag. To introduce line breaks, use <br /> tag.
Dept of I.T., NITK Surathkal
To insert a horizontal line, <hr /> tag is used. Attributes are align - alignment method. noshade - display using solid color (black) size - sets thickness in pixels width - sets width (100% whole page, or in pixels)
Used to define font properties. Attributes color - defines font color face - defines font style size - default sizes (1 to 7)
For e.g.
<font color=#00abec size=4 face=arial,courier> . </font>
1/21/2013
<b>, <i> and <u> - are called content based tags since tag indicates the style of the text that appears in their content. Other tags:
Emphasis Strong Subscript/superscript Code Blinking Text Moving Text <em> <strong> <sub> and <sup> <code> <blink> <marquee>
A collection of special Entity characters that are sometimes needed in natural Character Meaning text, but cannot be used as themselves in marked up text. Ampersand & & XHTML uses character entities to represent these in the browser. Lesser Than < <
>
o
Greater Than Double quotes Single quotes Fraction Degree Non breaking space Trademark Symbol Plus or minus
(space) TM
Dept of I.T., NITK Surathkal Dept of I.T., NITK Surathkal
Block Tags an element that creates large blocks of content like paragraphs or page divisions. They start new lines of text when used can contain other blocks as well as inline elements and text or data. Inline Tags an element that defines text or data in the document. don't start new lines when you use them. they generally only contain other inline tags and text or data. Or they include nothing at all, like the <br /> tag.
Dept of I.T., NITK Surathkal
Gives the file name/path/url of the image to be displayed. Left, right or center Gives a description of the image Sets border size (in pixels) In pixels In pixels Specifies additional horizontal space to be added around image. Specifies additional horizontal space to be added around image.
1/21/2013
Anchor tags are used to create clickable links. May point to a file, a URL or any other resource.
<a href = http://www.google.com/>Google</a> <a href = mailto:webmaster@site.com>Contact Us</a>
used to create a bookmark inside an XHTML document. Example: A sub heading with an unique id inside an XHTML document:
<h2 id ="tips">Useful Tips Section</h2>
Syntax:
Create a link to the "Useful Tips Section" inside the same document:
<a href="#tips">Go to Useful Tips Section</a>
Links can include images in their content, then browser displays the image with the link.
<a href = http://www.google.com/> <img src=/images/google.jpg alt=google_logo_pic /> </a>
Dept of I.T., NITK Surathkal
Or, create a link to the "Useful Tips Section" from another page:
<a href="http://www.mysite.com/help.html#tips"> Go to Useful Tips Section</a>
Dept of I.T., NITK Surathkal
E.g. open the linked document in a new browser window or a new tab:
<a href="http://www.google.com/" target="_blank"> Value Description Search on Google</a> Opens the linked document in a new window or tab _blank _self _parent _top Opens the linked document in the same frame as it was clicked (this is default) Opens the linked document in the parent frame Opens the linked document in the full body of the window
Used to format text using a list for ease of reading. 1. Unordered Lists: <ul> tag to create the list, <li> tag to specify each list item. <ul> tag has an attribute type (values circle, square and disc) 2. Ordered Lists: Used for lists where order of items is important. <ol> tag to create the list, <li> tag to specify each list item. Attribute type defines numbering style. (values 1, a, A, i, I ). Attribute start defines initial value. <li> tag has an attribute value that overrides previous numbering.
Dept of I.T., NITK Surathkal
1/21/2013
Used to format text using a list for ease of reading. 3. Definition Lists: Used to specify lists of terms and their definitions such as glossaries. <dl> creates the list. <dt> term to be defined. <dd> term description. Each term appears at left margin, and the description is displayed on the next line. (with indent.)
A table is a matrix of rows and columns, each intersection of a row and a column is called a cell.
Syntax: <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>
Dept of I.T., NITK Surathkal
Table can be given a title by using <caption> tag. Attributes of the <table> tag are as follows Attribute Name Description
align bgcolor
border
width
cellpadding Sets padding between data and cell border (in pixels) cellspacing Sets spacing between data cells (in pixels) rowspan colspan
Dept of I.T., NITK Surathkal
specifies no. of rows spanned by a data cell. specifies no. of columns spanned by a data cell.
Dept of I.T., NITK Surathkal
1/21/2013
XHTML Forms
colspan specifies no. of columns spanned by a data cell. rowspan specifies no. of rows spanned by a data cell.
Example
<table border="1"> <tr> <th>Month</th> <th>Savings</th> </tr> <tr><td>January</td> <td rowspan="2">$100</td> </tr> <tr> <td>February</td> </tr> <tr> <td colspan="2">Sum: $100 </td> </table>
XHTML provides tags to generate commonly used objects on a screen form. (called controls or form widgets.)
All tags to create widgets are inline tags and appear inside the <form> tag. Each widget can have a value, given by user input. Together, all values in a form are called form data.
Dept of I.T., NITK Surathkal
</tr>
is a block tag.
Syntax: <form action=pgm url method =GET or POST> </form> Attribute action method Description Provides URL of the server-side program/script for processing form data. Specified HTTP method for passing data to the server. If GET data is attached to the destination URL using a query string. If POST data is embedded inside the HTTP request message.
<form> - The root element which is the block element for all the form widgets <input> - Defines the different input elements within the <form> tag.
<form name=frm1 action= method= >
1/21/2013
Textbox
Password Textbox
Used for collecting simple text. All input widgets use the <input> tag, but type attribute defines the kind of widget to be rendered on the screen.
Special textbox for entering a password. <input type=password name=pwd id=txt2 size=20 maxlength=8 />
<form name=frm1 action=submit.php method=post> <input type=text name=cname size=20 maxlength=50 /> </form> id=txt1
Checkbox Used for choosing among a no. of items as applicable. Multiple checkboxes can be selected at a time. If a checkbox is checked, that name=value pair is passed to the server for processing.
<label>Hobbies </label> <input type=checkbox name=hobbies id=chk1 value=Books checked=checked/> Books <input type=checkbox name=hobbies id=chk2 value=Travel/> Travel
Dept of I.T., NITK Surathkal
Radio Buttons
Used for choosing among a no.of items as applicable. Only one can be selected at a time.
Creates a multiline textarea. Text has no limitation in length (both horizontal and vertical) Horizontal scrolling is provided automatically when needed.
<label>Age group</label>
<input type=radio name=age id=rad1 value=18 - 25 selected=selected />18 - 25 <input type=radio name=age id=rad2 value=26 - 35 /> 26 35 <label> Comments </label> <br /> <textarea name=comments rows=6 cols=50 > Please give your valuable feedback. </textarea>
1/21/2013
Creates a dropdown list or a select menu. size attribute defines how many fields are to be displayed. multiple attribute allows more than one selection. (for select menu) <option> tag is used to specify options available for selection.
<select name=state id=select1 size =1> <option value=Karnataka>Karnataka</option> <option value=Kerala>Kerala</option> </select>
<label>Your favorite cities </label><br /> <select name="city" size="5" multiple="multiple"> <option value="Surathkal">Surathkal</option> <option value="Mangalore">Mangalore</option> <option value="Udupi">Udupi</option> <option value="Goa">Goa</option> <option value="Bangalore">Bangalore</option> </select>
Action Buttons: Types: Button creates a clickable button. Reset clears all form widgets and resets them to their initial states. Submit When submit is pressed
Form data is encoded and sent to the server. Server is requested to execute the program specified in the action attribute. (which will process form data and return response to user.)
<input type=submit name=Submit value=submit form/> <input type=reset name=Reset value=reset form /> <input type=button name=Clickme value=Click Me!/>
10
1/21/2013
Frames
Used to display more than one webpage at a time on the browser display window. Window can be divided into rectangular areas, each of which is a frame, and so can display separate documents. XHTML1.1 does not support frames.
Number of frames and their layout in the browser window is specified with <frameset> tag. the <frameset> element is used instead of the <body> element. A document has either a <body> or a <frameset>, but cannot have both.
Syntax:
<html > <head> </head> <frameset . > </frameset> </html>
Dept of I.T., NITK Surathkal
XHTML docs with frames cannot be validated unless they include the Frameset DTD.)
The content of the frame is specified using the <frame> tag. <frame> is a inline tag, so it can appear only within its block tag <frameset> Syntax
<frameset rows =20%, 80%> <frame name=top src=top.html /> <frame name=bottom src=bottom.html /> </frameset>
Each frame defined within the frameset has an associated <frame> tag that gives the filename of the document that is to be displayed within it. Hence sequence of definition is important.
Dept of I.T., NITK Surathkal
11
1/21/2013
Frames (contd.)
Attribute frameborder src name noresize scrolling Description
If border is to be displayed or not (0 or 1) Specifies URL of initial document to be loaded. Specifies a name for id purposes Does not allow users to change size of frame Indicates whether a scrollbar is used (yes, no, auto)
More than one frameset tags can be used to create a nested set of frames. <?xml .?> The attributes rows and cols can be used separately or together. <DOCTYPE.. .>
<html ..> <head><title> index.html</title> </head> <frameset rows=20%, 80%> <frame name=banner src=mybanner.html/> <frameset cols=30%,70%> <frame name=nav src =mylinks.html/> <frame name=content src =mypage1.html/> </frameset> </frameset> </html> index.html
Other options _blank - display page in a new browser window (with frame setup ) _self - display page in originating frame. _top - display page in full browser window (without any frames.)
Dept of I.T., NITK Surathkal
12
1/21/2013
Frames (contd.)
You cannot bookmark a collection of documents in a frameset, or send someone a reference to the collection. Smaller devices often cannot cope with frames as their screen is not big enough to be divided up. Some times your page may be displayed differently on different computers due to different screen resolution. Search engines find (X)HTML pages, not Framed pages, so search results usually give you pages without the navigation context that was intended.
Use <noframes> tag which provides a message to users whose browsers do not support frames.
Syntax:
<html> <head> </head> <frameset . > <noframes> <body> Your browser does not support frames. </body> </noframes> </frameset> </html>
Dept of I.T., NITK Surathkal
XFrames is an XML application for composing documents together, replacing HTML Frames.
Metadata is information about data. The <meta> tag provides metadata about the HTML document. Metadata will not be displayed on the page, but will be machine parseable.
Some search engines will use the name and content attributes of the meta element to index your pages.
<meta name="author" content=Dept of IT" /> <meta name="revised" content="2013/01/01" /> <meta name="description" content=Client side Programming with XHTML and CSS" /> <meta name="keywords" content=XHTML, CSS" />
The metadata can be used by browsers (how to display content or reload page), search engines (keywords), or other web services.
Meta elements are typically used to specify page description, keywords, author of the document, last modified, and other metadata.
http-equiv attribute
address.
<meta http-equiv = refresh content = 5; url=http://www.newsite.com"/>
13
1/21/2013
<embed>, <object>, <audio>, <video> tags <map>, <area> tags <script> tag
Image maps
Scripts
Tag & attribute names (and values) must be in lowercase. All XHTML elements must be closed. If an XHTML tag is not a container, close it like this:
<br />, <hr />, <img src="smile.gif" />
Dept of I.T., NITK Surathkal
Wrong: <img src="picture.gif" name="pic1" /> Right: <img src="picture.gif" id="pic1" /> Best: <img src=nitk.gif" name=nitk_pic
id = "pic1"/>
14