> ## Documentation Index
> Fetch the complete documentation index at: https://docs.beyondwords.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Build your own UI

Use headless mode when you need full control over the widget interface (custom layouts, branded controls, or deep integration into your app), while the BeyondWords SDK still handles playback, streaming, [analytics](https://docs.beyondwords.io/docs-and-guides/audio/analytics.md), and [ads](https://docs.beyondwords.io/docs-and-guides/audio/ads.md).

> [!TIP]
>
> For most sites, [widget settings](https://docs.beyondwords.io/docs-and-guides/widget.md) in the project dashboard are enough. Only build a custom UI if you need a fundamentally different experience. For minor style tweaks, see [style overrides](#style-overrides) below, but prefer dashboard settings where possible.

## When to use headless mode

| Approach | Use when |
| - | - |
| [**Widget settings**](https://docs.beyondwords.io/docs-and-guides/widget.md) | Version, colors, sticky widget, and highlighting, with no code required |
| [**Style overrides**](#style-overrides) | Small CSS tweaks to the built-in UI |
| **Headless mode** (this guide) | Fully custom controls and layout |
| [**Direct API calls**](#direct-api-calls) | You don't want any widget code (loses analytics, ads, segment playback, and more) |

## How it works

1. Initialize the widget with `showUserInterface: false` (or omit `target` to mount headlessly at the end of `<body>`).
2. The SDK still loads content, manages the media element, and fires [events](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/events.md).
3. Your code reads widget state (`currentTime`, `playbackState`, `content`, etc.) and renders your own UI.
4. Your UI writes back to widget properties (`playbackState = 'playing'`, `currentTime = 30`, etc.).

The widget always mounts in the DOM because playback uses a native media element (`<video>`). With `playerStyle: "video"` and `showUserInterface: false`, the video element renders without built-in controls.

## Enable headless mode

**Option 1: Hide the built-in UI**:

```javascript theme={null}
new BeyondWords.Player({
  projectId: YOUR_PROJECT_ID,
  contentId: 'YOUR_CONTENT_ID',
  target: '#my-player-mount',
  showUserInterface: false,
});
```

**Option 2: Omit `target`**:

If you don't pass `target`, the widget mounts at the end of `<body>` with the UI disabled automatically.

On iOS and Android, set `showUserInterface: false` in `PlayerSettings` and build native controls that call the SDK setters. See the [iOS](https://docs.beyondwords.io/docs-and-guides/widget/installation/ios-sdk.md) and [Android](https://docs.beyondwords.io/docs-and-guides/widget/installation/android-sdk.md) example apps.

## Build a custom UI

The simplest pattern is event-driven re-rendering. Listen for [widget events](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/events.md), then read state and update your UI:

```javascript theme={null}
const player = new BeyondWords.Player({
  projectId: YOUR_PROJECT_ID,
  contentId: 'YOUR_CONTENT_ID',
  showUserInterface: false,
});

player.addEventListener('<any>', rerenderUI);

function rerenderUI() {
  const item = player.content[player.contentIndex];
  const isPlaying = player.playbackState === 'playing';
  // Update your DOM from player.currentTime, item.title, etc.
}
```

Use the `<any>` event type to re-render on every state change. See [widget events](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/events.md) for specific event types and listener cleanup.

For playback control, see [programmatic control](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/programmatic-control.md).

### React example

```javascript theme={null}
import { useEffect, useState } from 'react';

function CustomPlayer({ player }) {
  const [, setTick] = useState(0);

  useEffect(() => {
    const listener = player.addEventListener('<any>', () => setTick(t => t + 1));
    return () => player.removeEventListener('<any>', listener);
  }, [player]);

  const item = player.content[player.contentIndex];
  const isPlaying = player.playbackState === 'playing';

  return (
    <div>
      <span>{item?.title ?? 'Loading...'}</span>
      <button onClick={() => { player.playbackState = isPlaying ? 'paused' : 'playing'; }}>
        {isPlaying ? 'Pause' : 'Play'}
      </button>
      <span>{Math.floor(player.currentTime / 60)}:{String(Math.floor(player.currentTime % 60)).padStart(2, '0')}</span>
    </div>
  );
}
```

### WordPress

The [WordPress plugin](https://docs.beyondwords.io/docs-and-guides/integrations/publishing-platforms/wordpress.md) injects the widget script on published posts. Use the `beyondwords_player_script_onload` filter to call your custom UI initialization after the widget loads:

```php theme={null}
function my_beyondwords_player_script_onload( $onload, $params ) {
    return $onload . 'initializeCustomUserInterface();';
}
add_filter( 'beyondwords_player_script_onload', 'my_beyondwords_player_script_onload', 10, 2 );
```

The plugin injects the widget script, so do not add it manually. Then follow the plain JavaScript pattern above, using `BeyondWords.Player.instances()[0]` to get the widget instance.

### Plain JavaScript example

```html theme={null}
<div>
  <button id="play-button">Play</button>
  <span id="content-title">Loading...</span>
  <span id="time-indicator">0:00</span>
</div>

<script>
  var player, playButton, contentTitle, timeIndicator;

  function initializeCustomUserInterface() {
    player = BeyondWords.Player.instances()[0];
    player = player || new BeyondWords.Player({
      projectId: YOUR_PROJECT_ID,
      contentId: 'YOUR_CONTENT_ID',
      showUserInterface: false,
    });

    playButton = document.getElementById('play-button');
    contentTitle = document.getElementById('content-title');
    timeIndicator = document.getElementById('time-indicator');

    player.addEventListener('<any>', rerenderCustomUserInterface);
    playButton.addEventListener('click', playOrPause);
  }

  function rerenderCustomUserInterface() {
    var contentItem = player.content[player.contentIndex];
    var isPlaying = player.playbackState === 'playing';
    var minutes = Math.floor(player.currentTime / 60);
    var seconds = Math.floor(player.currentTime % 60);

    playButton.innerText = isPlaying ? 'Pause' : 'Play';
    contentTitle.innerText = contentItem ? contentItem.title : '';
    timeIndicator.innerText = minutes + ':' + seconds.toString().padStart(2, '0');
  }

  function playOrPause() {
    player.playbackState = player.playbackState === 'playing' ? 'paused' : 'playing';
  }
</script>

<script async defer
  src="https://proxy.beyondwords.io/npm/@beyondwords/player@latest/dist/umd.js"
  onload="initializeCustomUserInterface()">
</script>
```

## Style overrides

If you only need minor tweaks to the built-in widget UI, rather than a full custom interface, you can override CSS. Widget styles are highly specific, so use the intentional override selector:

```css theme={null}
.bwp.bwp.bwp.bwp.bwp.bwp.bwp.bwp.bwp.bwp.bwp.bwp.bwp.bwp.bwp .main {
  border-radius: 0 !important;
}
```

Widget styles may change between releases. Monitor overrides after widget updates, or prefer [dashboard settings](https://docs.beyondwords.io/docs-and-guides/widget.md) instead.

### Segment highlight colors

Override [segment detection](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/segment-detection.md) highlight colors without the `.bwp` selector:

```css theme={null}
[data-beyondwords-marker]:nth-child(3n) .beyondwords-highlight {
  background: #fcc !important;
}
```

## Direct API calls

You can call the [player API](https://docs.beyondwords.io/api-reference/player/by-source-id.md) directly and build a UI from the JSON response. This works, but you lose built-in features:

* BeyondWords analytics and [analytics integrations](https://docs.beyondwords.io/docs-and-guides/audio/analytics/integrations.md)
* [Ads](https://docs.beyondwords.io/docs-and-guides/audio/ads.md) (pre/mid/post-roll)
* [Segment detection](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/segment-detection.md) and playback from paragraphs.
* Media Session API support.
* Intro/outro and playlist handling.

We recommend headless mode over direct API calls unless you have a specific reason to bypass the SDK entirely. Currently, all player data comes from the [player endpoints](https://docs.beyondwords.io/api-reference/player/by-content-id.md), which are public and cached for 5 minutes. You could call these yourself and build your own user interface on top of this data.

## FAQs

> [accordion] Can I use headless mode with native apps?
>
> Yes. Set `showUserInterface: false` in `PlayerSettings` on iOS or Android, then build native controls. The example apps in the [iOS](https://github.com/beyondwords-io/player-ios/tree/main/Example) and [Android](https://github.com/beyondwords-io/player-android/tree/main/example) repositories demonstrate this pattern.

> [accordion] Does headless mode disable analytics?
>
> No. Analytics events still fire when using the SDK in headless mode, as long as you use the widget instance rather than calling the API directly.

> [accordion] How do I show paragraph highlighting with a custom UI?
>
> Enable highlighting on the **Widget** page in your project dashboard, then use [segment detection](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/segment-detection.md) markers in your article HTML. Your custom UI can listen for segment events and apply highlight styles, or use the [segment CSS overrides](#segment-highlight-colors) with the built-in highlight classes.

> [accordion] Should I use headless mode or Magic Embed?
>
> [Magic Embed](https://docs.beyondwords.io/docs-and-guides/import-content/sources/magic-embed.md) installs the standard widget automatically. Use headless mode when you need a bespoke interface that the dashboard widget can't provide.

## Get help

If you encounter issues or have questions, [contact support](https://docs.beyondwords.io/docs-and-guides/support.md). Include your initialization code and a description of the custom UI you're building.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.