Part 11 - Learning XHTML for Beginners

Written by Eric Muss-Barnes, 14 December 2018

I have a surprise for you in your XHTML lesson...

You ready?...

You already learned it! XHTML is simply a form of HTML which is a little less forgiving of minor errors and mistakes.

XHTML is an abbreviation for "Extensible Hyper Text Markup Language". Why is it "X" instead of "E" for "extensible"? I have no idea. Computer nerds are strange people, man. I can't explain their weird thought processes. Just know that XHTML means "eXtensible HTML".

XHTML is more strict than regular HTML. What does "strict" mean in this context?

The "strict" part simply means that you must close all of your tags. You can not leave anything open. For example, in regular HTML, you can list line-items without closing tags, and you can write paragraphs without closing tags. But, when using XHTML, you must close them.

When would you use XHTML?

I have used XHTML in publishing all of my ebooks. XHTML is a requirement for ebooks to function.

Let me give you two examples of an XHTML page. The first lesson, I will include deliberate errors, so you can see what happens in the browser. For the second lesson, I will code the page correctly.

PART 11 - LESSON A - INCORRECT XHTML

<!-- This page has an error in the XHTML. Open it in a browser and see if you can find the mistake. --> <!DOCTYPE HTML> <!-- The DOCTYPE declared above is a requirement for XHTML. You do not need it for ordinary HTML. --> <html xmlns="http://www.w3.org/1999/xhtml"> <!-- The xmlns attribute above is another bare-minimum requirement to instruct a browser that you are using XHTML for this page. --> <head> <title>Bill of Rights</title> </head> <body> <h1>Bill of Rights</h1> <!-- Note that the two line-break tags below do not have an open/close. Instead, you simply put a backslash after the "r" to make it XHTML compliant. --> <br/><br/> <p><b>Amendment I</b></p> <p>Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the Government for a redress of grievances. </p> <p><b>Amendment II</b></p> <p>A well regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed.</p> <p><b>Amendment III</b></p> <p>No Soldier shall, in time of peace be quartered in any house, without the consent of the Owner, nor in time of war, but in a manner to be prescribed by law.</p> <p><b>Amendment IV</b></p> <p>The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no Warrants shall issue, but upon probable cause, supported by Oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.</p> <p><b>Amendment V</b></p> <p>No person shall be held to answer for a capital, or otherwise infamous crime, unless on a presentment or indictment of a Grand Jury, except in cases arising in the land or naval forces, or in the Militia, when in actual service in time of War or public danger; nor shall any person be subject for the same offence to be twice put in jeopardy of life or limb; nor shall be compelled in any criminal case to be a witness against himself, nor be deprived of life, liberty, or property, without due process of law; nor shall private property be taken for public use, without just compensation.</p> <p><b>Amendment VI</b></p> <p>In all criminal prosecutions, the accused shall enjoy the right to a speedy and public trial, by an impartial jury of the State and district wherein the crime shall have been committed, which district shall have been previously ascertained by law, and to be informed of the nature and cause of the accusation; to be confronted with the witnesses against him; to have compulsory process for obtaining witnesses in his favor, and to have the Assistance of Counsel for his defence.</p> <p><b>Amendment VII</p> <p>In Suits at common law, where the value in controversy shall exceed twenty dollars, the right of trial by jury shall be preserved, and no fact tried by a jury, shall be otherwise re-examined in any Court of the United States, than according to the rules of the common law.</p> <p><b>Amendment VIII</b></p> <p>Excessive bail shall not be required, nor excessive fines imposed, nor cruel and unusual punishments inflicted.</p> <p><b>Amendment IX</b></p> <p>The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.</p> <p><b>Amendment X</b></p> <p>The powers not delegated to the United States by the Constitution, nor prohibited by it to the States, are reserved to the States respectively, or to the people.</p> </body> </html>

For the next example, I will have all the code work properly.

PART 11 - LESSON B - CORRECT XHTML

<!DOCTYPE HTML> <!-- The DOCTYPE declared above is a requirement for XHTML. You do not need it for ordinary HTML. --> <html xmlns="http://www.w3.org/1999/xhtml"> <!-- The xmlns attribute above is another bare-minimum requirement to instruct a browser that you are using XHTML for this page. --> <head> <title>Bill of Rights</title> </head> <body> <h1>Bill of Rights</h1> <!-- Note that the two line-break tags below do not have an open/close. Instead, you simply put a backslash after the "r" to make it XHTML compliant. --> <br/><br/> <p><b>Amendment I</b></p> <p>Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the Government for a redress of grievances. </p> <p><b>Amendment II</b></p> <p>A well regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed.</p> <p><b>Amendment III</b></p> <p>No Soldier shall, in time of peace be quartered in any house, without the consent of the Owner, nor in time of war, but in a manner to be prescribed by law.</p> <p><b>Amendment IV</b></p> <p>The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no Warrants shall issue, but upon probable cause, supported by Oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.</p> <p><b>Amendment V</b></p> <p>No person shall be held to answer for a capital, or otherwise infamous crime, unless on a presentment or indictment of a Grand Jury, except in cases arising in the land or naval forces, or in the Militia, when in actual service in time of War or public danger; nor shall any person be subject for the same offence to be twice put in jeopardy of life or limb; nor shall be compelled in any criminal case to be a witness against himself, nor be deprived of life, liberty, or property, without due process of law; nor shall private property be taken for public use, without just compensation.</p> <p><b>Amendment VI</b></p> <p>In all criminal prosecutions, the accused shall enjoy the right to a speedy and public trial, by an impartial jury of the State and district wherein the crime shall have been committed, which district shall have been previously ascertained by law, and to be informed of the nature and cause of the accusation; to be confronted with the witnesses against him; to have compulsory process for obtaining witnesses in his favor, and to have the Assistance of Counsel for his defence.</p> <p><b>Amendment VII</b></p> <p>In Suits at common law, where the value in controversy shall exceed twenty dollars, the right of trial by jury shall be preserved, and no fact tried by a jury, shall be otherwise re-examined in any Court of the United States, than according to the rules of the common law.</p> <p><b>Amendment VIII</b></p> <p>Excessive bail shall not be required, nor excessive fines imposed, nor cruel and unusual punishments inflicted.</p> <p><b>Amendment IX</b></p> <p>The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.</p> <p><b>Amendment X</b></p> <p>The powers not delegated to the United States by the Constitution, nor prohibited by it to the States, are reserved to the States respectively, or to the people.</p> <!-- All the XHTML in this file should be correct and it should render properly. --> </body> </html>

I wanted to teach the basic concept of XHTML, because if you program some websites using XHTML, it forces you to be a bit more diligent in your coding. You don't have to use XHTML. I never really use it myself, outside of ebook publishing. But, it's good to understand how it works and what it can be used to accomplish.

And remember, kids, the world owes you nothing... until you create things of value.


Glossary

XHTML

XHTML is an abbreviation for "Extensible Hyper Text Markup Language" and is a more strict/less forgiving version of HTML.


Downloads


Other Articles