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.

Below is a list of all the classes you can override, along with a description of what each class targets.

ClassDescriptionDefault Value
sectionThe wrapper `<section>` element for the entire component.
containerThe container for the input field and dropdown.
relative z-10 transform rounded-xl mt-4
icon_containerContainer for the search icon.
pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3
iconThe SVG search icon. Customize this to use a different 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>
inputStyles for the input field.
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_containerContainer for keyboard shortcut hints.
absolute inset-y-0 right-0 flex py-1.5 pr-1.5
kbd_escapeStyle for the "Esc" key hint.
inline-flex items-center rounded border border-gray-300 px-1 font-sans text-xs text-gray-500 w-8 mr-1
kbd_upStyle for the "Up" key hint.
inline-flex items-center justify-center rounded border border-gray-300 px-1 font-sans text-xs text-gray-500 w-6
kbd_downStyle for the "Down" key hint.
inline-flex items-center rounded border border-gray-400 px-1 font-sans text-xs text-gray-500 justify-center w-6
kbd_activeStyle for the active key hint.
bg-indigo-500 text-white
ulStyles for the suggestions dropdown (<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
liStyles for each suggestion list item (<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_currentStyles for the currently highlighted/selected suggestion.
bg-indigo-500
li_aStyles for the anchor link (<a>) within each list item.
block w-full flex justify-between
li_a_currentStyles for the currently highlighted/selected anchor link.
text-white
li_div_containerContainer for the content within each list item.
flex min-w-0 gap-x-4
li_div_oneContainer for the primary text content within each list item.
min-w-0 flex-auto
li_div_one_pPrimary text content within each list item.
text-sm/6 font-semibold
li_div_twoContainer for the secondary text content within each list item (e.g., distance).
shrink-0 flex flex-col items-end min-w-16
li_div_two_pSecondary text content within each list item.
mt-1 text-xs/5
highlightThe class applied to the <span> wrapping the matched text within suggestions.
font-bold

Code

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} 
/>					

2025 Places Autocomplete Svelte.