Group headings, controls, graphs, and other components into a layout section.
Page structure
Plotly · Class
html.Div is Dash's component wrapper for the HTML5 <div> element. Use it to group text or nested components in an app layout, with properties such as children, id, className, and style.
html.Div represents an HTML <div> and acts as a general-purpose container in a Dash layout. Pass displayed content or child components through children, then use component properties such as id, className, and style to identify the container and control its presentation.
html.Div(children=None, id=None, className=None, style=None, **kwargs)| Name | Type | Description |
|---|---|---|
children | Any | Content rendered inside the div; may be a component, string, number, or list of supported children. |
id | string | Optional HTML element identifier, useful for referencing the component. |
className | string | Optional CSS class name assigned to the rendered element. |
style | dict | Optional inline CSS declarations. |
A Dash HTML component representing an HTML5 <div> element.
<div> wrapper.children property supplies the content rendered inside the container.from dash import Dash, html
app = Dash(__name__)
app.layout = html.Div(
[
html.H1("Sales dashboard"),
html.P("Updated today", className="status"),
],
id="dashboard",
)
if __name__ == "__main__":
app.run(debug=True)Creates a Dash app whose layout uses a Div as the page container, with nested heading and paragraph components.
Page structure
Styling
Callbacks
html.Div, and what role does it play in a Dash layout?html.Div is Dash's Python component for the HTML5 <div> element. It is commonly used as a layout container and can hold text, other components, or lists of children.
Follow-up: How can the container be targeted by a callback? Give it an id, then reference that component ID and a property such as children in callback inputs or outputs.
html.Div?The first positional argument maps to children, so html.Div('Hello') is equivalent to html.Div(children='Hello'). Other properties should be passed by keyword, such as id, className, or style.
Follow-up: Why prefer keyword arguments for properties other than children? They make the intended property explicit and avoid confusion when a component has multiple configurable properties.
html.Div?Use style for inline CSS declarations, className to assign a CSS class, and id to reference the component. These properties are supplied as keyword arguments when constructing the component.
Follow-up: How would you apply the same styling to several Divs? Assign a shared className and define the styling in an external stylesheet rather than duplicating inline dictionaries.
htmlhtml.H1html.Pdcc.GraphDash