views:

179

answers:

4

Do labels that I create for my form elements need to be in the <form> body? for example would this be compliant:

<div style="display: none;">
    <label for="somename">Some Name</label>
    <!-- more labels.. //-->
</div>

<!-- insert lots of HTML here //-->

<form>
<input type="text" name="somename" id="somename">
<!-- insert more elems here //-->
</form>
A: 

If anyone is wondering, I installed Thunder screenreader and the format i provided above is perfectaly accessable.

+1  A: 

In general, the tag doesn't really provide much semantic meaning unless you happen to have more than 1 form on a page, in which case the form tag indicates what form elements it is associated with.

That being said, tags also do not depend on their location because they are tied to 1 and only 1 other element by that element's ID, so no, it doesn't matter where you put it in relation to the element it is a label for, but it is usually good practice to keep the label near the element. I would question the semantic validity of your page if it drifts too far from the element it describes, and making sure your document is semantic is a key component of being accessible. 508 does only require a best-effort for accessibility, but few and far between are the cases where having a semantic document is too hard to do.

cdeszaq
are labels even REQUIRED for 508? All of our form elements are 'labeled' but do not use label tags, the screen reader still picks up the label even if it is not in a label tag...
Since 508 is very vague, and more written with applications (rather than websites) in mind, there are no real requirements for it, other than that you make a best-effort to make your site as acessible as possible, both to sight-impaired people, as well as all other dissabilities. What this means is that while having explicit labels for input elements is not REQUIRED, it makes your page much more semantic, and a more semantic page is more accessible. That said, screen readers will often be able to better interpret forms if elements have explicit labels (elements), rather than implicit text ones
cdeszaq
A: 

you can also use

<label class="hideme" for="blah">blah blah</blah>

where

.hideme {
    display: none;
}
amit patel
Unfortunately, some screen readers will not "display" (or read in this case) elements that are hidden using "display: none;" for the element style. A safer way is to absolutely position the element WAY off the screen.
cdeszaq
+1  A: 

No. Ideally they'd be right next to the element they're related to, but they don't have to be. It is true the 508 standards seem vague; some of that is because there's more than 1 level of compliance you can try to match. I always found the Priority 1 508 compliance to be frustratingly low. You could get away with most anything. The two things I always tried to do (at a minimum) were

  1. Run the site or pages through a checker
  2. Look at the site in a text-only browser

I think the second step made me a better developer of accessible websites than the first because it became obvious that some common things were frustrating (e.g., having a huge block of navigation links at the top of every page without at least some way to skip them). If you're already checking your sites in a screenreader, you're probably ahead of the game.

Tom