
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS3 - Rounded Corner
- CSS3 - Border Images
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
How to Create a Black and White Image Using CSS
By specifying grayscale value to the filter property of CSS we can create a black and white image. filter property can be used to apply special effects like blur, drop-shadow to images.
Syntax
The syntax of CSS filter property is as follows −
Selector { filter: grayscale(100%); -webkit-filter: grayscale(100%); }
Example
The following examples illustrate CSS filter property.
<!DOCTYPE html> <html> <head> <style> img { margin: 2%; border-radius: 25%; } img:nth-of-type(even) { filter: grayscale(100%); -webkit-filter: grayscale(100%); } </style> </head> <body> <img src="https://images.unsplash.com/photo-1611825715408-826f2b19c43f?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=200&ixlib=rb-1.2.1&q=80&w=200" alt="img from unsplash"> <img src="https://images.unsplash.com/photo-1611825715408-826f2b19c43f?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=200&ixlib=rb-1.2.1&q=80&w=200" alt="img from unsplash"> </body> </html>
This gives the following output
Example
<!DOCTYPE html> <html> <head> <style> img { margin: 2%; } img:nth-of-type(odd) { filter: grayscale(100%); -webkit-filter: grayscale(100%); } </style> </head> <body> <img src="https://images.unsplash.com/photo-1611781750917-8777ab68668a?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=256&ixlib=rb-1.2.1&q=80&w=256"> <img src="https://images.unsplash.com/photo-1611781750917-8777ab68668a?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=256&ixlib=rb-1.2.1&q=80&w=256"> </body> </html>
This gives the following output
- Related Articles
- How to create a "black and white" image with CSS?
- How to create a black image and a white image using OpenCV Python?
- How to change the color of an image to black and white using CSS?
- Create white text with black shadow using CSS
- How to create a black and white word cloud in R?
- How to create Image Folding Effect using HTML and CSS?
- How to plot a half-black and half-white circle using Matplotlib?
- How to Create an Image Slider using HTML, CSS, and JavaScript?
- How to Create Image Lightbox Gallery using HTML CSS and JavaScript?
- How to Create Image Stack Illusion by using HTML and CSS?
- How to Create Image Hovered Detail using HTML & CSS?
- How to create a thumbnail image CSS?
- How to create and use CSS Image Sprites
- How to create an image with a transparent background text using CSS?
- How to create a Hero Image with CSS?

Advertisements