How to set alignment of each dropdown widget in Jupyter?

Dropdown widgets in Jupyter notebooks can be aligned using CSS layout properties and the ipywidgets package. We can control alignment using the Layout() class to position dropdowns side by side, center them, or arrange them vertically for better visual presentation.

Installation Requirements

Install the required packages ?

pip install ipywidgets ipyvuetify

Basic Syntax

The main components for creating aligned dropdown widgets ?

# Create dropdown widget
widgets.Dropdown(options=[], description='', layout=widgets.Layout())

# Define layout alignment
widgets.Layout(width='70%', align_self='center')

# Alternative using ipyvuetify
v.Select(multiple=True, items=[], label='', style_='width:300px')

Key Parameters

  • align_self ? Controls alignment: 'center', 'flex-start', 'flex-end'

  • width ? Sets dropdown width as percentage or pixels

  • multiple ? True allows multiple selections, False for single selection

  • layout ? Defines positioning and styling properties

Example 1: Center and Right Alignment

Creating two dropdowns with different alignments ?

import ipywidgets as widgets
from IPython.display import display

# Center-aligned dropdown
dropdown1 = widgets.Dropdown(
    options=['Apple', 'Xiaomi', 'Samsung'],
    description='BRAND:',
    layout=widgets.Layout(width='70%', align_self='center')
)

# Right-aligned dropdown  
dropdown2 = widgets.Dropdown(
    options=['PhonePe', 'Google Pay', 'Paytm'],
    description='PAYMENT:',
    layout=widgets.Layout(width='70%', align_self='flex-end')
)

display(dropdown1, dropdown2)

Dropdown alignment example

Example 2: Multiple Selection with ipyvuetify

Using ipyvuetify for advanced styling and multiple selections ?

import ipyvuetify as v

# Create styled button
button = v.Btn(
    color='green',
    children=['Submit'],
    style_='width:300px'
)

# Create multi-select dropdown
dropdown = v.Select(
    multiple=True, 
    items=['A', 'B', 'M', 'T', 'H', 'K'], 
    label='Select Letters',
    style_='width:300px'
)

# Arrange horizontally using flexbox
v.Html(
    tag='div',
    class_='d-flex flex-row',
    children=[dropdown, button]
)

Multiple selection dropdown

Example 3: Single Selection Dropdown

Creating a single-selection dropdown with custom styling ?

import ipyvuetify as v

# Single selection dropdown
dropdown = v.Select(
    multiple=False, 
    items=['Maharashtra', 'Telangana', 'Uttar Pradesh', 'Himachal Pradesh', 'Assam'], 
    label='Select State'
)

# Submit button
button = v.Btn(
    color='blue',
    children=['Submit'],
    style_='width:100px'
)

display(dropdown, button)

Single selection dropdown

Alignment Options

align_self Value Position Use Case
center Center aligned Main form elements
flex-start Left aligned Default alignment
flex-end Right aligned Secondary elements

Conclusion

Use widgets.Layout() with align_self property to control dropdown alignment in Jupyter notebooks. The ipyvuetify package provides additional styling options and flexbox classes for advanced layout control.

Updated on: 2026-03-27T08:06:48+05:30

660 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements