Trusted answers to developer questions

How to align-right in Bootstrap 4

Get the Learn to Code Starter Pack

Break into tech with the logic & computer science skills you’d learn in a bootcamp or university — at a fraction of the cost. Educative's hand-on curriculum is perfect for new learners hoping to launch a career.

Bootstrap is a CSS framework used to design and customize responsive, mobile-first sites.

In Bootstrap 4, aligning elements to the right can be achieved using any of the following classes:

Adding float-right class

The .float-right class in Bootstrap uses the CSS float property to place an element on the right. Note that the Bootstrap 4 container is a Flexbox that can prevent the float property from working.

<p class="float-right">This text is on the right</p>

Using justify-content-end class

The .justify-content-end class is used on Flexbox containers to align all items on the main axis to the right. Always remember that the container using this class must have its display property set to flex. This is the .d-flex class in Bootstrap 4.

<div class="justify-content-end">I am using justify-content-end</div>

Adding a align-items-right class

The .align-items-end class is used on Flexbox containers to align all items along its cross axis (i.e., vertically) to the right. The.d-flex class is required here, and the flex direction of the parent container should be set to column.

<div class="align-items-end">
<div>Item 1</div>
<div>Item 2</div>
</div>

See how the classes mentioned above work in the widget. Click "Run" to see the output.

Using .align-self-end class

.align-self-end is used to align a single item in a Flexbox to the right.

<div class="d-flex">
<div>Item 1</div>
<div class="align-self-end">Item 2</div>
<div>Item 3</div>
</div>

Using text-right class

text-right aligns text to the right on all viewport sizes. This is mostly used on inline elements.

<p class="text-right">This text is aligned to the right.</p>

Adding ml-auto class

The .ml-auto class is mostly used on columns, nav-bars, and a few other Flexbox children.

The result of applying all the classes above is mentioned below:

RELATED TAGS

html
css
Did you find this helpful?