https://developer.mozilla.org/en-US/docs/Web/API/Topics_API/Using * Skip to main content * Skip to search * Skip to select language Open main menu * ReferencesReferences + Overview / Web Technology Web technology reference for developers + HTML Structure of content on the web + CSS Code used to describe document style + JavaScript General-purpose scripting language + HTTP Protocol for transmitting web resources + Web APIs Interfaces for building web applications + Web Extensions Developing extensions for web browsers + Web Technology Web technology reference for developers * GuidesGuides + Overview / MDN Learning Area Learn web development + MDN Learning Area Learn web development + HTML Learn to structure web content with HTML + CSS Learn to style content using CSS + JavaScript Learn to run scripts in the browser + Accessibility Learn to make the web accessible to all * PlusPlus + Overview A customized MDN experience + AI Help Get real-time assistance and support + Updates All browser compatibility updates at a glance + Documentation Learn how to use MDN Plus + FAQ Frequently asked questions about MDN Plus * Curriculum * Blog * Tools + Playground Write, test and share your code + HTTP Observatory Scan a website for free + AI Help Get real-time assistance and support Search MDN[ ]Clear search inputSearch Theme * Log in * Sign up for free 1. References 2. Web APIs 3. Topics API 4. Using the Topics API Filter sidebar[ ]Clear filter input In this article * High-level overview * What API features enable the Topics API? * Private topic sets * Examples * Testing hints * See also 1. Topics API 2. Guides 1. Using the Topics API 3. Properties 1. HTMLIFrameElement.browsingTopics 4. Methods 1. Document.browsingTopics() 2. Window.fetch() In this article * High-level overview * What API features enable the Topics API? * Private topic sets * Examples * Testing hints * See also Using the Topics API Warning: This feature is currently opposed by two browser vendors. See the Standards positions section below for details of opposition. Note: An Enrollment process is required to use the Topics API in your applications. See the Enrollment section for details of what sub-features are gated by enrollment. This page explains how the Topics API works and how it can be used to create an interest-based advertising (IBA) solution. High-level overview Let's say we've got an ad tech platform, ad-tech1.example, which is embedding ads via + Programmatically by setting the equivalent HTMLIFrameElement.browsingTopics property to true: js const iframeElem = document.querySelector("iframe"); iframeElem.browsingTopics = true; When the request associated with one of the above features is sent: 1. A Sec-Browsing-Topics header is sent along with the request, which contains the top topic(s) for the current user. 2. The ad tech server selects a relevant ad to display in the Complete examples * Topics API demo: Demonstrates how document.browsingTopics() calls can be used to observe and then access topics (see source code). * Topics API header demo: Demonstrates a fetch() request with a Sec-Browsing-Topics header can be used to observe and then access topics (see source code). Testing hints Chrome The default epoch length for observing topics is one week, which is way too long to test code that uses the Topics API. To shorten this for test purposes, in Chrome you can open the browser with a feature flag along the following lines: bash BrowsingTopicsParameters:time_period_per_epoch/15s/max_epoch_introduction_delay/3s See Run Chromium with command-line switches for more information on how to do this. You can also test your Topics API code locally without enrollment by enabling the following Chrome developer flag: chrome://flags/#privacy-sandbox-enrollment-overrides See also * Topics API on developers.google.com (2023) Help improve MDN Was this page helpful to you? YesNo Learn how to contribute. This page was last modified on Sep 2, 2024 by MDN contributors. View this page on GitHub * Report a problem with this content Your blueprint for a better internet. * MDN on Mastodon * MDN on X (formerly Twitter) * MDN on GitHub * MDN Blog RSS Feed MDN * About * Blog * Careers * Advertise with us Support * Product help * Report an issue Our communities * MDN Community * MDN Forum * MDN Chat Developers * Web Technologies * Learn Web Development * MDN Plus * Hacks Blog * Website Privacy Notice * Cookies * Legal * Community Participation Guidelines Visit Mozilla Corporation's not-for-profit parent, the Mozilla Foundation. Portions of this content are (c)1998-2024 by individual mozilla.org contributors. Content available under a Creative Commons license.