CSS Visual Styling Examples
This page demonstrates visual styling techniques using modern CSS. Each example includes complete code that you can adapt for your projects.Gradient Text
Create eye-catching text with gradient fills using modern CSS.- Define a gradient background using
linear-gradient() - Set text fill color to transparent with
-webkit-text-fill-color - Clip the background to text shape using
background-clip: text - Include WebKit prefix for broader compatibility
Custom Scrollbar
Customize scrollbar styling to match your design system.::-webkit-scrollbarsets the scrollbar width::-webkit-scrollbar-trackstyles the scrollbar background (green)::-webkit-scrollbar-thumbstyles the draggable element (blue)border-radiuscreates rounded corners
Dynamic Shadow
Create shadows that inherit the element’s background colors.- Element has
position: relativewith a gradient background ::afterpseudo-element positioned absolutely, filling the same spacebackground: inheritcopies the parent’s gradient- Offset downward with
top: 0.5rem filter: blur()creates the shadow effectopacity: 0.7softens the shadowz-index: -1positions shadow behind parent
z-index: 1 for proper stacking context.
CSS Shapes
Create geometric shapes using pure CSS.Circle and Ellipse
- Circle: Equal width and height with
border-radius: 50% - Ellipse: Different width/height with radius matching half the dimensions
Triangles
Create triangles using CSS borders.- Set width and height to 0
- Create borders on all sides
- The border opposite to the desired direction gets the color
- Adjacent borders are transparent
- Border width determines triangle size
Rectangle
Image Overlay on Hover
Create an interactive overlay effect when hovering over images.<figure>contains image and caption withposition: relative::beforeand::aftercreate overlay bars, initially scaled and transparent<figcaption>positioned absolutely, flexbox-centered, initially transparent- On hover:
- Overlay pseudo-elements scale to normal size and become visible
- Image opacity reduces to 0.7
- Caption fades in with slight delay
Filters and Effects
Blur Effect
Combined Filters
Grayscale
Practical Tips
- Test visual effects across browsers - Rendering can vary slightly
- Provide fallbacks - Some effects have limited browser support
- Consider performance - Complex filters on large elements can impact frame rate
- Ensure accessibility - Maintain sufficient contrast ratios
- Use transitions - Smooth changes enhance user experience
- Optimize images - Compress images before applying effects