Online CSS Opacity Generator


Control element transparency easily with this online CSS opacity generator. Adjust opacity values in real time and instantly get clean CSS code for your projects. Whether you're working with the opacity property, rgba() colors, or modern hex alpha formats, this tool helps you visualize and implement transparency effects quickly.

What is CSS Opacity?

Opacity in CSS defines how transparent an element is. The value ranges from 0 (completely transparent) to 1 (fully visible).

  • opacity: 1 → fully visible
  • opacity: 0.5 → semi-transparent
  • opacity: 0 → invisible

Basic CSS Opacity Example

CSS
.box {
  opacity: 0.5;
}

This makes the entire element (including text and children) semi-transparent.

Image Opacity Examples

See how different opacity levels affect images. Below examples demonstrate opacity: 0, 0.5, and 1, helping you understand how transparency changes visibility from completely hidden to fully visible.

html
Opacity: 0
html
Opacity: 0.25
html
Opacity: 0.5
html
Opacity: 0.75

Live CSS Opacity Generator

Easily apply transparency effects to your elements with this interactive opacity generator. Start by selecting the element type whether it is a div box, image, or text then adjust the opacity level using the slider or input field. The preview updates instantly so you can see how the transparency affects your design.

Features

  • Choose element type: Div Box, Image, or Text
  • Adjust opacity from 0 to 1
  • Real-time preview of transparency
  • One-click copy CSS code
Select Element:
×
html
Background:
opacity: 0.5;
Set Opacity

HTML and CSS code

HTML
<img class="opacity" src="/images/HTMLpicture.png" alt="html">
CSS
.opacity {
    opacity: 0.5;

    width: 200px;
    height: auto;
}

Common Use Cases

CSS opacity is widely used to create modern and visually appealing UI effects. It helps control transparency for elements like images, backgrounds, and text, making designs more interactive and layered.

  • Overlay effects
  • Image hover transparency
  • Background fade
  • UI disabled states
  • Modal backdrop

CSS Opacity Animation Effect

Create dynamic visual effects by animating opacity values over time. This example demonstrates a continuous fade-in and fade-out animation, making elements smoothly transition between visible and transparent states.

Preview Opacity Animation

html

HTML and CSS Code for Opacity Animation

HTML
<img class="opacity-animation" src="/images/HTMLpicture.png" width="200">
CSS
.opacity-animation {
   Opacity: 0.5;
   animation: opacity_fade 3s linear infinite normal;
}

@keyframes opacity_fade {
    0%   { Opacity: 0 }
  	25%  { Opacity: 1 }
    50%  { Opacity: 0 }
    75%  { Opacity: 1 }
    100% { Opacity: 0 }
}

Smooth Hover Fade Effect

Create a clean fade animation on hover that smoothly adjusts opacity, adding subtle interactivity and improving the visual experience.

Preview Animation

html

HTML and CSS Code for Hover Fade Effect

HTML
<img class="smooth-hover-opacity" src="/images/HTMLpicture.png" width="200">
CSS
.smooth-hover-opacity {
   opacity: 0.5;
   transition: opacity 0.3s linear;
}
.smooth-hover-opacity:hover {
   opacity: 1;
}

Disabled Button Opacity Styling

Use opacity to visually indicate disabled input buttons and inactive states. Lowering the opacity helps users quickly recognize that an element is not interactive, while maintaining a clean and consistent UI design.

Preview Disabled

Checkbox
Radio button
Button
Textarea

HTML and CSS Code for Disabled Button

HTML
Checkbox <input type="checkbox" disabled>
Radio button <input type="radio" disabled>
Button <button disabled>Disabled button</button>
Textarea <textarea disabled></textarea>
CSS
.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

input:disabled, button:disabled, select:disabled, textarea:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

Frequently Asked Questions (FAQ)

What is opacity in CSS?

Opacity in CSS controls how transparent an element is. It uses values from 0 to 1, where 0 means completely invisible and 1 means fully visible. This property affects the entire element, including its content and child elements.

What is the difference between opacity and rgba?

The opacity property applies transparency to the whole element, including text and child elements. In contrast, rgba() controls transparency only for a specific color (usually background), allowing text and inner content to remain fully visible.

How do I make only background transparent?

To make only the background transparent, use rgba() or hex with alpha instead of the opacity property. This way, you can adjust the background transparency without affecting the text or other content inside the element.

CSS
.box {
  background-color: rgba(0, 0, 0, 0.5); /* transparent background */
  color: #ffffff; /* text remains fully visible */
  padding: 20px;
}