Rules of HTML5

Rules of HTML5

The rules of HTML5 are simple.Visual Studio helps you to show a list of errors and suggestions for how to fix them.

a. Close the Elements

Most elements in HTML must be closed. So when you start with a <div> tag, you must use </div> somewhere later in your page. In HTML5, these tags can be written as self-closing tags, where the closing slash is embedded directly in the tag itself as in <img src=”Logo.gif” /> or &lbr /&g.

b. Usage of Attributes

Whenever you write an attribute in a tag, you can write the value inside the double quotes, single quotes, or no quotes at all.

For example, when writing the <img> tag and its src attribute, you can write it like this:

<img src=”Logo.jpg” />

You could also use single quotes to enclose the attribute value, like this:

<img src=’Logo.jpg’ />

Both options work, as long as you use the same type of quote on both ends of the value.

It is also sometimes necessary to nest single and double quotes. For example, when some special ASP.NET syntax requires the use of double quotes, you should use single quotes to wrap the attributes.

<asp: Label ID=”TitleLabel” runat=”server” Text='<%# Eval (“Title”) %>’ />

c. Nest the Elements Correctly

When you write nested elements, make sure that you first close the inner element you opened last, and then close the outer element.

<strong><em>This is some formatted text</em></strong>

d. Add a DOCTYPE Declaration to the Page

A DOCTYPE gives the browser information about what kind of HTML it can expect.Visual Studio adds a DOCTYPE for HTML5 to the page.

<<! DOCTYPE html>

The DOCTYPE greatly influences the way browsers like Internet Explorer render the page, so if you are seeing odd behavior on your page, check that your page has the correct DOCTYPE. Here we will give you an example of HTML5 which contains the updated elements and attributes.

Scroll to Top