Syntax of code in HTML5.


 

Syntax of code in HTML5.

In this section, you will see the syntax of code in HTML5.

In this section, you will see the syntax of code in HTML5.
The Use of SVG and MathML

Syntax of code in HTML5.

HTML5 defines an HTML syntax compatible with HTML4 and XHTML1 documents but not compatible with SGML features of HTML4 like processing instructions and shorthand markup. The documents that use HTML syntax are almost always served with the text/html media type. Moreover HTML5 also defines detailed parsing rules include error handling for the syntax that are mostly compatible with popular implementations.

Here is the example of HTML5 Syntax:
<!DOCTYPE html>
<html>
<head>
<title>Title of document.</title>
</head>
<body>
<p><strong>Syntax of HTML5 program.</strong></p>
</body>
</html>

A text/html-sandboxed media type for documents can also be defined using HTML syntax in HTML5. This is used when hosting untrusted content.

HTML5 also uses XML syntax that is compatible with XHTML1 documents and implementations. Documents using this syntax need to be served with an XML media type such as application/xhtml+xml or application/xml.

See the example:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.roseindia.net/">
<head>
<title>Title of document</title>
</head>
<body>
<p>Example of syntax that can be use HTML.</p>
</body>
</html>

Character Encoding:

The authors of HTML5 has set the three means of character encoding for the syntax of HTML5:

· At the transport level. By using the HTTP Content-Type header for instance.
· Using a Unicode Byte Order Mark (BOM) character at the start of the file. This character provides a signature for the encoding used.
· Using a Meta element with a charset attribute that specifies the encoding within the first 512 bytes of the document. E.g. Instead of using <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">, use <meta charset="UTF-8"> for specifying UTF-8 encoding. However, the previous one is also allowed.

To set the character encoding for the XML syntax, authors will have to follow the rules as set forth in the XML specifications.

MathML and SVG:


The MathML refers to Math Markup Language while SVG stands for Scalable Vector Graphics. Both the elements are allowed to be used inside a document in HTML syntax of HTML5.

 See the example:
<!doctype html>
<title>The Use of SVG and MathML</title>
<p>
<b>A rectangle.</b>
<svg>
<rect x="60" y="20" height="160" width="260" fill="#FFCCCC" /> </svg>
</p>

Note: See the browser compatible page for successfully rendering the program.

This is the simplest use of SVG and MathML, while more complex combinations can also be used. With the use of SVG foreignObject element, MathML and HTML, or both can be nested inside an SVG fragment that is itself inside HTML.

 

Ads