Styling

The Places Autocomplete Svelte component is designed to be highly customizable, allowing you to tailor its appearance to match your application's design. You can override the default styles by providing your own CSS classes for various parts of the component.

Default Styles

The component includes built-in styles with .pac- prefixed CSS classes, providing a complete, accessible UI out of the box. These styles are:

✨ Framework-Agnostic

Pure CSS with no dependencies on Tailwind or other frameworks.

🎨 Modern Design

Clean, professional appearance with proper spacing, shadows, and hover effects.

⚡ Fully Functional

Includes keyboard navigation indicators, loading states, and responsive behavior.

🔧 Customizable

All styles can be overridden via the options.classes prop.

💡 How It Works

Override any default styling by providing your own CSS classes via options.classes. Your custom classes will replace the default .pac- classes for the specified elements.

\n\t\t\t\t

Component Classes Reference

Below is a complete list of all the classes you can override, along with their default class names and descriptions.

ClassDescriptionDefault Value
sectionThe wrapper `<section>` element for the entire component.
.pac-section
containerThe container for the input field and dropdown.
.pac-container
labelThe `<label>` element for the input field.
.pac-label
icon_containerContainer for the search icon (positioned absolutely).
.pac-icon-container
iconThe SVG search icon. Customize this to use a different icon.
SVG string
inputStyles for the input field with focus states and shadow.
.pac-input
kbd_containerContainer for keyboard shortcut hints (Esc, ↑, ↓).
.pac-kbd-container
kbd_escapeStyle for the "Esc" key hint.
.pac-kbd-escape
kbd_upStyle for the "Up" arrow key hint.
.pac-kbd-up
kbd_downStyle for the "Down" arrow key hint.
.pac-kbd-down
kbd_activeStyle applied to keyboard hints when active/highlighted.
.pac-kbd-active
ulStyles for the suggestions dropdown (<ul>) with scroll behavior.
.pac-ul
liStyles for each suggestion list item (<li>) with hover states.
.pac-li
li_currentStyles for the currently highlighted/selected suggestion item.
.pac-li-current
li_buttonThe `<button>` element within each list item.
.pac-li-button
li_button_currentStyles for the currently highlighted button within list items.
.pac-li-button-current
li_div_containerContainer div for content within each list item.
.pac-li-div-container
li_div_oneFirst inner div containing the main text content.
.pac-li-div-one
li_div_one_pThe `<p>` tag containing the primary suggestion text with matched highlighting.
.pac-li-div-one-p
li_div_one_p_secondaryTextThe `<p>` tag for secondary/subtitle text (e.g., city, country).
.pac-li-div-one-p-secondaryText
li_div_p_containerContainer for paragraph elements within list items.
.pac-li-div-p-container
li_div_twoSecond inner div containing secondary info (e.g., distance).
.pac-li-div-two
li_div_two_pThe `<p>` tag containing distance or secondary metrics.
.pac-li-div-two-p
map_pin_iconThe SVG map pin icon displayed next to suggestions.
SVG string
highlightThe class applied to the <span> wrapping matched text within suggestions for emphasis.
.pac-highlight

Styling Examples

Here are practical examples of customizing the component with different CSS frameworks and approaches.

Tailwind CSS

Override classes with Tailwind utility classes:

const options = {
  classes: {
    input: 'w-full px-4 py-2.5 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500',
    ul: 'absolute mt-1 w-full bg-white shadow-lg rounded-md border border-gray-200 max-h-60 overflow-auto',
    li: 'px-4 py-2 hover:bg-blue-500 hover:text-white cursor-pointer',
    li_current: 'bg-blue-500 text-white',
    highlight: 'font-semibold text-blue-700'
  }
};

Custom CSS Classes

Use your own custom CSS class names:

const options = {
  classes: {
    section: 'autocomplete-wrapper',
    input: 'search-input',
    ul: 'suggestions-list',
    li: 'suggestion-item',
    li_current: 'suggestion-item--active',
    highlight: 'match-highlight'
  }
};

Dark Mode

Create a dark theme variant:

const options = {
  classes: {
    input: 'w-full px-4 py-2.5 bg-slate-800 text-slate-100 border border-slate-600 rounded-md focus:ring-2 focus:ring-sky-500',
    ul: 'absolute mt-1 w-full bg-slate-800 shadow-lg rounded-md border border-slate-600 max-h-60 overflow-auto',
    li: 'px-4 py-2 text-slate-300 hover:bg-sky-600 hover:text-white cursor-pointer',
    li_current: 'bg-sky-600 text-white',
    highlight: 'font-semibold text-sky-400'
  }
};

Complete Code Example

Copy and paste the following code into your Svelte application and replace ___YOUR_API_KEY___ with your actual API key to start using the Places Autocomplete Svelte component.

<script lang="ts">
import { PlaceAutocomplete } from 'places-autocomplete-svelte';
// Google Maps API key
const PUBLIC_GOOGLE_MAPS_API_KEY = '___YOUR_API_KEY___';

const options = {
	classes : {
		section: '',
		container: 'relative z-10 transform rounded-xl mt-4',
		icon_container: 'pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3',
		icon: '<svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8" /><path d="m21 21-4.3-4.3" /></svg>',
		input:
			'border-1 w-full rounded-md border-0 shadow-sm bg-gray-100 px-4 py-2.5 pl-10 pr-20 text-gray-900 ring-1 ring-inset ring-gray-300 focus:ring-2 sm:text-sm',
		kbd_container: 'absolute inset-y-0 right-0 flex py-1.5 pr-1.5',
		kbd_escape:
			'inline-flex items-center rounded border border-gray-300 px-1 font-sans text-xs text-gray-500 w-8 mr-1',
		kbd_up:
			'inline-flex items-center justify-center rounded border border-gray-300 px-1 font-sans text-xs text-gray-500 w-6',
		kbd_down:
			'inline-flex items-center rounded border border-gray-400 px-1 font-sans text-xs text-gray-500 justify-center w-6',
		kbd_active: 'bg-indigo-500 text-white',
		ul: 'absolute z-50 -mb-2 mt-1 max-h-60 w-full overflow-auto rounded-md bg-white py-1 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm divide-y divide-gray-100',
		li: 'z-50 cursor-default select-none py-2 px-2 lg:px-4 text-gray-900 hover:bg-indigo-500 hover:text-white',
		li_current: 'bg-indigo-500',
		li_a: 'block w-full flex justify-between',
		li_a_current: 'text-white',
		li_div_container: 'flex min-w-0 gap-x-4',
		li_div_one: 'min-w-0 flex-auto',
		li_div_one_p: 'text-sm/6 ',
		li_div_two: 'shrink-0 flex flex-col items-end min-w-16',
		li_div_two_p: 'mt-1 text-xs/5',
		highlight: 'font-bold',
	}
}
...
</script>

<PlaceAutocomplete 
	{onError} 
	{onResponse} 
	{options}
	{PUBLIC_GOOGLE_MAPS_API_KEY} 
/>					

Google Maps Platform

Awards 2025 Winner

GitHub

2026 Places Autocomplete Svelte.