CSS Optical Illusions
Recorded: Jan. 23, 2026, noon
| Original | Summarized |
CSS Optical Illusions Skip to main content Alvaro Montoro About Work Projects Writing Change to light mode Change to dark mode CSS Optical Illusions January 22, 2026 You can find a collection with all the optical illusions in this article (and more!) on CodePen. You can move your mouse over many of the demos below to reveal the effect or stop the animations. 1 - Poggendorff Illusions The Poggendorff illusion is an optical illusion in which a diagonal line interrupted by a vertical bar appears misaligned, even when both segments are actually continuous. The effect can also be seen in a more elaborate version with multiple diagonal lines and vertical bars: This drawing can easily be achieved using two CSS gradients: one tilted at 70 degrees and another consisting of a series of vertical columns. I applied it to the body, although I could have used :root instead. 2 - Induced Gradients The following illusions combine gradients and flat colors. Surprisingly, some of the gradients do not actually exist. They are simple gray bars that, when placed over a gradient, appear to have gradients themselves. Here is another variation of this effect. It looks like the central line has a repeating gradient of dark and light grays, but in reality it is a flat color. If you mouse over the demo, the bar will expand, making it clear that there is no gradient at all. 3 - Cornsweet Illusion The next few optical illusions share a common idea: some colors are identical, but they do not look the same. This typically happens when regions of the same color or brightness are surrounded by areas with different contrast. 4 - White's Illusion Run the following demo. You will see two gray columns in a black-and-white grid. Both columns are the same shade of gray, but the one surrounded by black appears darker than the one surrounded by white. I coded this demo using mix-blend-mode so I could try something a bit different. That worked well, but it also made it harder to showcase the effect on hover. In hindsight, I should have planned that better. 5 - Wertheimer-Koffka Ring The ring in the following illustration has the same color all the way around. However, one side is placed over white and the other over black, which makes them look different. If you mouse over the demo, the red bar will disappear, making it more obvious that the ring is a single, uniform color. 6 - Adelson's Illusion You have probably seen the illusion involving a checkerboard and an object casting a shadow, where two tiles - one seemingly light and one seemingly dark - turn out to be the same color. 7 - Asahi illusion of Brightness The circle at the center of this flower-shaped element is the same white as the rest of the page, but it gives the impression of being brighter, as if it were emitting light. 8 - Color Spheres This is one of my favorite illusions in the collection. The circles (or spheres) look red, blue, or green, but in reality they are all the same grayish color. Our brain "colorizes" them based on the lines that overlap the shapes. Don't believe it? Mouse over the illustration. 9 - Colors from Contour In the following illustration, the lines inside the yellow section appear blue, while the lines inside the blue section appear red... but they are all black (or very dark gray). The white contour creates the illusion of color. Mouse over to remove the contour and the lines will clearly appear black. 10 - Curvature Blindness One set of lines looks straighter (top) while the other looks more curved (bottom). In reality, both sets are equally wavy. The only difference is how they are colored: changing the color at the peaks makes the lines look straighter. Changing it at the inflection points makes them look more curved. 11 - Cafe Wall This is a classic optical illusion and an easy one to code in CSS. Three gradients are all that is needed to generate the effect in which the horizontal lines appear slanted, even though they are perfectly parallel. 12 - Penrose Triangle This optical illusion depicts an impossible shape. Parts that should be in front appear in the back, top becomes right, and everything feels contradictory. I coded this one some time ago for the 2024 Divtober event. 13 - Ebbinghaus Illusion Which orange circle is larger: the one on the right or the one on the left? It is a trick question: both are the same size. However, having smaller surrounding elements gives the impression that one is larger. I also created an animated version of this illusion (see below), as well as another version using a square shape instead of a flower shape: 14 - Kanizsa Square When people look at this illustration, they usually say they see a white square over black circles. However, the square is not actually there. The "Pac-Man" shapes create the illusion of a square and a sense of depth. Our brain fills in the missing information. 15 - Ehrenstein's Illusion There are no circles or discs in this illustration, only vertical and horizontal lines forming crosses. Our visual system completes the shape and makes us perceive a disc that does not exist. 16 - Neon-Color-Spreading Illusion This illustration shows concentric circles, some of which have a green-and-black pattern. Our brain perceives a central patterned circle and four concentric circles around it, beneath the green circle. 17 - Hering and Wundt Illusions Perspective-based illusions are fascinating. Even when we know we are looking at a flat image, our brain insists on interpreting depth. The opposite effect is the Wundt illusion. When the lines expand from the sides toward the center, the red lines appear to curve inward (this effect is more subtle). 18 - Ponzo Illusion Both yellow lines are the same length, but the top one looks longer due to perceived depth and perspective. I tried a different approach when coding this one by applying a three-dimensional rotation in CSS... so the perspective is technically real. 19 - T Illusion This illusion is easy to code in CSS and easy to fall for. Both the vertical and horizontal lines are the same length, but the vertical line appears longer. 20 - Müller-Lyer Illusion A classic illusion: the horizontal lines are the same length, but inward- or outward-pointing edges dramatically change how we perceive them. I could swear the top one is longer. But it is not. 21 - Tilted Table Illusion It looks like the top rectangle is leaning to the left, but it is actually parallel to the one at the bottom. The trick lies in the direction of the diagonal lines used to "color" each rectangle. 22 - Parallel Lines This is a simple effect: the black lines are parallel, but they appear not to be because of the direction of the bars crossing them. Here is the original version I created. The effect is also visible there: Good news! There are more optical illusions below - but first, a warning. ATTENTION: The following optical illusions are static, but they give the impression of movement. Proceed accordingly. (Leaving some blank space in case you do not want to continue.) 23 - Expanding Hole This is a trippy optical illusion. It is completely static, yet it looks like the black hole at the center is expanding - especially when you are not looking at it directly, creating the sensation of falling into a pit. 24 - Rotating Snakes This is one of only two optical illusions in this collection where I used HTML elements instead of relying exclusively on CSS. It is a classic effect: when you look at the illustration, the peripheral discs appear to rotate, even though nothing is actually moving. 25 - Appearing Dots Another classic illusion. Focus on the white dots and the adjacent dots will appear to turn black. There is no animation, no transition, and nothing dynamic. Just intersecting lines and small white circles, yet it looks like motion. 26 - Disappearing Dots This pattern consists of repeating black and white dots across the page. If you focus on one dot, the others will begin to disappear. At first it may happen by row or column, but after a short while, most of them vanish. 27 - Ouchi Illusion This is a static image, but it gives the impression that the pattern inside the circle is moving sideways. This happens because our eyes are constantly making small movements, even when we are not aware of it. 28 - Orthogonal Dotted Lines Sway When you look around this pattern, the central area appears to slide and sway, even though it is completely static. This illusion makes me dizzy... but that may also be because I had to stare at it for a long time while coding it. 29 - Enigma This illusion is particularly interesting. There is a pink circle surrounded by concentric pink and purple rings. If you focus on the pink circle, the rings appear to spin or scintillate, as if there were some activity in them. Of course, nothing is actually moving. 30 - Waves This demo was challenging to code and takes a long time to load. Mainly because it uses a large number of conic gradients behind the scenes, which browsers struggle to render efficiently. There is probably a better way to implement it, but I have not explored that yet. Good news! There are more optical illusions below - but first, another warning. ATTENTION: The following optical illusions actually move, and the illusion is created by motion itself. Some of them can be dizzying, so proceed accordingly. (Leaving some blank space in case you do not want to continue.) 31 - Animated Ebbinghaus Illusion Earlier, we saw two static versions of the Ebbinghaus illusion. This one is animated. The elements move side to side, and the surrounding shapes grow and shrink, giving the impression that the orange circle is changing size - when it definitely is not. 32 - Psychokinematic Tower This looks like a three-dimensional tower spinning in space, as seen from above. In reality, it is a flat, two-dimensional image rotating. 33 - Color Fan This optical illusion requires only two gradients: a conic gradient for the fan-shaped arms and a radial gradient for the circles and discs. 34 - Reverse Spoke Illusion This illusion is delightful and disorienting. While the background colors of the wheel are spinning, the spokes remain fixed. However, they appear to rotate in the opposite direction. In reality, only the background is moving. 35 - Motion Binding What do you see in this animation? Most people report two sets of lines operating independently: one moving horizontally and another moving vertically. And that is exactly how it looks. 36 - Mainz-Linez Illusion Focus on one of the red dots. You will notice it moves straight up and down along a vertical path. Now shift your focus to one of the black crosses in the center. Suddenly, the red dots appear to zigzag instead of moving straight. 37 - Waddling Colors It may look like the boxes are moving at different speeds or like a set of walking feet. In reality, all elements move at the same pace and in parallel. Mouse over the demo to reveal the effect. The illusion also works when the "feet" move in circles, as shown in this alternative version: 38 - Dotted-Line Motion Follow the red dot as it moves sideways. From the corner of your vision, it may appear that the dashed black-and-white lines are moving closer together (when the dot moves left) or farther apart (when it moves right). In reality, the lines are completely static. 39 - Contrast Asynchrony These dots always have the same color. However, when placed against alternating backgrounds, they appear to jump or move out of sync because of how they blend with their surroundings. 40 - Breathing Square This illusion gives the impression that a blue square is growing and shrinking rhythmically, almost as if it were breathing or beating like a heart. 41 - Troxler Fading This illustration shows a circle made of pink dots, with one dot missing. Focus on the cross at the center and the missing dot will appear as a yellow or green dot, giving the impression that it is "eating" the pink dots. Just like Pac-Man. Here is a related effect. Follow the light gray circle as it spins, and the darker circles will appear to change from gray to greenish. Focus on the cross at the center, and after a short time, the darker circles may begin to fade entirely. 42 - Pinna-Brelstaff Illusion This illusion is particularly dizzying. Follow the bluish dot as it moves from right to left and back again. It will appear as though parts of the tiled background are shifting, even though they are static. The only moving element is the dot. 43 - Palisade The radii of a wheel, when viewed through a palisade, appear to curve. In reality, they are perfectly straight. Mouse over the demo to remove the palisade and you will see that the radii never bend. 44 - Alternative Motion This animation demonstrates how our minds infer motion that may not actually be there. Consider the two blue dots. Different people perceive different movements: side to side, top to bottom, or even circular motion. 45 - Motion Inversion These two illustrations are identical - same shapes, same animation. The only difference is the CSS timing function. Most of the inspiration for these optical illusions came from two excellent resources: "35 optical illusions and why they trick your brain" by Patrick Pester. You can also find this article on: Medium (You can leave comments on those platforms and I will reply there). Article originally published on January 22, 2026 Share Share on Twitter
Share on Reddit Share on Linkedin Share on Facebook Other posts Drawing Homer Simpson using circles in CSS 100 Days of CSS Illustrations Fix 85% of your web accessibility issues in 5 easy steps Developing an Interactive Résumé with HTML and CSS Free web accessibility tools Social Media Links Codepen Github Youtube RSS 2009—2026 © Álvaro Montoro. |
This article, penned by Álvaro Montoro, explores the fascinating world of CSS-based optical illusions, showcasing 45 unique demonstrations designed to trick and delight the eye. The core concept revolves around leveraging CSS’s capabilities—primarily pseudo-elements and gradients—to create illusions of movement, depth, and spatial manipulation. The article provides a valuable educational resource for web developers and designers interested in exploring the creative potential of CSS, specifically its ability to mimic visual phenomena. Montoro masterfully utilizes a diverse range of optical illusions, categorized into sections like Poggendorff Illusions, Induced Gradients, and Wertheimer-Koffka rings, illustrating the principle behind each effect. The article clearly explains the technical implementation behind each illusion, detailing the use of conic gradients, radial gradients and pseudo-elements. For instance, the Poggendorff illusion demonstrates how a diagonal line with a vertical bar can create a misaligned perception. The induced gradients showcases how a flat color placed over a gradient creates the illusion of a gradient itself, highlighting the brain’s interpretation of visual information. The Ebbinghaus illusion is meticulously explained, demonstrating how the perceived size of a circle changes based on surrounding elements—a powerful reminder of how context shapes perception. Montoro doesn’t only present the illusions, but also dives into the underlying mechanics of why they work, touching upon concepts like contrast, synchrony, and perception of motion. He emphasizes the role of the browser’s rendering engine and how it is interpreting these visual cues to generate the illusion. The article also offers insights into the importance of timing functions within CSS, which contribute significantly to the perceived movement in the animations. Furthermore, the inclusion of references to external resources such as Pester’s and Bach’s work, provides a valuable roadmap for further exploration of the subject. The article's inclusion of “attention” warnings for the more complex, moving illusions, is a vital safety measure. The article’s structure is clear and concise, facilitating easy understanding. The demonstrations are self-contained and interactive, allowing the reader to directly experience the illusions and observe the CSS code that creates them. Montoro's straightforward explanations, combined with the interactive nature of the code, make this article a truly engaging and effective learning tool. Ultimately, this is a testament to Montoro's creativity and technical skill, offering a valuable resource for anyone wishing to experiment with CSS and understand the complexities of visual perception. |