Frontend Development 2 min read

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.

frontendCSShtmlstyleweb 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

login 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.