Rajanikant Hawaldar
How to horizontally center a <div>
By Rajanikant Hawaldar in HTML 5 on Oct 10 2020
  • Deepak Rawat
    Apr, 2023 20

    Use margins: auto we can position a
    element horizontally by automatically adjusting the left and right margins.

    1. .deepak {
    2. width: 50%;
    3. margin: 0 auto;
    4. }

    Using flexbox
    You can use flexbox to center a horizontally within its containing element.

    1. .deepak {
    2. display: flex;
    3. justify-content: center;
    4. }
    5. .deepak div {
    6. width: 50%;
    7. }

    • 0
  • Dulanjali Senarathna
    Mar, 2023 15

    Use margin:auto

    • 0
  • Ravindra Bhati
    Dec, 2020 16

    Use below css for div.
    margin:0px auto;

    • 0
  • Kokul Jose
    Oct, 2020 15

    Adding the below CSS will help you attain the same:
    display: flex;justify-content: center;

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS