By Michael Irigoyen
PublishedonJune18th,2009in
Letstakealookat10waystoimprovetheaccessibilityofyourXHTMLwebsiteby makingitstandardscompliant.Wellgotheextramileandincludecriteriathatfallbeyond
1.SpecifyTheCorrectDOCTYPE
Criteria. TheDocumentTypedeclaration(DOCTYPE)isaninstructionthatsitsatthetopofyour document.TheDOCTYPEisrequiredtotellthebrowserhowtocorrectlydisplayyourpage. WhydoIneedit? WithoutaproperDOCTYPEdeclaration,thebrowsertriestoautomaticallyassigna DOCTYPEtothepage.Thiscanslowdowntherenderingofyourpageandcausethepageto bedisplayedinconsistentlyorincorrectlyindifferentbrowsers.Consistencyisthenameofthe gamewhenitcomestoaccessibility. Okay,sowhatdoIdo? IncludeaproperDOCTYPEatthetopofeachpageofyourwebsite.XHTML1.1is recommended,butXHTML1.0Strictisanoptionaswell. XHTML1.1 Thisisthecleanestwaytocodeyourwebsite.Allstyleforthewebsiteis containedinexternalCSSfiles.BesuretoaddtheXMLdeclarationatthetop, whichisessentialbecauseXHTML1.1isconsideredtobetrueXML.
< ? x m l v e r s i o n = " 1 . 0 " e n c o d i n g = " U T F 8 " ? > < b r > < ! D O C T Y P E h t m l P U B L I C " 1/ / W 3 C / / D T D X H T M L 1 . 0 S t r i c t / / E N " < b r > " h t t p : / / w w w . w 3 . o r g / T R / x h t m l 1 / D T D / x h t m l 1 s t r i c t . d t d " >
2.DefineTheNamespaceAndDefault Language
element. WhydoIneedit? XHTMLwebsitesshoulddefinethedefaultnamespace.Anamespacedefinesallofthe elementsyoucanusewithinthepage.Settingadefaultlanguageallowsascreenreaderto tellthevisitorwhichlanguagethepageisinwithoutevenseeingthecontent.Itisalsorequired byW3Cstandards. Okay,sowhatdoIdo? Appendthex m l n s andl a n g attributestothe< h t m l > element.InXHTML1.1,thel a n g attribute isx m l : l a n g . XHTML1.1
1< h t m l x m l n s = " h t t p : / / w w w . w 3 . o r g / 1 9 9 9 / x h t m l " x m l : l a n g = " e n " >
XHTML1.0
1< h t m l x m l n s = " h t t p : / / w w w . w 3 . o r g / 1 9 9 9 / x h t m l " l a n g = " e n " >
3.SupplyProperMetaTags
Criteria. Supplytheh t t p e q u i v ,l a n g u a g e ,d e s c r i p t i o n andk e y w o r d s metatagsinthe< h e a d > elementonyourpage. WhydoIneedit? Theh t t p e q u i v metatagisbyfarthemostimportant.Usedinconjunctionwiththe DOCTYPE,ithelpsthebrowserdisplayyourpagecorrectly.Thel a n g u a g e metatagis importantfornonEnglishwebsites,butithasbecomecommonpracticetoincludeitonevery page,despitethelanguage.Thed e s c r i p t i o n andk e y w o r d s metatagsarerequiredmorefor accessibilitythantomeetstandardsbecausetheyarecommonlyusedbyscreenreaders.
4.UseAccessibleNavigation
Criteria. Allowuserstoeasilyidentifywhatpageandsubsectionofapagetheyareviewing. WhydoIneedit? Amajorityofwebsitestodayuseacombinationoftext,colorsandgraphicstylestoorganize anddisplayinformation.Manypeoplewithdisabilitiescannotseeorusegraphicsandthus relyonscreenreaders,customstylesheetsandotheraccessibilitytoolstoretrieve information.Regardlessofwhovisitsyourwebsite,implementinganaccessiblenavigation systemhelpsthemquicklyandaccuratelyfindtheinformationtheyarelookingfor. Okay,sowhatdoIdo? Createadescriptivetitleforyourwebsite,andthensplitthepageintosubsectionsusingthe headingelements. Includeexactlyone< t i t l e > elementwithinthe< h e a d > element:
Correct:
< h 2 > < i m g s r c = " l o g o . p n g " a l t = " S m a s h i n g M a g a z i n e " / > S m a s h i n g 1 M a g a z i n e < / h 2 >
5.ProperlyEscapeJavaScript
Criteria. WhenincludingJavaScriptdirectlyonthepage,youshouldproperlyescapeitascharacter data. WhydoIneedit? InHTML,textinthe< s c r i p t > elementisrenderedasCDATA(characterdata).InXHTML,text inthe< s c r i p t > elementistreatedasPCDATA(parsedcharacterdata).PCDATAis processedbytheW3Cvalidatorand,therefore,mustbeescapedproperlyasCDATA.In addition,whilemostscreenreadersareintelligentenoughtoignorecontentwithinthe < s c r i p t > element,regardlessofthetypeofdataitcontains,ifthecodeisntcorrectly
6.ProperlyEscapeHTMLEntities
7.UseOnlyLowercaseTagsAndAttributes
Criteria. Allelementsandelementattributesmustbelowercase.Attributevaluescanbeboth uppercaseandlowercase. WhydoIneedit? BecausetheXHTMLstandardsetbytheW3Csaysso2 . Okay,sowhatdoIdo? Makesureyouuseonlylowercaseforallelementsandattributes.Acommonmistakemost developersmakeisusinguppercaseletterswhengivinganelementJavaScriptattributes (e.g.onClick,onLoad,etc.). Incorrect:
Correct:
1< a h r e f = " # " o n c l i c k = " d o S o m e t h i n g ( ) " > S e n d u s a m e s s a g e < / a >
8.LabelAllFormInputElements
Criteria. Allformelementsshouldbegivena< l a b e l > tag. WhydoIneedit? The< l a b e l > elementaddsfunctionalityforpeoplewhousethemouseandascreenreader. Clickingontextwithinthe< l a b e l > elementfocusesthecorrespondingformelement.Screen readerscanreadthelabelsothatvisitorsknowwhatinformationtoprovide. Okay,sowhatdoIdo? Adda< l a b e l > elementtoeachfieldinyourform. Example:
< p > < l a b e l f o r = " s e a r c h b o x " > S e a r c h : < / l a b e l > < i n p u t t y p e = " t e x t " i d = " s e a r c h b o x " / > 1 < / p > < p > < i n p u t t y p e = " c h e c k b o x " i d = " r e m e m b e r " / > < l a b e l f o r = " r e m e m b e r " > 2 R e m e m b e r < / l a b e l > < / p >
9.SupplyAlternativeContentForImages
Criteria. Everyimageonyourpageshouldbeaccompaniedbyatextualalttag. WhydoIneedit? Thealttagtellsvisitorswhatanimageisifitcannotbedisplayedorviewed.TheAmericans withDisabilitiesActdictatesthatallimagesmusthaveanalttag. Okay,sowhatdoIdo? Includeonewitheveryimage.Thealttagattributemustincludetextandcannotbeleftblank.If youuseimagesinyourdesignforstylisticreasonsalone,findawaytoachievethatstyleusing CSS.Anddontforgettoprovideexplicitvaluesforwidthandheightofyourimages. Incorrect:
1< i m g s r c = " p i c t u r e . p n g " / > 2< i m g s r c = " s p a c e r . g i f " a l t = " " / >
Correct:
1< i m g s r c = " p i c t u r e . p n g " a l t = " A w a r m s u n s e t " w i d t h = " 4 5 0 " h e i g h t = " 3 5 0 " / >
10.UseThe"id"And"class"CSSAttributes Correctly
Criteria.
WhenusingCSSattributes,useeach"id"onlyonceonapage.Useeach"class"asmuchas youwant. WhydoIneedit? Developersoftengetcarelessandincludean"id"multipletimesonasinglepage.Thiscan createunexpectedresultsacrossdifferentbrowsersandgetyouabigredValidationFailed fromtheW3C. Okay,sowhatdoIdo? Becertaintouseaparticular"id"onlyonceonapage.Ifyouneedthesamestyleappliedto mutlipleelements,usethe"class"attribute. Incorrect:
1< p i d = " l e f t N a v " > H o m e < / p > 2< p i d = " l e f t N a v " > C o n t a c t < / p >
Correct:
1< p i d = " h o m e N a v " c l a s s = " l e f t N a v " > H o m e < / p > 2< p i d = " c o n t a c t N a v " c l a s s = " l e f t N a v " > C o n t a c t < / p >
Summary:Validate,Validate,Validate!
Usingallthetechniquesinthisarticle,youllbewellonyourwaytoamoreaccessible, standardscompliantwebsite.Butdontstopthere!Continuallyvalidateyourwebsiteand addressproblemsimmediately.Hereisalistofvalidatorsyoushouldrunoneverypageyou create: W3CMarkupValidationService W3CCSSValidationService HiSoftwareCynthiaSaysAccessibilityValidation FunctionalAccessibilityEvaluator (al)
F OOT N OT E S :
1 OtherHTMLentitieshttp://htmlhelp.com/reference/html40/entities/special.html 2 sayssohttp://www.w3.org/TR/xhtml1/#h4.2
MichaelIrigoyenisaWebdeveloperandgraphicdesignerforComputer InfrastructureSupportServicesatIllinoisStateUniversity.
Withacommitmenttoqualitycontentforthedesigncommunity. SmashingMediaGmbH.MadeinGermany.20062012.http://www.smashingmagazine.com