UNIT - 1 XHTML

• What is XHTML – XHTML stands for EXtensible HyperText Markup Language. It is a cross between HTML and XML language. – XHTML is almost identical to HTML but it is stricter than HTML. XHTML is HTML defined as an XML application. It is supported by all major browsers. – Although XHTML is almost the same as HTML but It is more important to create your code correctly, because XHTML is stricter than HTML in syntax and case sensitivity. XHTML documents are well-formed and parsed using standard XML parsers, unlike HTML, which requires a lenient HTML-specific parser. • HTML Versions • Since the early days of the web, there have been many versions of HTML: Why Use XHTML?

• XHTML was developed to make HTML more extensible and increase interoperability with other data formats. There are two main reasons behind the creation of XHTML: – It creates a stricter standard for making web pages, reducing incompatibilities between browsers. So it is compatible for all major browsers. – It creates a standard that can be used on a variety of different devices without changes. • • • •

BAD HTML • • The above HTML code doesn't follow the HTML rule although it runs. Now a day, there are different browser technologies. Some browsers run on computers, and some browsers run on mobile phones or other small devices. The main issue with the bad HTML is that it can't be interpreted by smaller devices. • So, XHTML is introduced to combine the strengths of HTML and XML. • XHTML is HTML redesigned as XML. It helps you to create better formatted code on your site. • XHTML doesn't facilitate you to make badly formed code to be XHTML compatible. Unlike with HTML (where simple errors (like missing out a closing tag) are ignored by the browser), XHTML code must be exactly how it is specified to be. Basic Syntax

• Tags – The declaration defines this document to be HTML5 – The element is the root element of an HTML page – The element contains meta information about the document – The element specifies a title for the document – The <body> element contains the visible page content – The <h1> element defines a large heading – The <p> element defines a paragraph • <html> • <head> • <title>Page title • • •

This is a heading

This is a paragraph.

This is another paragraph.

• • • You can easily maintain, edit, convert and format your document in the long run. • Since XHTML is an official standard of the W3C, your website becomes more compatible with many browsers and it is rendered more accurately. • XHTML combines strength of HTML and XML. Also, XHTML pages can be rendered by all XML enabled browsers. • XHTML defines quality standard for your webpages and if you follow that, then your web pages are counted as quality web pages. The W3C certifies those pages with their quality stamp. • Web Browsers – The purpose of a web browser (Chrome, IE, Firefox, Safari) is to read HTML documents and display them. – The browser does not display the HTML tags, but uses them to determine how to display the document: Basic Understanding

• What is SGML? – This is Standard Generalized Markup Language (SGML) application conforming to International Standard ISO 8879. HTML is widely regarded as the standard publishing language of the World Wide Web. – This is a language for describing markup languages, particularly those used in electronic document exchange, document management, and document publishing. HTML is an example of a language defined in SGML. • What is XML? – XML stands for EXtensible Markup Language. XML is a markup language much like HTML and it was designed to describe data. XML tags are not predefined. You must define your own tags according to your needs. • XHTML – XHTML syntax is very similar to HTML syntax and almost all the valid HTML elements are valid in XHTML as well. But when you write an XHTML document, you need to pay a bit extra attention to make your HTML document compliant to XHTML. Basic Syntax

• converting existing HTML document into XHTML document − – Write a DOCTYPE declaration at the start of the XHTML document. – Write all XHTML tags and attributes in lower case only. – Close all XHTML tags properly. – Nest all the tags properly. – Quote all the attribute values. – Forbid Attribute minimization. – Replace the name attribute with the id attribute. – Deprecate the language attribute of the script tag. • XHTML document must include four tags , , , and <body> • Tags are fundamental syntactic unit of HTML. • Tags are used to specify categories of content. • Most tags appears in pairs: opening tag and closing tag. • The name of the closing tag is the name of its corresponding opening tag with a slash attached to the beginning. Whatever appears in between these two tags is the content of the tag. • The opening tag and the closing tag together specify a container for the content they enclose. • The container and its content together are called an element. • An XHTML document consists of two parts, the head and the body. • Head part provides information about the document. • Body parts provides the content of the document , which itself includes tags and attributes. • Comments :- browsers ignores the XHTML comments. • Comments in the program increase the readability of the programs. • E.g. • <!– anything except two adjacent dashes  DOCTYPE Declaration • DTD stands for Document Type Definition. • A DTD allows you to create rules for the elements within your XHTML documents. Although XHTML itself has rules, the rules defined in a DTD are specific to your own needs. • All XHTML documents must have a DOCTYPE declaration at the start. • The XHTML standard defines three Document Type Definitions (DTDs). The most commonly used and easy one is the XHTML Transitional document. • XHTML 1.0 document type definitions correspond to three DTDs − – Strict – Transitional – Frameset • The basic syntax is: <!DOCTYPE rootname [DTD]> • ...where, rootname is the root element, and [DTD] is the actual definition. • Actually, there are slight variations depending on whether your DTD is internal or external (or both), public or private. • <!DOCTYPE rootname PUBLIC identifier URL> • The keyword PUBLIC indicates that it's a public DTD (for public distribution). • The presence of URL indicates that this is an external DTD (the DTD is defined in a document located at the URL). • The identifier indicates the formal public identifier and is required when using a public DTD. – E.g. – <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd"> Standard XHTML Document Structure </p><p>• Every XHTML document must begin with an <a href="/tags/XML/" rel="tag">xml</a> declaration element that simply identifies the document as being one based on XML.</p><p><?xml version="1.0" encoding="UTF-8"?></p><p>– First Attribute specifies the version number (still 1.0) – Second attribute defines encoding used for the document. (unicode encoding , utf-8) Example </p><p><!DOCTYPE html> <html> <body></p><p><h1>My First Heading</h1></p><p><p>My first paragraph.</p></p><p></body> </html> Basic Text Markup</p><p>• Paragraph – Text is normally organized into paragraph in the body of a document. – XHTML standard does not allow text to be placed directly in a document. Example 1 Example 2 <!DOCTYPE html> <!DOCTYPE html> <html> <html> <body> <body></p><p><p> <p>This is a paragraph. This paragraph <p>This is a paragraph. contains a lot of lines <p>This is a paragraph. in the <a href="/tags/Source_code/" rel="tag">source code</a>, but the browser <p>Don't forget to close your HTML ignores it. tags!</p> </p></p><p></body> </body> </html> </html> Line Breaks</p><p>• <br /> element defines a line break. • Use <br /> if you want a line break (a new line) without starting a new paragraph. • < br /> the slash indicates that the tag is both an opening and closing tag. • eg. <p>This is<br / >a paragraph<br />with line breaks.</p></p><p>Preserving whitespace</p><p>• The text inside a <pre> element preserves both spaces and line breaks.</p><p>Headings </p><p>• In XHTML there are six levels of headings, specified by the tags <h1>, <h2>, <h3>, <h4>,<h5> and <h6>. • <h1>, <h2>, <h3> uses font sizes that are larger than that of the default size of text. • <h4> uses the default size and • <h5> and <h6> use smaller size.</p><p>Block Quotation</p><p>• A block of text to be set off from the normal flow of text in a document. <!DOCTYPE html> <html> <body></p><p><p>Browsers usually indent blockquote elements.</p></p><p><blockquote > “For 50 years, WWF has been protecting the future of nature. The world's leading conservation organization, WWF works in 100 countries and is supported by 1.2 million members in the United States and close to 5 million globally.” </blockquote></p><p></body> </html> Font styles and sizes </p><p>• Content – based style tags – tags indicates the particular kind of text that appears in their content. – Emphasis tag <em>- special text content. Mostly highlighted by italic font. – Strong tag <strong> - more than emphasis tag. Mostly highlighted by bold font. – Code tag <code> - used to specify a monospace font, usually used for program code. • Non content – based style tags- – <sub> subscript character – <sup> superscript character XHTML tags are categorized in block or inline. Inline tag :- content appears on the current line. Inline tag does not implicitly include line break . Exception is br. E.g <em>, <strong> Block tag :- breaks the current line so that its content appears on a new line. The heading and block quote tags are block tag. Character Entities</p><p>• The special character are defined as entities which are names for the character by the browser. Horizontal Rules</p><p>• Places the horizontal lines in between the document to make it easy for reading. • It is represented by <hr />. • The browser chose the thickness, length and horizontal placement of line. The Meta Element</p><p>Meta element :- provide additional information about a document. • It has no content and all the provided information is through attribute. • Two attributes are name and content. e.g. <meta name = “keyword” content = “binary trees, linked list, stacks” /> Web search use the information provided with the meta element to categorize web document in their indices. Images</p><p>• Image : - the image is stored in a file which is specified by an XHTML request. The image is inserted into the display of the document by the browser. • Image formats:- – GIF (Graphic Inter-change format): developed by compuserve network service provider for the specific purpose of moving images. It uses 8 bit color representation for pixels. Images use the .gif or .GIF extension. Supports transparency. – JPEG (Joint photographic expert group) :uses 24 bit color for representation for pixels. It uses .jpg or .JPG or .jpeg extension. The compression algorithm used by JPEG is better at shrinking an image than the one used by GIF. Size of JPEG is smaller than GIF but it does not support transparency. – PNG (Portable Network Graphics).: provides good replacement for both GIF and JPEG because it has best characteristics of both. – But PNG file requires more space as its compression algorithm does not compromise picture clarity. • The tag :- it is a inline tag , specifies an image that is to appear in a document. • It includes two attributes: src and alt – Src :- specifies the file containing the image. – alt :- specifies text to be displayed when it is not possible to display the image. • Two optional attributes of img width and height can be included to specify the size of the rectangle for the image. • E.g. XHTML Document Validation</p><p>• XHTML Document Validation: the W3C provides a convenient Web-based way to validate XHTML document against its standard. • The URL of the service is http://validator.w3.org/ file-upload.html • The XHTML validation system is a valuable tool for producing documents that adhere to W3C standards. • The specific std against which the document is checked is given in the DOCTYPE command. Hypertext Links</p><p>• A hypertext link in an XHTML document, called as a link, acts as a pointer to some resource. Links :- A link that points to a different document specifies the address of that document. – Such an address might be a filename, a directory path and a filename, or a complete URL. – Links are specified in an attribute of an anchor tag (<a>), which is a inline tag. – The anchor tag that specified a link is called the source of that link. – The document whose address is specified in a link is called the target of that link. – For creating link href( hypertext reference ) attribute is required. – The value assigned to href specifies the target of the link. – the content of an anchor tag, which becomes the clickable link the user sees, is restricted to text , line break, images and headings. – Links are usually implicitly rendered in a different color than the surrounding and most of the time underlined. – When the mouse cursor is placed over the anchor-tag content and the left mouse button is pressed, the link is taken by the browser. – If the target is a different document, that document is loaded and displayed, replacing the currently displayed document. • If the target is in the current document, the document is scrolled by the browser to display the target of the link. <!DOCTYPE html> <html> <head> <title>Hyperlink Example

Click following link

Link file Hyperlink Example

Click following link

Link info Targets within Document

• Links are used to allow readers to jump to specific parts of a Web page. • Links can be useful if your webpage is very long. • To make a bookmark, you must first create the bookmark, and then add a link to it. • When the link is clicked, the page will scroll to the location with the bookmark. • Example • First, create a bookmark with the id attribute: –

Chapter 4

• Then, add a link to the bookmark ("Jump to Chapter 4"), from within the same page: – Jump to Chapter 4 • Or, add a link to the bookmark ("Jump to Chapter 4"), from another page:

Jump to Chapter 4

Chapter 1

This chapter explains ba bla bla

Chapter 2

This chapter explains ba bla bla

Chapter 3

This chapter explains ba bla bla

Chapter 4

This chapter explains ba bla bla

Chapter 5

This chapter explains ba bla bla

Chapter 6

This chapter explains ba bla bla

• Jump to Chapter 4 • Chapter 1 • This chapter explains ba bla bla • Chapter 2 • This chapter explains ba bla bla • Chapter 3 • This chapter explains ba bla bla • Chapter 4 • This chapter explains ba bla bla • Chapter 5 • This chapter explains ba bla bla • Chapter 6 • This chapter explains ba bla bla Lists

• HTML offers web authors three ways for specifying lists of information. All lists must contain one or more list elements. Lists may contain − –