YouTip LogoYouTip

Prop Webcontrol Table Cellspacing

## ASP.NET Web Control: Table CellSpacing Property The `CellSpacing` property is a member of the ASP.NET `Table` web control. It is used to get or set the amount of space (in pixels) between adjacent table cells, as well as between a cell and the border of the table. --- ## Definition and Usage The `CellSpacing` property controls the layout of an ASP.NET `Table` control by defining the gap between individual cells. * **Default Value:** If not specified, the default value is `-1`, which indicates that the property is not set. The browser will then render the table using its default spacing. * **Unit of Measurement:** The value is defined as an integer representing pixels (`px`). > **Note:** While modern web development heavily relies on CSS (`border-spacing` and `border-collapse`) for layout styling, the `CellSpacing` property remains a quick and reliable declarative way to manage cell gaps directly within ASP.NET Web Forms markup. --- ## Syntax ```xml ``` ### Property Values | Value | Description | | :--- | :--- | | `px` | An integer that specifies the spacing between cells in pixels (e.g., `10`, `20`). | --- ## Code Example The following example demonstrates how to set the `CellSpacing` property of an ASP.NET `Table` control to `20` pixels. ```xml <%@ Page Language="C#" %> ASP.NET Table CellSpacing Example

Table with CellSpacing="20"

Cell 1, Row 1 Cell 2, Row 1 Cell 1, Row 2 Cell 2, Row 2
``` --- ## Considerations & Best Practices ### 1. CellSpacing vs. CellPadding It is easy to confuse `CellSpacing` with `CellPadding`. * **`CellSpacing`** defines the space **between** cells. * **`CellPadding`** defines the space between the **cell border and the cell content**. ### 2. Browser Compatibility and Modern CSS Alternatives Historically, some older browser versions had inconsistent rendering behaviors for HTML table spacing attributes. In modern web development, it is often recommended to control spacing using CSS for cleaner separation of concerns (presentation vs. structure). If you prefer to use CSS instead of the `CellSpacing` property, you can apply the following styles to your table: ```css /* CSS Equivalent to CellSpacing */ table { border-collapse: separate; border-spacing: 20px; /* Sets 20px spacing between cells */ } ```
← Prop Webcontrol Table GridlineProp Webcontrol Table Cellpadd β†’