# Custom components

Source: https://docs.streamlit.io/develop/api-reference/custom-components

Streamlit custom components extend your app beyond built-in widgets with custom UI elements. V2 components offer better performance and multiple callbacks without iframes, while V1 components run in iframes with single callbacks.

## V2 custom components

### Backend (Python)

**[Register](https://docs.streamlit.io/develop/api-reference/custom-components/st.components.v2.component)**: Register a custom component.

```python
my_component = st.components.v2.component(
    "my_component",
    html=HTML,
    js=JS
)
my_component()
```

**[Mount](https://docs.streamlit.io/develop/api-reference/custom-components/st.components.v2.types.componentrenderer)**: Mount a custom component.

```python
my_component = st.components.v2.component(
    "my_component",
    html=HTML,
    js=JS
)
my_component()
```

### Frontend (TypeScript)

**[npm support code](https://docs.streamlit.io/develop/api-reference/custom-components/component-v2-lib)**: Support code published through npm.

```bash
npm i @streamlit/component-v2-lib
```

**[FrontendRenderer](https://docs.streamlit.io/develop/api-reference/custom-components/component-v2-lib-frontendrenderer)**: Type alias for the component function.

```typescript
import { FrontendRenderer } from "@streamlit/component-v2-lib";
```

**[FrontendRendererArgs](https://docs.streamlit.io/develop/api-reference/custom-components/component-v2-lib-frontendrendererargs)**: Type alias for the component arguments.

```typescript
import { FrontendRendererArgs } from "@streamlit/component-v2-lib";
```

**[FrontendState](https://docs.streamlit.io/develop/api-reference/custom-components/component-v2-lib-frontendstate)**: Type alias for the component state.

```typescript
import { FrontendState } from "@streamlit/component-v2-lib";
```

**[CleanupFunction](https://docs.streamlit.io/develop/api-reference/custom-components/component-v2-lib-cleanupfunction)**: Type alias for the component cleanup function.

```typescript
import { CleanupFunction } from "@streamlit/component-v2-lib";
```

## V1 custom components

**[Declare a component](https://docs.streamlit.io/develop/api-reference/custom-components/st.components.v1.declare_component)**: Create and register a custom component.

```python
from streamlit.components.v1 import declare_component
declare_component(
    "custom_slider",
    "/frontend",
)
```

**[HTML](https://docs.streamlit.io/develop/api-reference/custom-components/st.components.v1.html)**

> This command was deprecated in version 1.56.0. Use `st.iframe` instead, or `st.html` to insert HTML without an iframe.

Display an HTML string in an iframe.

```python
from streamlit.components.v1 import html
html(
    "<p>Foo bar.</p>"
)
```

**[iframe](https://docs.streamlit.io/develop/api-reference/custom-components/st.components.v1.iframe)**

> This command was deprecated in version 1.56.0. Use `st.iframe` instead.

Load a remote URL in an iframe.

```python
from streamlit.components.v1 import iframe
iframe(
    "https://docs.streamlit.io"
)
```
