Browser behavior with unknown tags or attributes?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


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'>



and to my surprise instead of ignoring the <mytag> and </mytag>
alltogether and showing the <h3> content, the browser did not display
the content between <mytag> and </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?



Re: Browser behavior with unknown tags or attributes?

Scripsit fjanon:

Quoted text here. Click to load it

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 <DIV> element 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

Quoted text here. Click to load it

Which browser, for which specific test document? (The DOCTYPE declaration
might matter; probably it doesn't, but still you should specify a full

Anyway, the practice described in the HTML 2.0 spec means that the <mytag
...> and </mytag> tags 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.

Quoted text here. Click to load it

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.

Quoted text here. Click to load it

Now you know, and this should imply that you start looking at some other

Of course, if you intend to use _widely supported_ de facto extensions, such
as <embed> or <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

Jukka K. Korpela ("Yucca")

Re: Browser behavior with unknown tags or attributes?

fjanon wrote:

Quoted text here. Click to load it

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.

Re: Browser behavior with unknown tags or attributes?

Scripsit Andy Dingley:

Quoted text here. Click to load it

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

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")

Re: Browser behavior with unknown tags or attributes?

fjanon wrote:
Quoted text here. Click to load it

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

Concerned about someone (e.g., Pres. Bush) snooping
into your E-mail?  Use PGP.
See my <

Re: Browser behavior with unknown tags or attributes?

David E. Ross:

Quoted text here. Click to load it


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)


Site Timeline