--- url: "https://www.w3.org/WAI/WCAG22/Techniques/css/C18" titulek: "C18: Using CSS margin and padding rules instead of spacer images for layout design | WAI | W3C" h1: "Technique C18:Using CSS margin and padding rules instead of spacer images for layout design" popis: "" jazyk: "en" kanonicka: "" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 03:50:11" znaku: 2512 slov: 407 kodovani: "utf-8" sha256: "12f443fa0ef506dc6f458707b5111f6bab295a3c4e0df95a2dfe6646fb135054" --- # Technique C18:Using CSS margin and padding rules instead of spacer images for layout design ## About this Technique This technique relates to [1.1.1 Non-text Content](https://www.w3.org/WAI/WCAG22/Understanding/non-text-content) (**Advisory**). This technique applies to 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 Web designers sometimes use spacer images (usually 1 by 1 pixel, transparent GIFs) for better control over layout, for example in tables or to indent a paragraph. However, Cascading Style Sheets (CSS) allow sufficient control over layout to replace spacer images. The CSS properties for margins and padding can be used on their own or in combination to control the layout. The margin properties ('`margin-top`', '`margin-right`', '`margin-bottom`', '`margin-left`', and the shorthand '`margin`') can be used on any element that is displayed as a block; they add space at the outside of an element. The padding properties ('`padding-top`', '`padding-right`', '`padding-bottom`', '`padding-left`', and the shorthand '`padding`') can be used on any element; they add space inside the element. ## Examples ### Example 1 The following example consists of two parts: the CSS code, which specifies a margin on all sides of the table, and padding for the table cells; and the HTML code for the table, which does not contain spacer images and is not nested inside another table. #### The CSS ``` table { margin: .5em; border-collapse: collapse; } td, th { padding: .4em; border: 1px solid #000; } ``` #### The HTML ```
Books in the category 'Web development'
Title Author Date
How to Think Straight About Web Standards Andrew Stanovich 1 April 2007
``` ## Related Resources *No endorsement implied.* - [Margin properties: '`margin-top`', '`margin-right`', '`margin-bottom`', '`margin-left`', and '`margin`' in the CSS Box Model Module Level 3 specification](https://www.w3.org/TR/css-box-3/#margins) - [Padding properties: '`padding-top`', '`padding-right`', '`padding-bottom`', '`padding-left`', and '`padding`' in the CSS Box Model Module Level 3 specification](https://www.w3.org/TR/css-box-3/#paddings) Back to Top