xhtml| Beginners | tutorials | grammar
Writing XHTML code requires pure HTML syntax.
-
More XHTML Syntax rules:
-
- Property name must be lowercase
- Attribute values must be quoted
- Attribute cannot be abbreviated
- Replace the Name property with the id attribute
- The XHTML DTD defines the HTML elements that are forced to use
Property name must be lowercase
This is wrong:
WIDTH
= "100%" >
That's right:
width
= "100%" >
Attribute values must be quoted
This is wrong:
<table width= 100%
>
That's right:
<table width= "100%"
>
Attribute cannot be abbreviated
This is wrong:
<input checked><input readonly><input disabled><option selected><frame noresize>
That's right:
<input checked= "Checked"/><input readonly= "readonly"/><input disabled= "disabled"/><option Selected= "selected"/><frame noresize= "noresize"/>
The following is a list of shorthand attributes for HTML, and a rewrite in XHTML:
HTML |
XHTML |
Compact |
compact= "Compact" |
Checked |
Checked= "Checked" |
Declare |
Declare= "DECLARE" |
ReadOnly |
readonly= "ReadOnly" |
Disabled |
disabled= "Disabled" |
Selected |
Selected= "Selected" |
Defer |
Defer= "Defer" |
Ismap |
ismap= "Ismap" |
Nohref |
nohref= "Nohref" |
NoShade |
Noshade= "NoShade" |
NoWrap |
nowrap= "NoWrap" |
Multiple |
Multiple= "multiple" |
Noresize |
Noresize= "Noresize" |
Replace the Name property with the id attribute
HTML 4.01 defines the name attribute for the following elements: A, applet, frame, iframe, IMG, and map.
The use of the Name property is discouraged in XHTML and should be replaced with an ID.
This is wrong:
name
= "Picture1"/>
That's right:
id
= "Picture1"/>
Important Compatibility Tips:
You should add an extra space before the "/" symbol to make your XHTML compatible with today's browsers.
Language Properties (Lang)
The lang attribute applies to almost all XHTML elements. It defines the type of language in which the content inside the element is used.
If you use the lang attribute in an element, you must add an extra Xml:lang, like this:
lang="no" xml:lang="no"
>heia norge!</div>
The XHTML element that is forced to use
All XHTML documents must have a file type declaration (DOCTYPE declaration). The HTML, head, and body elements must exist in the XHTML document, and the title element must be located in the head element.
The following is a minimized XHTML file Template:
<!DOCTYPE Doctype goes here>
Tip: File type declarations are not part of the XHTML document itself. It is not an XHTML element, and there is no closing tag.
Hint: it is necessary to,
You'll learn more about XHTML document type declarations in the next chapter.