CSS Opacity Property
The CSS opacity property specifies the transparency of an element. It allows you to make an element transparent, semi-transparent, or fully visible.
Values Range
Opacity takes a value between 0 and 1:
- 1: The default value. The element is fully opaque (visible).
- 0.5: The element is 50% transparent.
- 0: The element is fully transparent (invisible), but still takes up space in the layout.
Inheritance
When you apply opacity to an element, it affects the entire element, including its borders, background, and all child elements. A child element cannot be more opaque than its parent.
If you only want to make the background color transparent without affecting the text or children, use background-color: rgba(R, G, B, alpha) instead of the opacity property.
Accessibility
Elements with opacity: 0 are invisible to users but may still be reachable by keyboard navigation (Tab key) and read by screen readers. If you want to hide an element completely from assistive technology, use visibility: hidden or display: none.
