Advertisement

Viking Rune Wood Toggle

| by Vladimir | 2 min read | code by santhosh_2608
A11y Ready Advanced

Tech & Dependencies

HTML CSS

Features

  • Particle System
  • Complex Gradients
  • SVG Filters
  • Glow Effects

Browser Support

Chrome 60+ Edge 79+ Firefox 55+ Safari 11+

Core

This Viking Rune Wood Toggle demonstrates how far CSS styling can go without JavaScript. It recreates a physical artifact - a wooden switch with bronze inlays and magical runes - perfect for RPG game interfaces or fantasy-themed websites. The switch features a “fire” state when active, complete with pulsating runes and floating ember particles, creating an immersive, tactile experience.

Core Technique

The visual richness comes from heavy use of layered backgrounds and pseudo-elements.

  1. Wood & Noise: The track background combines a linear-gradient (for the wood tones) with an inline SVG Data URI containing a feTurbulence filter. This adds a realistic grainy texture to the surface.
  2. Metallic Inlays: Gradients with hard stops (var(--vt-bronze) 15%, var(--vt-metal-medium) 30%) simulate the reflection of light on metal surfaces (bronze/gold) around the border and knob.
  3. Particle System: The “embers” are span elements absolutely positioned within the track. They use a @keyframes animation (viking-ember-float) to drift upwards and fade out, mimicking rising sparks.
  4. State Changes: The :checked pseudo-class triggers multiple changes: moving the knob (left), intensifying the box-shadow to create a glow (--vt-fire-glow), and changing the text shadow of the runes.

Customization

Theme colors are defined as CSS variables, allowing for easy adjustments.

.viking-toggle {
  /* Wood Tones */
  --vt-wood-dark: #1a1208;
  --vt-wood-medium: #2d2116;
  
  /* Fire/Active Colors */
  --vt-fire: #ff6a00;
  --vt-fire-glow: rgba(255, 120, 40, 0.6);
}

To change the symbols, simply edit the text content inside the HTML span.

<span class="viking-toggle__runes">ᛟ ᛏ ᛞ ᛁ ᚾ</span>

Tips

1. SVG Filters for Texture: Using inline SVG for noise (filter='url(#noise)') is a powerful technique to add texture without external image requests. It’s performant and scales infinitely.

2. Focus Indicators: The toggle includes :focus-visible styles (outline: 3px solid var(--vt-gold)). This is crucial for accessibility, ensuring that keyboard users can clearly see when the switch is focused, even amidst the complex visual design.

Advertisement