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:
float-right
classThe .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>
justify-content-end
classThe .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>
align-items-right
classThe .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.
.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>
text-right
classtext-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>
ml-auto
classThe .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: