Category · Search Components Difficulty Level · Intermediate Published on · January 22, 2024

Animated Search Bar

A modern, interactive search bar with smooth animations, auto-suggestions, voice search, and multiple visual styles. Perfect for websites, dashboards, and applications requiring elegant search functionality.

#search #animation #autocomplete #voice #input

Responsive Design

Yes

Dark Mode Support

Yes

lines

1203

Browser Compatibility

No

Live Preview

Interact with the component without leaving the page.

600px

A comprehensive collection of modern, animated search bars featuring smooth transitions, auto-suggestions, voice search capabilities, and multiple visual styles. Perfect for websites, dashboards, and applications requiring elegant and functional search interfaces.

Features

  • Multiple Search Styles: Classic animated, expanding, glassmorphism, and advanced with suggestions
  • Smart Suggestions: Auto-complete with search history, trending terms, and popular searches
  • Voice Search: Built-in speech recognition for hands-free searching
  • Real-time Results: Live search results with highlighting and filtering
  • Keyboard Navigation: Full keyboard support with arrow keys and shortcuts
  • Search History: Persistent search history with localStorage
  • Responsive Design: Optimized for all screen sizes and devices
  • Accessibility Ready: ARIA labels, screen reader support, and keyboard navigation

Search Bar Variants

Classic Animated

  • Clean, professional design with subtle border animation
  • Smooth focus transitions and hover effects
  • Perfect for corporate websites and professional applications
  • Compact icon that expands into full search bar
  • Space-saving design ideal for navigation bars
  • Smooth expand/collapse animations

Glassmorphism Style

  • Modern frosted glass effect with backdrop blur
  • Semi-transparent design with elegant visual depth
  • Includes voice search integration

Advanced with Suggestions

  • Full-featured search with auto-complete dropdown
  • Search history and trending suggestions
  • Voice search and filter options
  • Real-time search results display

Usage Examples

<!-- Basic animated search -->
<div class="search-wrapper classic">
  <div class="search-box">
    <input type="text" class="search-input" placeholder="Search anything...">
    <button class="search-btn" type="button">
      <svg class="search-icon" width="20" height="20" viewBox="0 0 24 24" fill="none">
        <circle cx="11" cy="11" r="8" stroke="currentColor" stroke-width="2"/>
        <path d="M21 21L16.65 16.65" stroke="currentColor" stroke-width="2"/>
      </svg>
    </button>
    <div class="search-border"></div>
  </div>
</div>

<!-- Expanding search -->
<div class="search-wrapper expanding">
  <div class="search-box">
    <button class="search-trigger" type="button">
      <svg class="search-icon" width="20" height="20" viewBox="0 0 24 24" fill="none">
        <circle cx="11" cy="11" r="8" stroke="currentColor" stroke-width="2"/>
        <path d="M21 21L16.65 16.65" stroke="currentColor" stroke-width="2"/>
      </svg>
    </button>
    <input type="text" class="search-input" placeholder="Type to search...">
    <button class="search-close" type="button">
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none">
        <path d="M18 6L6 18M6 6L18 18" stroke="currentColor" stroke-width="2"/>
      </svg>
    </button>
  </div>
</div>

JavaScript API

// Initialize search bar
const searchBar = new AnimatedSearchBar();

// Programmatic search
searchBar.search('javascript tutorials');

// Add custom search data
searchBar.setSearchData([
  {
    title: "Custom Result",
    description: "This is a custom search result",
    url: "https://example.com/custom"
  }
]);

// Add custom suggestion
searchBar.addSuggestion({
  text: 'custom search term',
  type: 'Custom',
  icon: 'settings'
});

// Get search history
const history = searchBar.getSearchHistory();

// Clear search results
searchBar.clearResults();

// Get performance metrics
const metrics = searchBar.getPerformanceMetrics();

Customization Options

Search Styles

  • Classic: Traditional search with animated border
  • Expanding: Compact icon that expands on click
  • Glassmorphism: Modern frosted glass effect
  • Advanced: Full-featured with suggestions and filters

Voice Search Integration

// Voice search is automatically enabled if supported
// Customize voice recognition settings
recognition.lang = 'en-US'; // Set language
recognition.continuous = false; // Single result
recognition.interimResults = false; // Final results only

Custom Suggestions

// Add custom suggestion categories
const customSuggestions = [
  { text: 'product search', type: 'Products', icon: 'shopping' },
  { text: 'user profiles', type: 'Users', icon: 'user' },
  { text: 'documentation', type: 'Docs', icon: 'book' }
];

customSuggestions.forEach(suggestion => {
  searchBar.addSuggestion(suggestion);
});

Accessibility Features

  • Keyboard Navigation: Arrow keys, Enter, Escape support
  • Screen Reader Support: Proper ARIA labels and descriptions
  • Focus Management: Clear focus indicators and logical tab order
  • Voice Search: Alternative input method for accessibility
  • High Contrast: Compatible with high contrast modes
  • Reduced Motion: Respects user motion preferences

Browser Support

  • Chrome 60+ (full support)
  • Firefox 55+ (full support)
  • Safari 12+ (full support)
  • Edge 79+ (full support)
  • iOS Safari 12+ (full support)
  • Android Chrome 60+ (full support)

Voice Search Support:

  • Chrome 25+ (webkitSpeechRecognition)
  • Edge 79+ (SpeechRecognition)
  • Limited support in Firefox and Safari

Performance Considerations

  • Debounced Search: Prevents excessive API calls during typing
  • Virtual Scrolling: Efficient handling of large suggestion lists
  • Memory Management: Proper cleanup of event listeners
  • Lazy Loading: Search results loaded on demand
  • Caching: Search history and suggestions cached locally

Integration Examples

<!-- E-commerce search -->
<div class="search-wrapper advanced">
  <div class="search-box">
    <div class="search-input-wrapper">
      <svg class="search-icon">...</svg>
      <input type="text" class="search-input" placeholder="Search products...">
      <div class="search-actions">
        <button class="voice-btn" title="Voice Search">🎤</button>
        <button class="filter-btn" title="Filters">🔍</button>
      </div>
    </div>
  </div>
</div>

<!-- Documentation search -->
<div class="search-wrapper glassmorphism">
  <div class="search-box">
    <svg class="search-icon">...</svg>
    <input type="text" class="search-input" placeholder="Search docs...">
    <button class="voice-btn" title="Voice Search">🎤</button>
  </div>
</div>

Advanced Configuration

// Custom search configuration
const config = {
  searchDelay: 300, // Debounce delay in ms
  maxSuggestions: 8, // Maximum suggestions to show
  maxHistory: 10, // Maximum history items
  enableVoice: true, // Enable voice search
  enableHistory: true, // Enable search history
  highlightResults: true // Highlight search terms in results
};

const searchBar = new AnimatedSearchBar(config);

HTML

152

lines

CSS

567

lines

JavaScript

484

lines


                <div class="search-container">
  <div class="search-header">
    <h2 class="search-title">Animated Search Bar Collection</h2>
    <p class="search-subtitle">Modern search interfaces with smooth animations and smart features</p>
  </div>
  
  <div class="search-demos">
    <!-- Classic Animated Search -->
    <div class="search-demo">
      <h3 class="demo-title">Classic Animated</h3>
      <div class="search-wrapper classic">
        <div class="search-box">
          <input type="text" class="search-input" placeholder="Search anything..." id="classicSearch">
          <button class="search-btn" type="button">
            <svg class="search-icon" width="20" height="20" viewBox="0 0 24 24" fill="none">
              <circle cx="11" cy="11" r="8" stroke="currentColor" stroke-width="2"/>
              <path d="M21 21L16.65 16.65" stroke="currentColor" stroke-width="2"/>
            </svg>
          </button>
          <div class="search-border"></div>
        </div>
      </div>
    </div>
    
    <!-- Expanding Search -->
    <div class="search-demo">
      <h3 class="demo-title">Expanding Search</h3>
      <div class="search-wrapper expanding">
        <div class="search-box">
          <button class="search-trigger" type="button">
            <svg class="search-icon" width="20" height="20" viewBox="0 0 24 24" fill="none">
              <circle cx="11" cy="11" r="8" stroke="currentColor" stroke-width="2"/>
              <path d="M21 21L16.65 16.65" stroke="currentColor" stroke-width="2"/>
            </svg>
          </button>
          <input type="text" class="search-input" placeholder="Type to search..." id="expandingSearch">
          <button class="search-close" type="button">
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none">
              <path d="M18 6L6 18M6 6L18 18" stroke="currentColor" stroke-width="2"/>
            </svg>
          </button>
        </div>
      </div>
    </div>
    
    <!-- Glassmorphism Search -->
    <div class="search-demo">
      <h3 class="demo-title">Glassmorphism Style</h3>
      <div class="search-wrapper glassmorphism">
        <div class="search-box">
          <svg class="search-icon" width="20" height="20" viewBox="0 0 24 24" fill="none">
            <circle cx="11" cy="11" r="8" stroke="currentColor" stroke-width="2"/>
            <path d="M21 21L16.65 16.65" stroke="currentColor" stroke-width="2"/>
          </svg>
          <input type="text" class="search-input" placeholder="Search with style..." id="glassSearch">
          <button class="voice-btn" type="button" title="Voice Search">
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none">
              <path d="M12 1C10.34 1 9 2.34 9 4V12C9 13.66 10.34 15 12 15S15 13.66 15 12V4C15 2.34 13.66 1 12 1Z" stroke="currentColor" stroke-width="2"/>
              <path d="M19 10V12C19 16.42 15.42 20 11 20H13C17.42 20 21 16.42 21 12V10" stroke="currentColor" stroke-width="2"/>
              <path d="M12 20V24" stroke="currentColor" stroke-width="2"/>
              <path d="M8 24H16" stroke="currentColor" stroke-width="2"/>
            </svg>
          </button>
        </div>
      </div>
    </div>
    
    <!-- Advanced Search with Suggestions -->
    <div class="search-demo">
      <h3 class="demo-title">Advanced with Suggestions</h3>
      <div class="search-wrapper advanced">
        <div class="search-box">
          <div class="search-input-wrapper">
            <svg class="search-icon" width="20" height="20" viewBox="0 0 24 24" fill="none">
              <circle cx="11" cy="11" r="8" stroke="currentColor" stroke-width="2"/>
              <path d="M21 21L16.65 16.65" stroke="currentColor" stroke-width="2"/>
            </svg>
            <input type="text" class="search-input" placeholder="Search with suggestions..." id="advancedSearch" autocomplete="off">
            <div class="search-actions">
              <button class="voice-btn" type="button" title="Voice Search">
                <svg width="16" height="16" viewBox="0 0 24 24" fill="none">
                  <path d="M12 1C10.34 1 9 2.34 9 4V12C9 13.66 10.34 15 12 15S15 13.66 15 12V4C15 2.34 13.66 1 12 1Z" stroke="currentColor" stroke-width="2"/>
                  <path d="M19 10V12C19 16.42 15.42 20 11 20H13C17.42 20 21 16.42 21 12V10" stroke="currentColor" stroke-width="2"/>
                  <path d="M12 20V24" stroke="currentColor" stroke-width="2"/>
                  <path d="M8 24H16" stroke="currentColor" stroke-width="2"/>
                </svg>
              </button>
              <button class="filter-btn" type="button" title="Filters">
                <svg width="16" height="16" viewBox="0 0 24 24" fill="none">
                  <polygon points="22,3 2,3 10,12.46 10,19 14,21 14,12.46" stroke="currentColor" stroke-width="2" fill="none"/>
                </svg>
              </button>
            </div>
          </div>
          <div class="suggestions-dropdown" id="suggestionsDropdown">
            <div class="suggestions-header">
              <span class="suggestions-title">Suggestions</span>
              <button class="clear-history" type="button">Clear</button>
            </div>
            <ul class="suggestions-list" id="suggestionsList">
              <li class="suggestion-item" data-value="javascript tutorials">
                <svg class="suggestion-icon" width="16" height="16" viewBox="0 0 24 24" fill="none">
                  <circle cx="12" cy="12" r="3" stroke="currentColor" stroke-width="2"/>
                  <path d="M19.4 15C19.2 15.3 19.1 15.6 19.1 16S19.2 16.7 19.4 17L20.7 18.3C20.9 18.5 20.9 18.9 20.7 19.1L19.1 20.7C18.9 20.9 18.5 20.9 18.3 20.7L17 19.4C16.7 19.6 16.4 19.7 16 19.7S15.3 19.6 15 19.4L13.7 20.7C13.5 20.9 13.1 20.9 12.9 20.7L11.3 19.1C11.1 18.9 11.1 18.5 11.3 18.3L12.6 17C12.4 16.7 12.3 16.4 12.3 16S12.4 15.3 12.6 15L11.3 13.7C11.1 13.5 11.1 13.1 11.3 12.9L12.9 11.3C13.1 11.1 13.5 11.1 13.7 11.3L15 12.6C15.3 12.4 15.6 12.3 16 12.3S16.7 12.4 17 12.6L18.3 11.3C18.5 11.1 18.9 11.1 19.1 11.3L20.7 12.9C20.9 13.1 20.9 13.5 20.7 13.7L19.4 15Z" stroke="currentColor" stroke-width="2"/>
                </svg>
                <span class="suggestion-text">javascript tutorials</span>
                <span class="suggestion-type">Popular</span>
              </li>
              <li class="suggestion-item" data-value="react components">
                <svg class="suggestion-icon" width="16" height="16" viewBox="0 0 24 24" fill="none">
                  <circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2"/>
                  <path d="M8 14S9.5 16 12 16S16 14 16 14" stroke="currentColor" stroke-width="2"/>
                  <line x1="9" y1="9" x2="9.01" y2="9" stroke="currentColor" stroke-width="2"/>
                  <line x1="15" y1="9" x2="15.01" y2="9" stroke="currentColor" stroke-width="2"/>
                </svg>
                <span class="suggestion-text">react components</span>
                <span class="suggestion-type">Recent</span>
              </li>
              <li class="suggestion-item" data-value="css animations">
                <svg class="suggestion-icon" width="16" height="16" viewBox="0 0 24 24" fill="none">
                  <path d="M13 2L3 14H12L11 22L21 10H12L13 2Z" stroke="currentColor" stroke-width="2"/>
                </svg>
                <span class="suggestion-text">css animations</span>
                <span class="suggestion-type">Trending</span>
              </li>
              <li class="suggestion-item" data-value="web development">
                <svg class="suggestion-icon" width="16" height="16" viewBox="0 0 24 24" fill="none">
                  <rect x="2" y="3" width="20" height="14" rx="2" ry="2" stroke="currentColor" stroke-width="2"/>
                  <line x1="8" y1="21" x2="16" y2="21" stroke="currentColor" stroke-width="2"/>
                  <line x1="12" y1="17" x2="12" y2="21" stroke="currentColor" stroke-width="2"/>
                </svg>
                <span class="suggestion-text">web development</span>
                <span class="suggestion-type">Popular</span>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
  
  <!-- Search Results Demo -->
  <div class="search-results" id="searchResults">
    <div class="results-header">
      <h3>Search Results</h3>
      <span class="results-count" id="resultsCount">0 results</span>
    </div>
    <div class="results-list" id="resultsList">
      <!-- Results will be populated here -->
    </div>
  </div>
</div>

              
152lines
8571characters
HTMLLanguage

Related Code Snippets

Explore template packs

Need larger building blocks? Browse responsive landing pages and component bundles.

Open HTML Template Library →