These forums are currently read-only due to receiving more spam than actual discussion. Sorry.

It is currently Sat Dec 02, 2017 4:13 pm Advanced search

which is more semantic? (for the purpose of screen readers)

If you are stuck or have questions regarding HTML or other Web technologies, ask your questions here. No question too dumb!

which is more semantic? (for the purpose of screen readers)

Postby nathan.russell » Tue Feb 08, 2011 9:43 am

Hi,
I wonder if anyone can offer some gems of wisdom :)
I am working on a site which needs to meet WCAG 2.0. Its a forms based site where the user needs to answer some questions.

Each question is presented in a row with 'columns', where the question text is on the left, followed by an optional help icon/link, an optional mandatory character, and then the answer field. The anwser may have an optional prefix character (eg: a £ sign). If the user has sumbitted the form and the field is in error, an error message is displayed spanning all columns.

(If my description above sounds very 'tabular' - thats because the site used to use tables for layout :( Its all been changed now in favour of divs but not with any real view as to changing the markup structure. I am looking to see if we can improve things further)

So, the div based code for a given question is:
Code: Select all
<div id="row_request_risk_proposerDetails_personalDetails_title" class="row">
   <div id="err_request_risk_proposerDetails_personalDetails_title" class="errorRow hidden">
   </div>
   <div id="label_request_risk_proposerDetails_personalDetails_title" class="question">
      <label for="request_risk_proposerDetails_personalDetails_title">Title</label>
   </div>   
   <div id="help_request_risk_proposerDetails_personalDetails_title" class="help">
   </div>
   <div id="mand_request_risk_proposerDetails_personalDetails_title" class="mandatory">
   </div>
   <div id="prfx_request_risk_proposerDetails_personalDetails_title" class="prefix">     
   </div>
   <div id="fld_request_risk_proposerDetails_personalDetails_title" class="answer">
      <select id="request_risk_proposerDetails_personalDetails_title" name="request.risk.proposerDetails.personalDetails.title" saved_disabled_attr="false">
         <option value="">Please select</option>
         <option value="DR">Dr</option>
         <option value="MISS">Miss</option>
         <option value="MR">Mr</option>
         <option value="MRS">Mrs</option>
         <option value="MS">Ms</option>     
      </select>
   </div>
   <div id="reset_request_risk_proposerDetails_personalDetails_title" class="reset"></div>   
</div>


The above validates to WCAG 2.0 AAA (http://achecker.ca/checker/index.php) but we are using a lot of structural markup (divs) as content containers.
I am wondering if we can make it more semantic. Something like this:
Code: Select all
      <div id="row_request_risk_proposerDetails_personalDetails_title" class="row">
         <p id="err_request_risk_proposerDetails_personalDetails_title" class="errorRow hidden">
         </p>
         <p id="label_request_risk_proposerDetails_personalDetails_title" class="question">
            Title
         </p>   
         <p id="help_request_risk_proposerDetails_personalDetails_title" class="help">
         </p>
         <p id="mand_request_risk_proposerDetails_personalDetails_title" class="mandatory">
         </p>
         <fieldset>
            <legend>Title</legend>
            <span id="prfx_request_risk_proposerDetails_personalDetails_title" class="prefix">     
            </span>
            <select id="request_risk_proposerDetails_personalDetails_title" name="request.risk.proposerDetails.personalDetails.title">
               <option value="">Please select</option>
               <option value="DR">Dr</option>
               <option value="MISS">Miss</option>
               <option value="MR">Mr</option>
               <option value="MRS">Mrs</option>
               <option value="MS">Ms</option>     
            </select>
            <label for="request_risk_proposerDetails_personalDetails_title" class="accessibleLabel">Title</label>         
         </fieldset>
      </div>


Again, this validates to WCGA 2.0 AAA, but to me it 'feels' better. Text is contained within p elements, the input control is in a fieldset (which is what we currently do for radios etc), and theres a lot less page structure implied in the markup.

So, my question is, which is better? Would a screen reader do a better job with version 1 (div based) or version 2 (paragraph based) ?

Also, could I improve the semantics further by not including empty elements. For example, the optional help and mandatory elements - if a given question does not use them, would I be better off not including them at all in the markup? (I think I know the answer to this one, but just checking! :)- what I dont know is if a screen reader will try to read an empty p or div )

Many thanks for any help
Best regards

Nathan
nathan.russell
<h6>
 
Posts: 1
Joined: Tue Feb 08, 2011 9:33 am

Re: which is more semantic? (for the purpose of screen reade

Postby GlitchMr » Fri Apr 15, 2011 6:17 am

<div>s doesn't hold any more semantic value than tables. The screen reader probably would ignore empty <div>. The real answer is to use elements supposed to work like such. without all those lol <div>s.

Code: Select all
<label>Title:
<select><option></option>
<option>Dr</option>
<option>Miss</option>
<option>Mr</option>
<option>Mrs</option>
<option>Ms</option></select></label>


And use CSS with it:
Code: Select all
label {width:300px; display:block; text-align:right}
label select, label input {width:150px}


Everybody is happy :D.
GlitchMr
<h6>
 
Posts: 1
Joined: Fri Apr 15, 2011 5:59 am


Return to Help & Advice

Who is online

Users browsing this forum: No registered users and 1 guest