# MozWidget `moz-widget` is a card that embeds a self-contained, interactive widget in a host surface. Widgets are used for presenting brief updates or completing a quick task. It clips content to its bounds and uses the dimensions set by the `size` attribute. Content comes from a browser or iframe when `src` is set and otherwise from the default slot. ```html story

Los Angeles

72°F and sunny

``` ## Code The source for `moz-widget` can be found under [browser/components/widgets/content/](https://searchfox.org/firefox-main/source/browser/components/widgets/content). ## How to use `moz-widget` ### Importing the element `moz-widget` is not registered by `customElements.js` and needs to be imported to use: ```html ``` ### Setting the `size` `size` selects fixed dimensions based on the IAB Medium Rectangle (300x250) but the host surface can override them. A missing or unrecognized `size` uses the `large` dimensions. The widget sets `--widget-size` to `small`, `medium`, or `large` for its header and content to query with `@container style()`.
size Width Height Ratio
large 300px 250px 6:5
medium 300px 125px 12:5
small 150px 125px 6:5
If a surface overrides the sizing, it should keep the dimensions close to the IAB rectangle as New Tab does. ### Setting the `widget-id` `widget-id` is the registered ID of the hosted widget. ### Setting the `title` `title` provides the accessible name of the widget. Set `data-l10n-id` to a Fluent message with a `.title` attribute: ``` widget-weather = .title = Weather ``` ```html ``` Or set the attribute directly: ```html ``` ### Adding a header A `moz-widget-header` in the `header` slot appears above the widget content. `moz-widget` imports `moz-widget-header`. `title` sets the header text: ```html ``` The `leading` slot holds content before the heading, such as a back button or a badge. The `trailing` slot holds content at the end of the header. In a `small` widget, the header hides a `moz-badge` in the `leading` slot, and hides the `trailing` slot when the header shows a menu button. ```html ``` When `moz-widget`'s `menu` slot holds a `panel-list`, the header shows a menu button that opens it. A `panel-list` without an `id` gets a generated one. An `id` set by the surface has to be unique to its document or shadow root. `menu-label` sets the button's accessible name, which defaults to "More options": ```html
``` ```ftl weather-header = .title = Weather .menu-label = Weather options ``` ### Setting `padded` `padded` insets the card and rounds the corners of the content. ```html ``` ### Without a header Without a header, the content extends to the card's edges. `moz-widget` draws the menu button over the top-end corner of the content, shown while the widget is hovered or focused, or while its menu is open. `menu-label` on `moz-widget` sets the button's accessible name. ```html ``` ### Remote content with `src` `src` uses a remote frame for the widget content instead of the slotted content. ```html ``` The frame is a `browser` element in chrome or an `iframe` element in content. In a browser element, `remote-type="extension"` loads a `moz-extension:` document in the extension process, and `group-id` joins the extension's browsing context group, taken from `WebExtensionPolicy.browsingContextGroupId`.