Add

Lorem ipsum

Lorem ipsum

A
A
A
Tracking

1 views

5 min

Hide or Show Webflow Elements Based on the User’s Country

See how to show or hide Webflow elements based on the user’s country: GDPR banners, geo-restricted offers, localized content.

In this tutorial, Sandro, cofounder of Gemeos Webflow agency, shows you how to show or hide elements on your Webflow site based on the visitor’s country. Handy for targeting a GDPR banner to European visitors, restricting an offer to certain countries, or personalizing a welcome message.

Example

Detecting country...

🇫🇷 FR / BE / CH / LU content

This block is visible only to visitors in France, Belgium, Switzerland, and Luxembourg.

🇺🇸 Content for US / CA / GB

This block is visible only for visitors from the United States, Canada and United Kingdom.

🇩🇪 Content for DE / AT

This block is visible only to visitors from Germany and Austria.

No country-specific content in this demo.

1. Add a custom attribute to your elements

In the Webflow Designer, select the element you want to show or hide based on the country. In the "Element Settings" panel, add a custom attribute:

  • Name : data-country
  • Value : the 2-letter ISO country code (for example: FR for France, US for the United States, DE for Germany)

You can add several values separated by commas if the element should appear in multiple countries: FR,BE,CH.

By default, set these elements to display: none in your Webflow styles. The script will show them if the country matches.

Custom attributeValueExample
Namedata-countrydata-country
Value (one country)2-letter ISO codeFR
Value (multiple countries)Comma-separated codesFR,BE,CH
Default displaynone (hidden)display: none

2. Get the user’s country via the ipapi API

The ipapi.co API lets you fetch a visitor’s country for free from their IP address, with no API key needed for basic use (up to 1,000 requests per day). A fetch call to https://ipapi.co/json/ returns a JSON object, including the country_code field in 2-letter ISO format.

good to know

ipapi.co is free up to 1,000 requests per day. Beyond that, you’ll need a paid plan. For high-traffic sites, alternatives like ip-api.com (45,000 free requests per minute) or ipinfo.io are worth considering. IP-based detection isn’t foolproof: users behind a VPN may appear to be in a different country.

3. Add the script to your page footer

In Webflow, go to the relevant page’s Page Settings, open the "Before </body> tag" section, and paste the following script:

fetch('https://ipapi.co/json/')
.then(function(response) {
return response.json();
})
.then(function(data) {
var userCountry = data.country_code;
var elements = document.querySelectorAll('[data-country]');
elements.forEach(function(el) {
var countries = el.getAttribute('data-country').split(',');
if (countries.indexOf(userCountry) !== -1) {
el.style.display = 'block';
}
});
})
.catch(function(error) {
console.log('Erreur ipapi:', error);
});

The script gets the user’s country, loops through all elements with a data-country attribute, and shows the ones whose country code matches.

If you want to show a different element display type depending on the container (flex, grid), replace block with flex or grid as needed.

Conclusion

With just a few lines of JavaScript and a custom attribute, you can control how any Webflow element appears based on your visitors’ location. A few real-world use cases:

  • Show a GDPR compliance banner only to European visitors
  • Restrict a promotional offer to France and Belgium
  • Display a local phone number based on the visitor’s country
  • Personalize a welcome message ("Welcome!" vs "Welcome!") without using Webflow Localization

To go further with SEO and technical best practices in Webflow, check out our guide: 9 steps to optimize your Webflow site for SEO.

Good to know

Heading

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

Lorem ipsum dolor sit amet consectetur.

Lorem ipsum dolor sit amet consectetur. Aliquam orci sagittis dignissim sapien praesent donec.

Lorem ipsum

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Published on

You might be interested in these tutorials

Similar tutorials

SEO / GEO

5 min read

5 views

How to Set Up a Redirect in Webflow? (2026)

Updated on 19.12.2025 by Sandro DA SILVA

SEO / GEO

5 min read

5 views

Add structured data to your Webflow site?

Updated on 21.08.2025 by Sandro DA SILVA

No-code

5 min read

5 views

How to Obfuscate a Link in Webflow

Updated on 23.04.2025 by Sandro DA SILVA

Let’s f*****G GO !!

Ready to launch
Your business?

Alexandre

Max

Enora

Bryan

Cannelle

Tiphaine

You'll :heart: our collaboration...