# Manage layout and size

When you embed TradingView widgets into your website, it's important to
understand how their sizing works to ensure they display correctly.

The widget always tries to fill the space allowed by CSS. The recommended
approach is [automatic sizing](#automatic-sizing-recommended), where you style
the container element with flexible CSS and the widget adapts to it. If needed,
you can use [fixed sizing](#fixed-sizing) by assigning a specific, unchanging
width and height to the container.

## Automatic sizing (recommended)

This is the default and most flexible approach. Letting the widget automatically
adapt to its container makes your layout naturally responsive. It also keeps
your code clean by separating styling logic into your CSS, not in widget
attributes. You manage the container's size, and the widget follows.

1. Place the widget's script inside a container element (e.g., `<div>`).
2. Use CSS to define the container's size. You can use responsive units, flexbox
   properties, or grid properties.

**Learn more about CSS layouts**

- [CSS flexible box layout](https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Flexible_box_layout)
- [CSS grid layout](https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Grid_layout)

The example below shows the Mini Chart widget in a responsive container.

```html
<div class="widget-wrap">
	<tv-mini-chart symbol="NASDAQ:AAPL"></tv-mini-chart>
</div>

<style>
	.widget-wrap {
		width: 100%;
		height: 100%;
	}
</style>
```

## Fixed sizing

In this approach, you apply the fixed dimensions to the widget's container. Use
this approach when you need a widget to occupy a precise, unchanging area on
your page.

1. Place the widget inside a container element.
2. Use CSS to set an explicit width and height on the container.

:::info

Some widgets, like the Horizontal Ticker Tape, define their own height based on
their content and settings. Give them adequate vertical space, but note that
they will not stretch to fill an arbitrary height.

:::

The example below shows the Mini Chart widget with explicit dimensions.

```html
<div class="widget-fixed">
	<tv-mini-chart symbol="NASDAQ:AAPL"></tv-mini-chart>
</div>

<style>
	.widget-fixed {
		display: block;
		width: 250px;
		height: 200px;
		overflow: hidden;
		/* Optional: make it responsive within a cap */
		max-width: 100%;
	}
</style>
```

## Layout tips and warnings

- If the container scrolls, ensure it has enough height. Otherwise, it may
  collapse and hide the widget.
- Be aware that `overflow: hidden` will clip pop-ups. If a widget uses
  interactive elements like menus or dialogs, applying this style to its
  container can make those features unusable.

## Multiple widgets examples

### Using flexbox

```html
<div class="flex-row">
	<tv-mini-chart symbol="NASDAQ:AAPL"></tv-mini-chart>
	<tv-mini-chart symbol="NASDAQ:NVDA"></tv-mini-chart>
</div>

<style>
	.flex-row {
		display: flex;
		flex-direction: row;
		gap: 16px;
		block-size: 100%; /* Make the flex row stretch to full height */
	}
</style>
```

### Using CSS grid

```html
<div class="grid">
	<tv-mini-chart symbol="NASDAQ:AAPL"></tv-mini-chart>
	<tv-mini-chart symbol="NASDAQ:TSLA"></tv-mini-chart>
	<tv-mini-chart class="wide" symbol="NASDAQ:NVDA"></tv-mini-chart>
</div>

<style>
	.grid {
		display: grid;
		grid-template-columns: repeat(2, 1fr);
		grid-auto-rows: 1fr;
		gap: 16px;
		block-size: 100%; /* Make the grid stretch to full height */
	}
	.wide {
		grid-column: span 2;
	}
</style>
```

---

## Sitemap

- [All documentation pages](https://www.tradingview.com/widget-docs/llms.txt)
- [Full page map with headings](https://www.tradingview.com/widget-docs/docs_map.md)
