--- url: "https://www.w3.org/WAI/WCAG22/Techniques/css/C22" titulek: "C22: Using CSS to control visual presentation of text | WAI | W3C" h1: "Technique C22:Using CSS to control visual presentation of text" popis: "" jazyk: "en" kanonicka: "" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 04:43:02" znaku: 9583 slov: 1438 kodovani: "utf-8" sha256: "2bb4cb07ef1c754d98b6388f937c47659cfd4d4f4125c010b560471506e89910" --- # Technique C22:Using CSS to control visual presentation of text ## About this Technique This technique relates to: - [1.3.1 Info and Relationships](https://www.w3.org/WAI/WCAG22/Understanding/info-and-relationships) ( **Advisory** ) - [1.4.4 Resize Text](https://www.w3.org/WAI/WCAG22/Understanding/resize-text) ( **Advisory** ) - [1.4.5 Images of Text](https://www.w3.org/WAI/WCAG22/Understanding/images-of-text) ( **Sufficient** ) - [1.4.9 Images of Text (No Exception)](https://www.w3.org/WAI/WCAG22/Understanding/images-of-text-no-exception) ( **Sufficient** ) This technique applies to all technologies that support CSS. Techniques are examples of ways to meet Web Content Accessibility Guidelines (WCAG). They are **not required** to meet WCAG. Content can satisfy the normative requirements of WCAG even if it does not use any of the documented techniques. See [About WCAG Techniques](https://www.w3.org/WAI/WCAG22/Techniques/about). ## Description The objective of this technique is to demonstrate how CSS can be used to control the visual presentation of text. This will allow users to modify, via the user agent, the visual characteristics of the text to meet their requirement. The text characteristics include aspects such as size, color, font family and relative placement. CSS benefits accessibility primarily by separating document structure from presentation. Style sheets were designed to allow precise control - outside of markup - of character spacing, text alignment, object position on the page, audio and speech output, font characteristics, etc. By separating style from markup, authors can simplify and clean up the markup in their content, making it more accessible at the same time. Text within images has several accessibility problems, including the inability to: - be scaled according to settings in the browser - be displayed in colors specified by settings in the browser or rules in user-defined style sheets - honor operating system settings, such as high contrast It is better to use real text for the text portion of these elements, and a combination of semantic markup and style sheets to create the appropriate visual presentation. For this to work effectively, choose fonts that are likely to be available on the user's system and define fallback fonts for users who may not have the first font that is specified. Newer machines and user agents often smooth or anti-alias all text, so it is likely that your headings and buttons will look nice on these systems without resorting to images of text. The following CSS properties are useful to style text and avoid the need for text in images: - The `font-family` property is used to display the code aspect in a monospace font family. - The `text-align` property is used to display the text to the right of the viewport. - The `font-size` property is used to display the text in a larger size. - The `font-style` property is used to display text in italics. - The `font-weight` property is used to set how thick or thin characters in text should be displayed. - The `color` property is used to display the color of text or text containers. - The `line-height` property is used to display the line height for a block of text. - The `text-transform` property is used to control the case of letters in text. - The `letter-spacing` property is used to control the spacing of letters in text. - The `background-image` property can be used to display text on a non-text background. - The `::first-line` pseudo-element can be used to modify the presentation of the first line in a block of text. - The `::first-letter` pseudo-element can be used to modify the presentation of the first letter in a block of text. - The `::before` and `::after` pseudo-elements can be used to insert decorative non-text content before or after blocks of text. ## Examples ### Example 1: Using CSS font-family to control the font family for text #### The HTML component ```

The JavaScript method to convert a string to uppercase is toUpperCase().

``` #### The CSS component ``` code { font-family:"Courier New", Courier, monospace } ``` ### Example 2: Using CSS text-align to control the placement (alignment) of text #### The HTML component ```

This text should be to the right of the viewport.

``` #### The CSS component ``` .right { text-align: right; } ``` ### Example 3: Using CSS font-size to control the size of text #### The HTML component ```

09 March 2008

``` #### The CSS component ``` strong.largersize { font-size: 1.5em; } ``` ### Example 4: Using CSS color to control the color of text Note The style used in this example is not used to convey information, structure or relationships. #### The HTML component ```

09 March 2008

``` #### The CSS component ``` .highlight{ color: red; } ``` ### Example 5: Using CSS font-style to italicize text Note The style used in this example is not used to convey information, structure or relationships. #### The HTML component ```

The article is available in the Endocrinology Blog.

``` #### The CSS component ``` .featuredsite{ font-style:italic; } ``` ### Example 6: Using CSS font-weight to control the font weight of the text Note The style used in this example is not used to convey information, structure or relationships. #### The HTML component ```

This deal is available now!

``` #### The CSS component ``` .highlight { font-weight:bold; color:#990000; } ``` ### Example 7: Using CSS text-transform to control the case of text Note The style used in this example is not used to convey information, structure or relationships. #### The HTML component ```

09 March 2008

``` #### The CSS component ``` .caps { text-transform:uppercase; } ``` ### Example 8: Using CSS `line-height` to control spacing between lines of text The CSS `line-height` property is used to display the line height for the paragraph at twice the height of the font. #### The HTML component ```

Concern for man and his fate must always form the chief interest of all technical endeavors. Never forget this in the midst of your diagrams and equations.

``` #### The CSS component ``` p { line-height:2; } ``` The CSS `line-height` property is used to display the line height for the text at less than the height of the font. The second line of text is positioned after the first line of text and visually appears as though the text is part of the first line but dropped a little. #### The HTML component ```

News today

``` #### The CSS component ``` .overlap { line-height:0.2;} .upper { text-transform:uppercase; } .byline { color:red; font-style:italic; font-weight:bold; padding-left:3em; } ``` ### Example 9: Using CSS `letter-spacing` to space text The CSS `letter-spacing` property is used to display the letters farther apart in the heading. #### The HTML component ```

News
today

``` #### The CSS component ``` .overlap { line-height:0.2em; } .upper { text-transform:uppercase; } .byline { color:red; font-style:italic; font-weight:bold; padding-left:3em; letter-spacing:-0.1em; } ``` The CSS `letter-spacing` property is used to display the letters closer together in the second line of text. #### The HTML component ```

News

``` #### The CSS component ``` .upper2 { text-transform:uppercase; letter-spacing:1em; } ``` ### Example 10: Using CSS `background-image` to layer text and images The CSS `font-style` property is used to display the textual component of a banner and `background-image` property is used to display a picture behind the text. #### The HTML component ``` ``` #### The CSS component ``` #banner { color:white; background-image:url(banner-bg.gif); background-repeat:no-repeat; background-color:#003399; width:29em; } #bannerstyle1 { text-transform:uppercase; font-weight:bold; font-size:2.5em; } #bannerstyle2 { font-style:italic; font-weight:bold; letter-spacing:-0.1em; font-size:1.5em; } ``` ### Example 11: Using CSS `::first-line` to control the presentation of the first line of text The CSS `::first-line` pseudo-element is used to display the first line of text in a larger, red font. #### The HTML component ```

Once upon a time...
...in a land far, far away...

``` #### The CSS component ``` .startline::first-line { font-size:2em; color:#990000; } ``` ### Example 12: Using CSS `::first-letter` to control the presentation of the first letter of text The CSS `::first-letter` pseudo-element is used to display the first letter in a larger font size, red and vertically aligned in the middle. #### The HTML component ```

Once upon a time...

``` #### The CSS component ``` .startletter::first-letter { font-size:2em; color:#990000; vertical-align:middle; } ``` ## Related Resources *No endorsement implied.* - [CSS2.1 Specification](https://www.w3.org/TR/CSS21/) - [CSS Fonts Module Level 3](https://www.w3.org/TR/css-fonts-3/) - [CSS Color Module Level 4](https://www.w3.org/TR/css-color-4/) - [CSS Text Module Level 3](https://www.w3.org/TR/css-text-3/) - [CSS Backgrounds and Borders Module Level 3](https://www.w3.org/TR/css-backgrounds-3/) - [Selectors Level 3](https://www.w3.org/TR/selectors-3/) - [Learning CSS](https://www.w3.org/Style/CSS/learning) - [CSS and Accessibility](https://www.w3.org/TR/CSS-access) ## Tests ### Procedure 1. Check whether CSS properties were used to control the visual presentation of text ### Expected Results - Check #1 is true. Back to Top