Applying a Grayscale (Black‑and‑White) Effect to a Website Using CSS

This article explains how to turn an entire website black‑and‑white by adding a simple CSS snippet that applies grayscale filters, provides the exact code, and offers guidance on where to insert it in the HTML head for immediate effect.

php Courses
php Courses
php Courses
Applying a Grayscale (Black‑and‑White) Effect to a Website Using CSS

The page commemorates a national memorial day and shows a quick way to change a website’s appearance to black‑and‑white as a sign of respect.

Grayscale CSS Code

html{
  -webkit-filter: grayscale(100%);
  -moz-filter: grayscale(100%);
  -ms-filter: grayscale(100%);
  -o-filter: grayscale(100%);
  filter: grayscale(100%);
  filter: gray;
}

Adding the above snippet at the top of your CSS file (or inside a <style>...</style> block in the <head> of your HTML) will render the whole site in grayscale.

The article also notes that if a site does not use a CSS file, you can place the code directly between the <head> tags, remembering to wrap it with <style> tags; otherwise it will have no effect.

For sites that use outdated standards, the author suggests updating to the latest web standards to ensure the CSS works correctly.

Although a JavaScript method could achieve the same result, the author recommends the CSS approach for better performance and less impact on page rendering.

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.

CSSHTMLstyleWeb Designgrayscale
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

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.