## HTML `
![]()
` hspace Attribute
The `hspace` attribute of the `
![]()
` tag specifies the amount of horizontal space (whitespace) on the left and right sides of an image.
> **β οΈ Deprecation Notice:**
> The `hspace` attribute is **deprecated** in HTML 4.01 and is **not supported** in HTML5. Modern web development standards require using CSS instead to control spacing around elements.
---
## Syntax
```html
![]()
```
### Attribute Values
| Value | Description |
| :--- | :--- |
| *pixels* | The width of the horizontal margin on both the left and right sides of the image, specified in pixels. |
---
## Browser Support
The `hspace` attribute is supported by all major legacy browsers (Internet Explorer, Firefox, Opera, Chrome, and Safari). However, because it is obsolete in modern HTML standards, relying on it can lead to inconsistent rendering in modern browsers and strict document types.
---
## Code Examples
### Legacy HTML Example (Deprecated)
The following example adds 20 pixels of horizontal space to both the left and right sides of the image using the `hspace` attribute:
```html
This is some text surrounding the image.
```
---
## Modern Alternative: Using CSS
Instead of using the obsolete `hspace` attribute, you should use the CSS `margin` property. This provides better control, cleaner code separation, and full compatibility with modern web standards (HTML5).
### Equivalent CSS Syntax
To apply horizontal spacing (left and right margins) while keeping top and bottom margins at `0`, use the following CSS:
```html

```
### Detailed CSS Comparison
* **Using `hspace="20"` (Obsolete):**
Applies 20px of margin to the left and right sides of the image.
* **Using CSS Inline Style (Recommended):**
```html

```
* **Using an External CSS Class (Best Practice):**
```css
/* CSS File */
.spaced-image {
margin: 0 20px; /* 0px top/bottom, 20px left/right */
}
```
```html

```