Avoid six common HTML5 errors (5-6 )-

Source: Internet
Author: User
5. Do not use unnecessary type attributes. This is a common problem, but it is not an error. I think we should avoid this style through best practices. In HTML5, the type attribute is no longer required for script and style elements. However, these are likely to be automatically added by your CMS, so you need to remove them ...,. Avoid six common HTML5 errors (5-6) 5. Do not use unnecessary type attributes

This is a common problem, but it is not a mistake. I think we should avoid this style through best practices.

In HTML5, the type attribute is no longer required for script and style elements. However, these are likely to be automatically added by your CMS, so removing them is not that easy. However, if you are manually coding or you have full control over your template, there is no reason to include the type attribute. All browsers think that scripts are javascript and styles are css. You don't have to do this any more.

View sourceprint? 1
 2
 3Script


In fact, you only need to write as follows:

view sourceprint?1    
      2    《script》

Even the code of the specified character set can be omitted. Mark Pilgrim explained in the semantic chapter of Dive into HTML5.

6. incorrect use of the form attribute

HTML5 introduces some new form attributes. The following are precautions for use:

Boolean attribute

Some multimedia elements and other elements also have a Boolean attribute. The rules mentioned here also apply.

Some new form attributes are Boolean, which means that as long as they appear in the tag, the corresponding behavior has been set. These attributes include:

  • Autofocus

  • Autocomplete

  • Required

Frankly speaking, I seldom see this. Taking required as an example, the following is common:

1
 23
 4


Strictly speaking, this is not a serious problem. As long as the browser's HTML Parser sees that the required attribute appears in the tag, its function will be applied. But what if you write equired = "false" in turn?

1
 2

The parser will still regard the required attribute as valid and execute the corresponding behavior, even though you try to tell it not to execute it. This is obviously not what you want.

There are three effective ways to use the Boolean attribute. (The last two types are only valid in xthml)

  • Required

  • Required = ""

  • Required = "required"

The correct example is as follows:

 

The above is to avoid the common six HTML5 error usage (5-6) content. For more information, see PHP Chinese website (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.