A question on the basics of HTML tags.

F

Florent

Hi,

We are having a small discussion about tags in html.
would I be right in saying that the ONLY allowed syntax is
....
<my_tag attrib="name"> and </my_tag>
....
To be more precise, I want to know,
Is these legal html tags "<my_tag>" and "< my_tag >" or are some browsers
forgiving when it comes to the above, (and for closing could I do "< /
my_tag >"?).

Because if both "<my_tag>" and "< my_tag >" are legal/accepted then how
would I enter something like,
....
<my_tag> Hello World this < is allowed in html </my_tag>
....
or even an invalid "<" and more subtle case where it might look like a tag,
(look for the "<is" with no space)
....
<my_tag> Hello World this <is allowed in html </my_tag>
....
Because if some browsers are been too lax then is this fair to say that the
code above might be displayed one way in one browser and differently in
another.

Many thanks for your views. Would there be a site to dispute/verify my
assumption?

Florent
 
D

Dylan Parry

As an authority on the subject, Florent proclaimed:
Is these legal html tags "<my_tag>" and "< my_tag >"

According to the specs, no -- but that doesn't mean that a browser would
treat them as invalid. The best case is to stick to the standards and use
the former.
<my_tag> Hello World this < is allowed in html </my_tag>
^

In this case you would replace the ambiguous "<" with "&lt;" which is the
character code for the the less-than symbol.
 
S

Steve Pugh

We are having a small discussion about tags in html.
would I be right in saying that the ONLY allowed syntax is
...
<my_tag attrib="name"> and </my_tag>
...
To be more precise, I want to know,
Is these legal html tags "<my_tag>" and "< my_tag >" or are some browsers
forgiving when it comes to the above, (and for closing could I do "< /
my_tag >"?).

The start of the element name must follow immediately after the <
So < my_tag > is just text not a tag.

You can have space after the element name and before the >
So <my_tag > is fine.

For closing tags if there is a space after the < then as with opening tags
you have text not a tag. A space between the / and the element name is an
error.
Spaces after the tag name and before the > are fine.
Because if both "<my_tag>" and "< my_tag >" are legal/accepted

They're both legal, but one is a tag and the other is text.
then how would I enter something like,
...
<my_tag> Hello World this < is allowed in html </my_tag>

You could leave it as it is or escape the < as &lt; Your choice.
or even an invalid "<" and more subtle case where it might look like a
tag,
(look for the "<is" with no space)
...
<my_tag> Hello World this <is allowed in html </my_tag>

This is different.
As 'i' is a valid start charcter for an element name the < must be escaped
as &lt; in this case.

Steve
 
F

Florent

The start of the element name must follow immediately after the <
So < my_tag > is just text not a tag.

It makes sense, maybe I should test how browsers would view it.
Is there a set of "official" rules or is it simply accepted?
You can have space after the element name and before the >
So <my_tag > is fine.

It also makes sense.
They're both legal, but one is a tag and the other is text.

Yes, sorry I meant is, is the second one a legal tag.
This is different.
As 'I is a valid start charcter for an element name the < must be escaped
as &lt; in this case.

Yes but "<I>" is legal but how would/should "<I" be interpreted?
following the rules and example above. the tag would become "<is allowed in
html </my_tag>" where the tag is "is" with garbage inside as attributes and

Florent
 
F

Florent

Dylan Parry said:
As an authority on the subject, Florent proclaimed:


According to the specs, no -- but that doesn't mean that a browser would
treat them as invalid. The best case is to stick to the standards and use
the former.

Are those specs freely available? if so where?
^

In this case you would replace the ambiguous "<" with "&lt;" which is the
character code for the the less-than symbol.

It might be ambiguous to rogue browsers but am I right in saying that
according to the specs there is nothing wrong with it the way it is?

Florent
 
S

Steve Pugh

It makes sense, maybe I should test how browsers would view it.

I doubt you'll find many browsers getting this wrong.
Is there a set of "official" rules or is it simply accepted?

The rules are those of SGML as used in the HTML specification.


Yes but "<I>" is legal but how would/should "<I" be interpreted?

The above example has nothing to do with <i>. If it was <the then I would
have said exactly the same thing with 't' instead of 'i' and there is no
following the rules and example above. the tag would become "<is allowed
in html </my_tag>" where the tag is "is" with garbage inside as
attributes and <my_tag> is never closed.

The </ marks the start of an end tag. So the
"<is allowed in html" opening tag is never completed.

Steve
 
R

rf

Florent wrote
Are those specs freely available? if so where?

You are kidding, are you not? You are posting to an HTML group and you don't
know where the HTML specifications are?

I will assume that you are new and you wish to learn... So, here you are:

http://www.w3.org/TR/html4/

Read all of it!


Then read it again.


Then when you have a question (which is likely as the specs are loose) come
back :)
 
B

brucie

In alt.html rf said:
Then when you have a question (which is likely as the specs are loose)

i believe the polite term is "sexually free" not "loose". we don't want
the kiddies picking up unsavory terminology do we.
 
R

rf

brucie said:
In alt.html rf said:
i believe the polite term is "sexually free" not "loose". we don't want
the kiddies picking up unsavory terminology do we.

Hmmm... <looks at specs/>

Property: The house your parents live in, you know, the place where you get
your money and sometimes if you are real lucky the keys to the car.

Attribute: What the owners of the Property try to instill in one. You know:
If you have good attributes you will get a nice job in the Bank across the
road.

Element: Well, they make us learn about those things in physics class don't
they. No use for a job in the Bank though.

Tag: You're it!

Rule: Enough said.
 
F

Florent

You are kidding, are you not? You are posting to an HTML group and you
don't
know where the HTML specifications are?

I didn't know it was a requirement for posting here.
Are there any other obscure rules I should know in the hope of posting here
again?
I will assume that you are new and you wish to learn... So, here you are:

No, I am not new, but thanks anyways.
http://www.w3.org/TR/html4/

Then when you have a question (which is likely as the specs are loose)
come
back :)

So another basic rule for posting here is to already be an expert in html.
Seen that you are posting here I will assume you are yourself an expert and
that you know exactly where the answer to my OP would be in the document.

Florent
 
S

Sam Hughes

I didn't know it was a requirement for posting here.
Are there any other obscure rules I should know in the hope of posting
here again?

You did pay your crystal ball tax, right?
So another basic rule for posting here is to already be an expert in
html. Seen that you are posting here I will assume you are yourself an
expert and that you know exactly where the answer to my OP would be in
the document.

That is not a rule (and my sarcasm detector might be malfunctioning:
forgive me).
 
N

Neal

Hi,

We are having a small discussion about tags in html.
would I be right in saying that the ONLY allowed syntax is
...
<my_tag attrib="name"> and </my_tag>

Essentially, yes.
To be more precise, I want to know,
Is these legal html tags "<my_tag>" and "< my_tag >" or are some browsers
forgiving when it comes to the above, (and for closing could I do "< /
my_tag >"?).

To be a valid tag there must be a legal character after <. Browsers may or
may not be forgiving, depending on their conformance.
Because if both "<my_tag>" and "< my_tag >" are legal/accepted then how
would I enter something like,
...
<my_tag> Hello World this < is allowed in html </my_tag>
...
or even an invalid "<" and more subtle case where it might look like a
tag,
(look for the "<is" with no space)
...
<my_tag> Hello World this <is allowed in html </my_tag>

I never include < or > (or &) in HTML as text as a rule. If I need those
characters I "escape" them with &lt; and &gt; (and &amp;) respectively.
This is the safe route.

Compare to attribute values. Sometimes you don't need to quote them, but
it's never wrong to, and it's far easier to always quote than to memorize
when you can leave the quotes out. Same here. There may well be times when
< will work as text, but best to avoid the mess by using the other form.

W3C links to this page for more info about SGML:
[http://www.iso.org/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=16387]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top