简体   繁体   中英

Site validation throws an error: there is no attribute “DATA-BG”

Validating my website under development, which can be viewed here , I'm receiving the error message: Line 92, Column 32: there is no attribute "DATA-BG". I'm using data-attributes like this throughout my site:

<div class="sbi_panel" data-bg="slider/images/4.jpg">

So, the data-bg attibute is not recognised. I'd like to know what is wrong here?

The problem is your DOCTYPE , which is currently set as:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

The W3C validator looks at the DOCTYPE declaration when determining what type of validation to perform. HTML attributes that begin data- are an HTML5 idea, so you'll need to change your DOCTYPE to HTML5 so it validates as correct.

The data- attributes are not allowed according to HTML 4.01 doctype, or any a published doctype, This has no impact on their functionality; it is just a syntactic matter.

Options:

  1. Just ignore the message. This gets impractical if you have loads of such attributes, because then the amount of these messages makes it difficult to detect real markup errors.
  2. Construct a custom DTD that allows the data- attribute(s) that you are using. The W3C shouts against the idea , but the real problem with it is that most people don't want to get involved in DTDs, and it takes some learning to edit a DTD. In this case, you would just add your attribute(s) to the coreattrs attributes. You would need to add each data- attribute separately.
  3. Change to the HTML5 doctype statement, <!doctype html> . This make all data- attributes allowed, but it also implies restrictions in other areas. HTML5 is not a pure extension on HTML 4.01; for example, it declares most kinds of meta tags invalid (and although most meta tags are useless, you may have some that are useful but not allowed in HTML5 at present).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM