Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

html
css
community creator

How to align-right in Bootstrap 4

Daphnie Ozioma

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>

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.

Implementation

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

Code Output

RELATED TAGS

html
css
community creator
RELATED COURSES

View all Courses

Keep Exploring