Penn State Homepage

Teaching and Learning with Technology

Creating Accessible Web Sites

Cascading Style Sheets

See the list of C.S.S. style sheet tutorials if you are interested in learning more about style sheets. This site also includes a page on C.S.S. Rollovers.

This Page

  1. Synopsis
  2. Some Benefits of Style sheets
  3. When Styling is Inaccessible
  4. Styles and Netscape 4.7
  5. Links to CSS Tutorials

Synopsis

  1. The use of style sheets to provide formatting has several accessibility advantages including the following:

    1. You can use CSS to improve readability by increasing line spacing, increasing left/right margins and by specifying fonts designed for a monitor.
    2. You can replace less accessible image links and Javascript rollovers with text links combined with CSS styles. Text links are more accessible because they do not "pixellate" when text is zoomed, but retain crisp edges.
    3. Users with color blindness or low visibility conditions can implement a custom style sheet which suits their needs better.
    4. In some cases the use of Style sheets to specify background colors and borders can improve the accessibility of layouts and decrease reliance on HTML tables for layouts.
    5. It is easier to re-design content for alternate media such as printing, Palm pilots and cell phones via alternate Style sheets

    See some code examples below.

  2. However, care must be taken that Web sites are still readable on visual browsers with style sheets turned off. See a later section for details on what to avoid.

    SECTION 508 - Documents shall be organized so they are readable without requiring an associated style sheet.

    NOTE: The Bobby verification report will display your Web page without your CSS markup.

  3. Do not use "visibility: hidden" to hide text from visual browsers; it also hides it from screen readers. Use color (e.g. white on white) or specifying size to 1px to hide text from visual browsers. See Accessible Methods for Hiding Text for details.

  4. Remember that just about any tag can be styled. This includes accessibility tags such as TH, CAPTION, STRONG, FIELDSET, LABEL, and even B, I and OPTION or SELECT.

  5. Avoid using float:right, since it typically requires coders to place elements which will be displayed on the right BEFORE elements placed on the left. Screen readers will read files in code order, not in layout order. A layout table may sometimes be more accessible than complicated CSS layouts.

  6. It is also important to preview styled sheets in several browsers, especially Netscape 4.7 and lower. Implementation is still not standard across all browsers and some CSS errors cause blocks of text to overlap each other or disappear on some browsers.

  7. Style sheet commands should usually be stored in another .css text file, not embedded in the HTML document itself. This allows users to completely override your style sheet

  8. C.S.S. commands for fixing absolute font sizes should be avoided. Use relative font size scales instead.

  9. Care should be taken that color schemes and backgrounds are accessible.

Top of Page

Some Benefits of Style sheets

Style sheets are designed to allow you to globally specify colors, fonts and backgrounds for an entire Web site. For instance, if you specify that all H1 tags should be centered, then you do not need to repeat the ALIGN="center" tag on every page.

Here are some examples of how Style sheets can improve accessibility and reduce code maintenance.

Line Spacing and Margins

The generic specifications for margin and line spacing are not optimized for screen legibility. Compare the following two paragraphs - one style for legibility and one with no styling.

With CSS

Increased side margins, Verdana specified and line spacing increased slightly.

SAMPLE PARAGRAPH: Style sheets are designed to allow you to globally specify colors, fonts and backgrounds for an entire Web site. For instance, if you specify that all H1 tags should be centered, then you do not need to repeat the ALIGN="center" tag on every page.

View the Code

body: {margin-left: 25px; margin-right: 25px;
font-family: Verdana,Arial,Helvetica,sans-serif;
line-spacing: 120%}

Without CSS

Text goes to edge of screen, is single spaced and in Times New Roman (bad for monitors).

SAMPLE PARAGRAPH: Style sheets are designed to allow you to globally specify colors, fonts and backgrounds for an entire Web site. For instance, if you specify that all H1 tags should be centered, then you do not need to repeat the ALIGN="center" tag on every page.

 

Creating Links with Rollovers

This Link becomes white text with navy background when the mouse rolls over it. See the Rollover Links page for more information on using CSS to create rollover links.

View the Code

a:hover {background-color: #000066; color: white: font-weight: bold}

....

<a href="#"> Link </a>

Coloring and aligning H Tags

Sample H1 - Centered and colored blue

With C.S.S.

h1 {color: #000066; text-align: center;}

...

<h1 > Sample H1 </h1>

Without C.S.S.

<h1 align="center"> <font color="#336699> Sample H1 </font> </h1>

 

Creating Formatting Div's Resembling Tables

This is a centered pink div with dotted black border. Actually it's a P with a style specification.

With CSS

.pinkdiv {border: 1px dotted black;
background-color: #FFAADD;
padding: 7px;
margin-left: 150px; margin-right: 150px;}

...

<p class="pinkdiv" > I want a centered pink div area </p >

Without CSS

1. Displaying colored or dotted borders extremely difficult and would probably require nested tables.

2. For a pink table with a plain border:

<table align="center" width="60%" cellpadding="7" border = "1">
<tr>
<td bgcolor="FFAADD"> I want a pink table </td>
</tr>
</table>

NOTE: Data tables are still be the best option for presenting tabular data.

Top of Page

When Styling is Inaccessible

Styling can become inaccessible when style sheet commands are mixed with older HTML formatting tags. When Style sheets are turned on, the result may be readable. But with Style sheets turned off, only the older HTML formatting is read and the page may become unreadable. For example:

Positioning and Float: Right

Some sites use different "floats" to position content without tables. However, some style attributes, such as float: right cause text to place in an order different from that of the HTML file. For instance the following site uses float: right to position the gray box to the right of a list of links.

Page with Float:Right Positioning

Sample Page with gray box to right

But in the code, the list in the gray box actually comes first. When CSS is disabled, you can see that list above the links. Fortuniately, the text can be read in either order.

With CSS Removed. "Right" is on Top

Same page with no CSS and right text on top

Mixing Styles with Old Formatting Tags

This Web site has a black linen background with a pale rose area in the center with dark text. The color contrast is acceptable.

Stitching site with blackbaground and pink text area

The designer used CSS for the pink area and an HTML tag to specify the black linen background as <body background="blacklinen.gif">.

website with CSS on

 

Styling Turned Off - Inaccessible

Becaiuse only the rose text was formatted with CSS, when the style sheet was turned off, the result was black text and blue links on a black textured background - clearly unreadable in a visual browser.

no css, black on black

 

Styling Turned Off - Accessible

Once the site was redesigned so that the background image was included in the CSS file and not in the HTML, the site without CSS was readable, although it appears with standard white background with black text.

without css, black on white

Notice that the use of H tags to provide content structure means that sections are easier to distinguish even with Style sheets turned off.

 

Top of Page

Styles and Netscape 4.7

Although Netscape 4.7 has some style sheet support, it is very inconsistent. In some cases, problematic styles may be ignored, but in others, the parsing may cause text to overlap or entire chunks of text to not display. All Websites with CSS should be previewed in Netscape 4.7 for legibility.

If you do have styles which are causing serious problems in Netscape 4.7, but not other browsers, you can specify styles which will be ignored by Netscape 4.7. This is done by creating two .css style sheets - one with styles which are rendered well in all browsers and those which are problematic for Netscape 4.7. Then, you use two different protocols to create links to the .css files, the "LINK" protocol which all browsers recognize and the "@IMPORT" protocol which Netscape 4.7 ignores, but it recognized by other browsers. See the example below.

Two .css File Protocols

<head>

<link href="Accessibility.css" rel="stylesheet" type="text/css" >
<style type="text/css" media="screen">@import url(AccesExtra.css); </style >

</head>

This is HEAD statement linking to two style sheets. The first statement is the LINK protocol which Netscape 4.7 recognizes. It links to a file called "Accessibility.css" containing styles which work in all browsers. The second statement is the @IMPORT protocol and it links to a second file called "AccessExtra.css". It also specifies that these styles are meant for the screen media and not other outlets such as print.

Top of Page

Links to C.S.S.Tutorials

Top of Page

Site Menu: Home Page/Main Menu | Section 508 Guidelines | Quick Checklist | Details by Tag
| Links | I.T.S. Seminar Page | Sitemap


©1999-2006 Pennsylvania State University.

This Web page is hosted by (by Teaching and Learning with Technology, a unit of Information Technology Services. Please contact the Webmaster if you have any questions.

Last Update: Friday, 02-Sep-2005 14:51:48 EDT