By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,960 Members | 1,009 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,960 IT Pros & Developers. It's quick & easy.

Browser behavior with unknown tags or attributes?

P: n/a
Hi,

I went through the HTML spec without finding the description of what
the browsers behavior should/must be regarding tags or attributes they
don't understand. I did a quick experiment like this:

<mytag style='display:none'>

<h3>Hello</h3>

</mytag>

and to my surprise instead of ignoring the <mytagand </mytag>
alltogether and showing the <h3content, the browser did not display
the content between <mytagand </tag>.

I am working on having some proprietary tags and I need to know what
the specs say about non standard tags.

Any idea of where it is specified?

Thanks

Fred

Sep 29 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Scripsit fjanon:
I went through the HTML spec without finding the description of what
the browsers behavior should/must be regarding tags or attributes they
don't understand.
The good old HTML 2.0 specification is a great improvement over its
successors in this area, too. It said:

"4.2.1. Undeclared Markup Error Handling

To facilitate experimentation and interoperability between
implementations of various versions of HTML, the installed base of
HTML user agents supports a superset of the HTML 2.0 language by
reducing it to HTML 2.0: markup in the form of a start-tag or end-
tag, whose generic identifier is not declared is mapped to nothing
during tokenization. Undeclared attributes are treated similarly. The
entire attribute specification of an unknown attribute (i.e., the
unknown attribute and its value, if any) should be ignored. - -
- -
Support for notifying the user of such errors is encouraged.

Information providers are warned that this convention is not binding:
unspecified behavior may result, as such markup does not conform to
this specification."

(If you read the full story in the HTML 2.0 spec, with examples, note that
there was no <DIVelement in HTML 2.0.)

Of course, this wasn't _rigorous_, and it's basically descriptive, not
prescriptive (normative); and the idea of notifying users was never
implemented. It's still better than the sloppier prose in HTML 3.2 and HTML
4 specs and formal vagueness in XHTML. (People often say that XHTML does not
tolerate any syntax errors, and they regard this is a key benefit. However,
browsers aren't required to have validating parsers.)

What HTML 4.01 says about the issue is the (non-normative) clause B.1, see
http://www.w3.org/TR/html401/appendi...s-invalid-docs
<mytag style='display:none'>

<h3>Hello</h3>

</mytag>

and to my surprise instead of ignoring the <mytagand </mytag>
alltogether and showing the <h3content, the browser did not display
the content between <mytagand </tag>.
Which browser, for which specific test document? (The DOCTYPE declaration
might matter; probably it doesn't, but still you should specify a full
example.)

Anyway, the practice described in the HTML 2.0 spec means that the <mytag
....and </mytagtags are ignored, and this is what the HTML 4.01 spec
really _means_ in this context. Other processing would indeed be surprising
and undesirable, but technically not wrong. Your document is not an HTML
document, so an HTML user agent may do anything it likes with it, as far as
HTML specs are concerned.
I am working on having some proprietary tags
Well, stop right now and solve the original problem by some other means. If
you need help with the original problem, it might help if you gave a hint of
what the original problem is.
and I need to know what
the specs say about non standard tags.
Now you know, and this should imply that you start looking at some other
direction.

Of course, if you intend to use _widely supported_ de facto extensions, such
as <embedor <nobr>, then the practical question is how widely and how
consistently supported they are and what browsers actually do if they don't
support them. You might even try and make an educated guess on how long the
extensions will be supported; this tends to depend on how widely known and
used the extension is. The specifications are not useful in such an
analysis.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Sep 29 '06 #2

P: n/a

fjanon wrote:
I went through the HTML spec without finding the description of what
the browsers behavior should/must be regarding tags or attributes they
don't understand.
Browsers are reliable at safely ignoring unknown attributes.

Their behaviour with unknown tags is variable. You seem to have found
one that ignored the tag itself, but still recognised the attached
CSS. It's hard to say that this is strictly "wrong" (or strictly right
either!), but it's certainly not coding style that should be encouraged.

Sep 29 '06 #3

P: n/a
fjanon wrote:
Hi,

I went through the HTML spec without finding the description of what
the browsers behavior should/must be regarding tags or attributes they
don't understand. I did a quick experiment like this:

<mytag style='display:none'>

<h3>Hello</h3>

</mytag>

and to my surprise instead of ignoring the <mytagand </mytag>
alltogether and showing the <h3content, the browser did not display
the content between <mytagand </tag>.

I am working on having some proprietary tags and I need to know what
the specs say about non standard tags.

Any idea of where it is specified?

Thanks

Fred
If you create your own tags and elements, what do you expect a
widespread, specification-compliant browser to do? The browser
recognizes those tags defined in the W3C specifications. How is it to
recognize and understand your proprietary tags that are not defined in
the specifications. Where will the browser get the tag definition?

More important, if you create Web pages using your proprietary tags how
do you expect your audience to view your pages? The key is "graceful
degradation". This means that the text of the page might still be
displayed but without a layout that reflects the Web author's intended
formatting. However, embedding a recognized element within an
unrecognized, proprietary element (as you have done) could result in
completely hiding the former without regard for CSS styles.

In the end, if a Web page is not compliant with the W3C specifications,
how it is displayed by a compliant browser cannot be predicted. The
GIGO rule applies: garbage in = garbage out.

--

David E. Ross
<http://www.rossde.com/>

Concerned about someone (e.g., Pres. Bush) snooping
into your E-mail? Use PGP.
See my <http://www.rossde.com/PGP/>
Sep 29 '06 #4

P: n/a
David E. Ross:
If you create your own tags and elements, what do you expect a
widespread, specification-compliant browser to do?
Exactly.

While the spec doesn't specify how user agents SHOULD or MUST recover
from errors, it does say (informatively):

| If a user agent encounters an element it does not
| recognize, it should try to render the element's content.
| ...
| We also recommend that user agents provide support
| for notifying the user of such errors.
|
| Since user agents may vary in how they handle error
| conditions, authors and users must not rely on specific
| error recovery behavior.

(sec. B.1)

--
Jock

Sep 29 '06 #5

P: n/a
Scripsit Andy Dingley:
Browsers are reliable at safely ignoring unknown attributes.
You cannot really guarantee that. The specifications impose no requirements,
and what browsers commonly do does not make them reliable; the next version
may be different.

There are at least three reasons why you cannot rely on them ignoring
unknown attributes:

1) Future specifications may add atributes, possibly with semantics
different from the meaning that you expect your nonstandard attributes to
have.

2) An "unknown" attribute might not be unknown to a browser. It might
recognize it as an extended feature, possibly in a meaning different from
yours. Different browsers may well do this differently.

3) Some browsers might actually implement the originally recommended idea,
and the "modern" XMLish idea, of reporting an error to the user when there
are syntax errors.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Sep 29 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.