spaces in names and id's

Discussion in 'HTML' started by Jeff Thies, Jun 10, 2004.

  1. Jeff Thies

    Jeff Thies Guest

    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
     
    Jeff Thies, Jun 10, 2004
    #1
    1. Advertising

  2. Jeff Thies

    rf Guest

    "Jeff Thies" <> wrote in message
    news:tyPxc.4468$...
    > 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.
     
    rf, Jun 10, 2004
    #2
    1. Advertising

  3. Jeff Thies

    Jeff Thies Guest

    "rf" <> wrote in message
    news:eKPxc.64$...
    >
    > "Jeff Thies" <> wrote in message
    > news:tyPxc.4468$...
    > > 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
    >
    > Cheers
    > Richard.
    >
    >
     
    Jeff Thies, Jun 10, 2004
    #3
  4. Jeff Thies

    Stan McCann Guest

    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?


    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
     
    Stan McCann, Jun 10, 2004
    #4
  5. rf wrote:
    > Jeff Thies wrote:

    <snip>
    >> 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.
     
    Richard Cornford, Jun 10, 2004
    #5
  6. "Jeff Thies" <> wrote:

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

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html
     
    Jukka K. Korpela, Jun 10, 2004
    #6
  7. Jeff Thies

    Andy Dingley Guest

    "Jeff Thies" <> wrote in message news:<tyPxc.4468$>...

    > 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.
     
    Andy Dingley, Jun 10, 2004
    #7
  8. Jeff Thies wrote:
    > 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

    --
    Mvh Magnus Haugsand
     
    Magnus Haugsand, Jun 10, 2004
    #8
  9. Jeff Thies

    Jeff Thies Guest

    <snip>

    >
    > 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
    >
    > --
    > Mvh Magnus Haugsand
     
    Jeff Thies, Jun 10, 2004
    #9
  10. Jeff Thies wrote:
    > <snip>
    >
    >>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


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

    --
    Mvh Magnus Haugsand
     
    Magnus Haugsand, Jun 10, 2004
    #10
  11. Magnus Haugsand wrote:

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


    Not sure about IE 5, but certainly IE 6 as well as decent browsers.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me - http://www.goddamn.co.uk/tobyink/?page=132
     
    Toby A Inkster, Jun 10, 2004
    #11
  12. Magnus Haugsand wrote:

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

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me - http://www.goddamn.co.uk/tobyink/?page=132
     
    Toby A Inkster, Jun 10, 2004
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John B. Matthews
    Replies:
    4
    Views:
    682
    John B. Matthews
    Sep 12, 2008
  2. Roedy Green
    Replies:
    3
    Views:
    642
  3. Tomasz Chmielewski

    [CSS] how can I show spaces as spaces?

    Tomasz Chmielewski, Sep 5, 2009, in forum: HTML
    Replies:
    21
    Views:
    1,638
    Jan C. Faerber
    Sep 10, 2009
  4. Tomasz Chmielewski

    how can I show spaces as spaces, part 2

    Tomasz Chmielewski, Sep 9, 2009, in forum: HTML
    Replies:
    14
    Views:
    895
    Jan C. Faerber
    Sep 10, 2009
  5. johkar
    Replies:
    2
    Views:
    2,965
    Mayeul
    Dec 10, 2009
Loading...

Share This Page