spaces in names and id's

J

Jeff Thies

I have image names with spaces in them. Is that likely to cause any trouble?

<img src="x.gif" name="about us" id="foo bar">

I'm writing a little rollover code (first time for everything) and from my
bit of testing, spaces in image names seems to be fine. I'm pretty sure that
spaces in ID's is no good, at least it would be for setting styles. I know
that spaces in form names is OK. Is that about right?

Cheers,
Jeff
 
R

rf

Jeff Thies said:
I have image names with spaces in them. Is that likely to cause any trouble?

<img src="x.gif" name="about us" id="foo bar">

I'm writing a little rollover code (first time for everything) and from my
bit of testing, spaces in image names seems to be fine. I'm pretty sure that
spaces in ID's is no good, at least it would be for setting styles. I know
that spaces in form names is OK. Is that about right?

The specifications:

http://www.w3.org/TR/html4/types.html#type-cdata

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed
by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"),
colons (":"), and periods (".").

I don't see space mentioned anywhere there.

Cheers
Richard.
 
J

Jeff Thies

rf said:
Jeff Thies said:
I have image names with spaces in them. Is that likely to cause any trouble?

<img src="x.gif" name="about us" id="foo bar">

I'm writing a little rollover code (first time for everything) and from my
bit of testing, spaces in image names seems to be fine. I'm pretty sure that
spaces in ID's is no good, at least it would be for setting styles. I know
that spaces in form names is OK. Is that about right?

The specifications:

http://www.w3.org/TR/html4/types.html#type-cdata

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed
by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"),
colons (":"), and periods (".").

I don't see space mentioned anywhere there.

So it is.

I can't tell you how many forms that I've seen with spaces in the form
names. I've always replaced them with underscores when I caught them. But
that was just my personal preference rather than a desire to do right!


Thanks,
Jeff
 
S

Stan McCann

Jeff said:
I'm writing a little rollover code (first time for everything) and from my
bit of testing, spaces in image names seems to be fine. I'm pretty sure that
spaces in ID's is no good, at least it would be for setting styles. I know
that spaces in form names is OK. Is that about right?

Best not to use spaces for any of those things. While spaces may work
in one instance, they may not work in another.

--
Stan McCann
Webmaster/Computer Center Manager, NMSU at Alamogordo
Cooordinator, Tularosa Basin Chapter, ABATE of NM AMA#758681
'94 1500 Vulcan (now wrecked) :( http://surecann.com/Dcp_2068c.jpg
A zest for living must include a willingness to die. - R.A. Heinlein
 
R

Richard Cornford

rf said:
Jeff Thies wrote:
I'm writing a little rollover code (first time for everything) and
from my bit of testing, spaces in image names seems to be fine. I'm
pretty sure that spaces in ID's is no good, at least it would be for
setting styles. I know that spaces in form names is OK. Is that
about right?

The specifications:

http://www.w3.org/TR/html4/types.html#type-cdata

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
followed by any number of letters, digits ([0-9]), hyphens ("-"),
underscores ("_"), colons (":"), and periods (".").

I don't see space mentioned anywhere there.

ID tokens apply to ID attributes, NAME tokens apply to NAME attributes
on META elements only. NAME attributes on IMG are specified as CDATA and
may contain spaces (there is some mention in the CDATA section of the
spec about UAs optionally trimming leading and trailing spaces from
CDATA so they may not be a good idea in a NAME attribute).

Space characters (and many others) would require additional care if the
corresponding elements were to be scripted, but that just involves using
the correct accessor syntax.

Richard.
 
J

Jukka K. Korpela

Jeff Thies said:
I can't tell you how many forms that I've seen with spaces in the form
names.

But that's a different issue. You asked about name and id attributes in
img elements.

The name attribute is actually very polymorphic - i.e., it has different
rules in different elements, or the name attributes in different elements
are really _different attributes_ which just incidentally share the same
name.

In _form fields_, the name attribute may (and often needs to) contain
just about anything. Spaces are no problem.

In <img> and <form> elements, the name attribute is not needed except for
certain modes of JavaScript coding and is not even allowed in all
versions of HTML. What you can put there if you use it depends on
JavaScript more than anything else.

The id attribute must by definition have a unique value of type ID, which
sets very strict syntax rules.

The name attribute in <a> may contain any string from the HTML
perspective, but since it is used for the purpose of using it in a
fragment identifier, it's best to stick to simple syntax, e.g. no spaces.
In theory, if you use <a name="foo bar">, you can then use
href="#foo%20bar" (i.e., with the space as URL encoded), but this is
clumsy, odd-looking, and not supported by all browsers.
 
A

Andy Dingley

Jeff Thies said:
I have image names with spaces in them. Is that likely to cause any trouble?

<img src="x.gif" name="about us" id="foo bar">

What's a "name" ?

This examples looks as if you mean a human-readable "title" for the
image, so you'd be better putting that into the title attribute. This
can use whatever characters you like, subject to basic HTML encoding
rules (i.e. quote characters, angle brackets and ampersands are an
issue, but not spaces)

The name and id attributes are not intended for humans, they're
machine identifiers. These have tighter naming rules (read the specs)
and you certainly can't embed spaces.

Filenames and URLs should avoid spaces. They're permitted, but you
need to use the appropriate encoding to represent them. Browsers are
generally roubust here, so you can do things that are definitely wrong
and they'll still work, but it's bad practice and they might not
always work in all circumstances.
 
M

Magnus Haugsand

Jeff said:
I have image names with spaces in them. Is that likely to cause any trouble?

<img src="x.gif" name="about us" id="foo bar">

I'm writing a little rollover code (first time for everything) and from my
bit of testing, spaces in image names seems to be fine. I'm pretty sure that
spaces in ID's is no good, at least it would be for setting styles. I know
that spaces in form names is OK. Is that about right?

Cheers,
Jeff

I do not now if the same applies to id, but class="foo bar" decides that
the element is both .foo and .bar
 
J

Jeff Thies

I do not now if the same applies to id, but class="foo bar" decides that
the element is both .foo and .bar

Really? What is the level of support for it? That could be usefull.

Jeff
 
M

Magnus Haugsand

Jeff said:
Really? What is the level of support for it? That could be usefull.

Jeff

I think even IE 5 supports it, but I am not sure if NS4 nor IE4 does.
 
T

Toby A Inkster

Magnus said:
I do not now if the same applies to id, but class="foo bar" decides that
the element is both .foo and .bar

Doesn't apply to IDs. An element can only have one ID.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top