How to Turn Your Website Grayscale with Simple CSS Tricks

Learn four straightforward methods to render an entire webpage in grayscale—by editing CSS files, adding inline styles in the head, modifying the HTML tag, or applying universal CSS filters—complete with code snippets for each approach.

Programmer DD
Programmer DD
Programmer DD
How to Turn Your Website Grayscale with Simple CSS Tricks

On occasions like Qingming, national mourning days, or anniversaries of influential figures, site owners often turn their entire website grayscale to pay respects.

This article shows how to achieve that effect with just a few lines of CSS, offering four different implementations.

Method 1: Modify the CSS file

Add the following rule to your stylesheet to make the whole page appear in grayscale.

html {
    filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
    -webkit-filter: grayscale(100%);
}

Method 2: Insert inline CSS in the tag

If you prefer not to edit external files, place this style block inside the page’s <head> section.

<style type="text/css">
html {
    filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
    -webkit-filter: grayscale(100%);
}
</style>

Method 3: Add inline style to the tag

Alternatively, apply the filter directly on the <html> element.

<html style="filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); -webkit-filter: grayscale(100%);">

Method 4: Apply a universal CSS filter

This rule targets all elements and works across major browsers.

body * {
    -webkit-filter: grayscale(100%); /* webkit */
    -moz-filter: grayscale(100%);    /* firefox */
    -ms-filter: grayscale(100%);     /* ie9 */
    -o-filter: grayscale(100%);      /* opera */
    filter: grayscale(100%);
    filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
    filter: gray; /* ie9- */
}

All these methods rely on CSS filters; choose the one that best fits your workflow.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

frontendCSSHTMLWeb DesignStylinggrayscale
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.