HTML and XHTML
XHTML is HTML written in XML language.
What is XHTML ?
- XHTML stands for Extensible HyperText Markup Language (Extended Hypertext Markup Language)
- XHTML is similar to HTML
- XHTML has stricter rules than HTML
- XHTML is HTML defined as an XML application
- XHTML is supported by most popular browsers
Why use XHTML?
Many sites on the Internet contain 'very bad' HTML, although they do not follow HTML rules but still work on many browsers. The following is an example of a non-compliant HTML paragraph, but still works.
HTML không đúng quy định
'Bad' HTML
Network administrator.
Today there are many browser technologies, which can run on computers, phones or other small devices. These small devices often lack the resources or the power to translate 'bad' markups.
XHTML is a markup language in which documents must be properly marked, developed by combining the power of both HTML and XML.
Important differences between HTML and XHTML
Text structure
- XHTML DOCTYPE is required
- The xmlns attribute in the tag
is required.
- Tags
,,
andis required.
Elements in XHTML
- Elements in XHTML must be properly nested.
- Elements in XHTML must always be closed.
- Elements in XHTML must be lowercase.
- Elements in XHTML must have a root element.
Properties in XHTML
- Attribute names must be in lowercase.
- Attribute value must be in quotation marks.
- It is forbidden to simplify attributes.
is required
XHTML text must contain XHTML DOCTYPE declaration.
Must have elements ,,
and , xmlns attribute in the tag
must specify xml space for text. The example below shows XHTML text with minimum required tags.
"https://quantrimang.com/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Tiêu đề văn bản
nội dung
XHTML elements must be properly nested
In HTML, some elements can be nested within the same way as the example below.
Văn bản in đậm và in nghiêng
But in XHTML, all elements must be properly nested, as in the example below.
Văn bản in đậm và in nghiêng
XHTML elements must always be closed
Writing as below is wrong
Paragraph 1
Paragraph 2
It must be this:
Paragraph 1
Paragraph 2
Empty elements must also be closed
As the example below is invalid.
Ngắt dòng:
Đường nằm ngang:
Hình ảnh:
Which must write as below.
Ngắt dòng:
Đường nằm ngang:
Hình ảnh:
Elements in XHTML must be written in lowercase
Writing as below is wrong.
Paragraph
Which must write lowercase as below.
Paragraph
Attribute names in XHTML must be written in lowercase
Do not write
but must write
Attribute value must be in quotation marks
Do not write but must write
Do not simplify attributes
False
It's correct
False
It's correct
How to convert from HTML to XHTML
- Add XHTML to the first line of each page
- Add xmlns attribute to the html element of each page
- Change all element names to lower case
- Close all empty elements
- Change all attribute names to lower case
- Put a quote on all attribute values
Previous article: Uniform Resource Locators in HTML
The following article: Form in HTML
You should read it
May be interested
- Text in HTMLthe element in html is used to define a paragraph of text.
- How to Use Text Color Tags in HTMLthis article explains how to change the font color in html documents. although the html style tag is obsolete in html5, you can use css to color content on an html page. if you use an older version of html, you can use the html text color tag as needed.
- Format text in HTMLformat elements in html help determine the style and importance of text.
- Elements in HTMLthe html element usually goes in pairs, including the opening tag, closing tag, and the content inside the two tags.
- Symbol - Icon in HTMLhtml has many mathematical, technical and monetary symbols that cannot be used to write.
- Common HTML mistakes that you should avoid for better web programminglearning html is not difficult, but when running it in the browser, errors often occur. here are common html errors and how to handle them for better web development.
- How to insert spaces in HTMLthis tutorial explains how to insert spaces and line breaks in html. because no matter how many times you type a space, html will display a space so to insert more than one space, you will need to use the html tag.
- Image img in HTMLwhen you visit the website, you will often see images of all sizes and positions on the page. images in html web pages will help to enrich the content as well as increase the aesthetics of the page.
- Attributes in HTMLproperties are used to add information to elements in html.
- The id attribute in HTMLin html, the id attribute is used to specify a unique id for an html element (the value must be unique in the html file).