• XHTML - For beginers

 #83729  by reececlarke
 Thu Feb 18, 2016 11:12 am
What makes XHTML different from html
The biggest difference between the two is standardization html can be written in quite a shoddy format and still be accepted by the web browser however with XHTML if your code does not conform with the standards then the webpage will refuse to show and will point out to where the error is located.

What are the benefits of using XHTML?
The main benefits of using XHTML come into practise when you are set standards to conform to e.g. in the workplace. If we look past things such as the inability to write sloppy code, this also helps those with special browsers to help with poor sight or lack of it, which are designed to read pages written in xhtml, as those who conform to the standard closer make it easier for the software to display the information in a easy to read manor, as opposed to a poorly written html page which would still load however it might be displayed poorly in the software making it harder for someone with disabilities to read.
What are the big difference between XHTML and HTML?
One of the big differences between the two is that you have to end single tag elements an example of this can be found within the <img> tag in the example shown below

HTML
Code: Select all
 <img src="GenericImage.png"> 
XHTML
Code: Select all
<img src="GenericImage.png" alt="A cool generic image" />
For XHTML we first have to point out the alt which is shown within the tag, this is required in order to conform to the format as it is used to point out to those who are less able to still use the content you provide. Second of all before the end we can also see' />', this is because we have to inform the browser the end of every element, even if it is contained within a single tag. Other examples of this include '<br />', which stands for a line break, although it is dis-advised to use this as CSS should be used for all formatting.

One of the next big differences between HTML and XHTML is that we have to inform the browser within each webpage what standard we are using for us this would be XHTML1.0 strict and the following bellow should be the base for every XHTML webpage you create.
Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title> Site Name</title>
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width; initial-scale=1.0" />
		
	</head>
	<body>
		<!-- All content for the site should be in here and only within here -->
	</body>
</html>

as we are using a xml format for creating the site without telling this to the web-browser it will have no clue as to what it is doing and there for will not render the page unless you tell it the standards you are using.

The next big difference is unlike within html you are able to just like the style sheet within the head and be done with it within xhtml you have to inform the browser what type of link it is as shown below.
Code: Select all

<link rel="stylesheet" type="text/css" href="linkToStyleSheet.css" />

How do i check if my page is valid?
The simplest way in order to make sure that your web page is valid you could go to the W3Schools validator which is linked here http://www.validator.w3.org
Last edited by reececlarke on Thu May 12, 2016 7:02 am, edited 2 times in total.
 #83731  by Codex
 Fri Feb 19, 2016 2:06 am
Is it possible to list out the pros of using xHTML as well? I guess there are benefits of using xHTML otherwise everyone would've just used normal html and ignored all the errors (and still have the page displayed)
 #83734  by reececlarke
 Sun Feb 21, 2016 10:47 am
Codex wrote:Is it possible to list out the pros of using xHTML as well? I guess there are benefits of using xHTML otherwise everyone would've just used normal html and ignored all the errors (and still have the page displayed)
Fair point I will have to add that as it is mostly down to industry standards and allowing your site to be easily accessed by those with disabilities.