404 Error Page
An entertaining, interactive custom 404 error page that turns the frustrating experience of hitting a dead link into a delightful user engagement opportunity.
Overviewβ
The custom 404 page replaces the default Docusaurus error page with an interactive, humorous experience featuring:
- Animated Rainbow 404 Display with CSS gradient animations
- Rotating Excuse Generator that cycles through funny explanations every 3 seconds
- Interactive Cat Facts Spinner with rotation animations
- Emergency Navigation with quick links to important pages
- Fake Statistics displaying random "helpful" metrics
- Absurd Troubleshooting Tips mixing technical and creative "solutions"
π¨ Featuresβ
Core Interactive Elementsβ
-
Rainbow Animated 404 Number
- Multi-color gradient background that shifts continuously
- Large 8rem font size for maximum visual impact
- CSS keyframe animation with 3-second cycle
-
Excuse Generatorβ’
- 15 humorous excuses that rotate automatically
- Smooth transitions with 0.5s ease animation
- Emoji-rich content for visual appeal
-
Cat Facts Spinner
- Interactive button with rotation animation
- Random cat facts that are tangentially related to the error
- 1-second spin animation on click
-
Emergency Navigation
- Quick access buttons to Home, Docs, and Demos
- Styled as prominent secondary buttons
- Organized in a responsive button group
-
Fun Statistics Cards
- Randomized "Pages Found Today" counter
- "Robots Consulted" with fake numbers
- "Coffee Consumed" by developers
User Experience Featuresβ
- Responsive Design: Works seamlessly on all device sizes
- Accessibility: Proper ARIA labels and semantic HTML
- Performance: Lightweight with minimal JavaScript
- Brand Consistency: Uses site's design tokens and themes
π File Structureβ
src/pages/
βββ 404.tsx # Custom 404 page component
src/theme/NotFound/
βββ index.tsx # Docusaurus NotFound component override
π§ Technical Implementationβ
Component Architectureβ
The 404 system uses a modern reusable component architecture:
// Reusable core component (v1.0)
export default function Custom404Component(): React.JSX.Element {
const [excuse, setExcuse] = useState(0);
const [isSpinning, setIsSpinning] = useState(false);
const [catFact, setCatFact] = useState('');
// Auto-rotating excuse system (enhanced)
useEffect(() => {
const interval = setInterval(() => {
setExcuse((prev) => (prev + 1) % excuses.length);
}, 3000);
return () => clearInterval(interval);
}, [excuses.length]);
// Random cat fact initialization
useEffect(() => {
setCatFact(catFacts[Math.floor(Math.random() * catFacts.length)]);
}, []);
const handleSpinClick = () => {
setIsSpinning(true);
setTimeout(() => setIsSpinning(false), 1000);
setCatFact(catFacts[Math.floor(Math.random() * catFacts.length)]);
};
// Enhanced render logic with accessibility
}
Theme-Level Integration (New in v1.0)β
// Theme NotFound Content component
import Custom404 from '../../../components/Custom404';
export default function ContentWrapper(): ReactNode {
return (
<>
<Custom404 />
</>
);
}
This architecture provides:
- Reusability: Same component used in pages and theme
- Global Coverage: Handles ALL 404s through theme integration
- Component Isolation: Separated logic from presentation
CSS Animationsβ
The page includes inline CSS animations for the rainbow effect:
@keyframes rainbow {
0% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}
State Managementβ
- excuse: Index of currently displayed excuse (auto-increments)
- isSpinning: Boolean for button rotation animation
- catFact: Currently displayed cat fact (random selection)
π Content Strategyβ
Excuse Categoriesβ
The excuse generator includes diverse categories:
- Animal-related: Dogs eating pages, unicorns, dragons
- Technology: Robots, JavaScript, parallel dimensions
- Pop culture: Wizards, pirates, zombies, aliens
- Absurd daily life: Pizza runs, toilet paper shortages, circus acts
Cat Facts Integrationβ
Cat facts are chosen to be:
- Genuinely interesting but tangentially related to the error
- Light-hearted and maintaining the playful tone
- Educational while being entertaining
Troubleshooting Humorβ
Divided into two categories:
- Technical Solutions: Parodies of real troubleshooting (restarting, blowing in cartridges)
- Creative Solutions: Completely absurd suggestions (interpretive dance, parallel universes)
π Integrationβ
Docusaurus Integrationβ
The 404 page integrates with Docusaurus through:
- File-based Routing: Located at
src/pages/404.tsx
- Layout Component: Uses
@theme/Layout
for consistent styling - Link Component: Uses
@docusaurus/Link
for internal navigation - Theme Integration: Respects site's CSS custom properties
NotFound Overrideβ
The src/theme/NotFound/index.tsx
provides the same functionality for Docusaurus's built-in 404 handling.
π Analytics Integrationβ
The page includes engagement opportunities:
- Links to demos and documentation
- Call-to-action for exploring the site
- Fake but entertaining statistics that could be replaced with real analytics
π¨ Customizationβ
Easy Modificationsβ
- Add New Excuses: Extend the
excuses
array - Change Animation Timing: Modify
useEffect
intervals - Update Cat Facts: Replace or extend the
catFacts
array - Modify Statistics: Change the random number generators
- Customize Colors: Update the gradient in the rainbow animation
Branding Customizationβ
The page uses CSS custom properties for easy theming:
--ifm-color-primary
: For accent colors--ifm-color-emphasis-*
: For text and background variations--ifm-background-color
: For card backgrounds
π Related Componentsβ
- Layout: Docusaurus theme layout wrapper
- Link: Internal navigation component
- RelatedResources: Can be added for additional navigation
π Best Practicesβ
Performanceβ
- Minimal JavaScript with efficient
useEffect
cleanup - CSS animations instead of JavaScript animations
- Lazy loading of random content
SEO & Accessibilityβ
- Proper meta tags and title
- Semantic HTML structure
- Descriptive alt text and ARIA labels
- Keyboard navigation support
User Experienceβ
- Clear navigation options
- Entertaining content that reduces frustration
- Responsive design for all devices
- Fast loading with minimal dependencies
π Usage Exampleβ
// The 404 page is automatically used by Docusaurus
// No manual integration required - just place at src/pages/404.tsx
// For manual usage in other routes:
import Custom404Page from '@site/src/pages/404';
export default function SomeErrorPage() {
return <Custom404Page />;
}
π§ Configurationβ
The 404 page requires no configuration but can be customized through:
- Content Arrays: Modify excuses and cat facts
- Timing Values: Change animation and rotation intervals
- Styling: Update CSS custom properties in your theme
- Navigation Links: Modify the emergency navigation buttons
This 404 page transforms a negative user experience into an opportunity for brand engagement, demonstrating attention to detail and user experience throughout the entire site.