I want to remove all indentation from ul
. I tried setting margin
, padding
, text-indent
to 0
, but no avail. Seems that setting text-indent
to a negative number does the trick - but is that really the only way to remove the indentation?
To remove this left-indentation consistently across all browsers, set both padding and margins to "0" for the "UL".
You can use the CSS text-indent property to indent text in any block container, including divs, headings, asides, articles, blockquotes, and list elements. Say you want to indent all div elements containing text on a page to the right by 50px. Then, using the CSS type selector div, set the text-indent property to 50px.
Set the list style and left padding to nothing.
ul { list-style: none; padding-left: 0; }
ul { list-style: none; padding-left: 0; }
<ul> <li>a</li> <li>b</li> <li>c</li> </ul>
To maintain the bullets you can replace the list-style: none
with list-style-position: inside
or the shorthand list-style: inside
:
ul { list-style-position: inside; padding-left: 0; }
ul { list-style-position: inside; padding-left: 0; }
<ul> <li>a</li> <li>b</li> <li>c</li> </ul>
My preferred solution to remove <ul> indentation is a simple CSS one-liner:
ul { padding-left: 1.2em; }
<p>A leading line of paragraph text</p> <ul> <li>Bullet points align with paragraph text above.</li> <li>Long list items wrap around correctly. Long list items wrap around correctly. Long list items wrap around correctly. Long list items wrap around correctly. Long list items wrap around correctly. </li> <li>List item 3</li> </ul> <p>A trailing line of paragraph text</p>
This solution is not only lightweight, but has multiple advantages:
Legacy info:
For IE versions 8 and below you must use margin-left instead:
ul { margin-left: 1.2em; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With