Unicode character as bullet for list-item in CSS - html

I need to use, for example, the star-symbol(★) as the bullet for a list-item.
I have read the CSS3 module: Lists, that describes, how to use custom text as bullets, but it's not working for me. I think, the browsers simply don't support the ::marker pseudo element.
How can I do it, without using images?

Using Text As Bullets
Use li:before with an escaped Hex HTML Entity (or any plain text).
Example
My example will produce lists with check marks as bullets.
ul {
list-style: none;
padding: 0px;
}
ul li:before
{
content: '\2713';
margin: 0 1em; /* any design */
}
<ul>
<li>First item</li>
<li>Second item</li>
</ul>
Browser Compatibility
Haven't tested myself, but it should be supported as of IE8.
At least that's what quirksmode & css-tricks say.
You can use conditional comments to apply older/slower solutions like images, or scripts. Better yet, use both with <noscript> for the images.
HTML:
<!--[if lt IE 8]>
*SCRIPT SOLUTION*
<noscript>
*IMAGE SOLUTION*
</noscript>
<![endif]-->
About background images
Background images are indeed easy to handle, but...
Browser support for background-size is actually only as of IE9.
HTML text colors and special (crazy) fonts can do a lot, with less HTTP requests.
A script solution can just inject the HTML Entity, and let the same CSS do the work.
A good resetting CSS code might make list-style (the more logical choice) easier.
Enjoy.

EDIT
I probably wouldn't recommend using images anymore. I'd stick to the approach of using a Unicode character, like this:
li:before {
content: "\2605";
}
OLD ANSWER
I'd probably go for an image background, they're much more efficient versatile and cross-browser-friendly.
Here's an example:
<style type="text/css">
ul {list-style:none;} /* you should use a css reset too... ;) */
ul li {background:url(images/icon_star.gif) no-repeat 0 5px;}
</style>
<ul>
<li>List Item 1</li>
<li>List Item 2</li>
<li>List Item 3</li>
</ul>

This is the W3C solution. You can use it in 3012!
ul { list-style-type: "*"; }
/* Sets the marker to a "star" character */
https://drafts.csswg.org/css-lists/#text-markers
Update: according to the comments this works in all modern browsers in 2021.

You can construct it:
#modal-select-your-position li {
/* handle multiline */
overflow: visible;
padding-left: 17px;
position: relative;
}
#modal-select-your-position li:before {
/* your own marker in content */
content: "—";
left: 0;
position: absolute;
}
<ul id="modal-select-your-position">
<li>First item</li>
<li>Second item</li>
</ul>

Images are not recommended since they may appear pixelated on some devices (Apple devices with Retina display) or when zoomed in. With a character, your list looks awesome everytime.
Here is the best solution I've found so far. It works great and it's cross-browser (IE 8+).
ul {
list-style: none;
padding-left: 1.2em;
text-indent: -1.2em;
}
li:before {
content: "►";
display: block;
float: left;
width: 1.2em;
color: #ff0000;
}
<ul>
<li>First item</li>
<li>Second item</li>
</ul>
The important thing is to have the character in a floating block with a fixed width so that the text remains aligned if it's too long to fit on a single line.
1.2em is the width you want for your character, change it for your needs.
Don't forget to reset padding and margin for ul and li elements.
EDIT: Be aware that the "1.2em" size may vary if you use a different font in ul and li:before. It's safer to use pixels.

To add a star use the Unicode character 22C6.
I added a space to make a little gap between the li and the star. The code for space is A0.
li:before {
content: '\22C6\A0';
}

Today, there is a ::marker option. so,
li::marker {
content: "\2605";
}

A more complete example of 222's answer:
ul {
list-style:none;
padding: 0 0 0 2em; /* padding includes space for character and its margin */
/* IE7 and lower use default */
*list-style: disc;
*padding: 0 0 0 1em;
}
ul li:before {
content: '\25BA';
font-family: "Courier New", courier, "Lucida Sans Typewriter", "Lucida Typewriter", monospace;
margin: 0 1em 0 -1em; /* right margin defines spacing between bullet and text. negative left margin pushes back to the edge of the parent <ul> */
/* IE7 and lower use default */
*content: none;
*margin: 0;
}
ul li {
text-indent: -1em; /* negative text indent brings first line back inline with the others */
/* IE7 and lower use default */
*text-indent: 0;
}
I have included star-hack properties to restore the default list styles in older IE versions. You could pull these out and include them in a conditional include if desired, or replace with a background-image based solution. My humble opinion is that special bullet styles implemented in this manner should degrade gracefully on the few browsers that don't support pseudoselectors.
Tested in Firefox, Chrome, Safari and IE8-10 and renders correctly in all.

ul {
list-style-type: none;
}
ul li:before {
content:'*'; /* Change this to unicode as needed*/
width: 1em !important;
margin-left: -1em;
display: inline-block;
}

I've been through this whole list and there are partially correct and partially incorrect elements right through, as of 2020.
I found that the indent and offset was the biggest problem when using UTF-8, so I'm posting this as a 2020 compatible CSS solution using the "upright triangle" bullet as my example.
ul {
list-style: none;
text-indent: -2em; // needs to be 1 + ( 2 x margin), and the result 'negative'
}
ul li:before {
content: "\25B2";
margin: 0 0.5em; // 0.5 x 2 = 1, + 1 offset to get the bullet back in the right spot
}
use em as the unit to avoid conflict with font sizing

As mentioned in these two comments, the modern approach is to use list-style-type or ::marker. You can also combine them depending on your use case.
One of the more notable setbacks with these methods is that you can't yet apply margin or padding to ::marker, and instead must rely on whitespace (as illustrated in the examples here) or use an offset method as outlined in the demo provided in 2.1 below.
1. Using list-style-type to set a custom marker
li { list-style-type: "🔧 "; }
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
2. Using ::marker to style list-style-type
/* intentional whitespace, may vary cross-browser */
li { list-style-type: "★ "; }
li::marker { color: red; }
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
2.1 Spacing
While it's not immediately apparent in the demo above, the marker is moving away from the list as opposed to pushing itself into it. This means that it may fall outside of your grid and/or may become obscured by another element.
I've created a demo on Codepen that highlights the whitespace issue alongside two potential solutions depending on if you need to match the default ul styling or create something that's inside the parent container.
3. Using ::marker exclusively for variants:
li.one::marker { content: "🥇 "; }
li.two::marker { content: "🥈 "; }
li.three::marker { content: "🥉 "; }
<ul>
<li class="one">1</li>
<li class="two">2</li>
<li class="three">3</li>
</ul>
Additional Resources:
"List Markers and String Styles" by Eric Meyer on CSS Tricks [2021]
Can I Use list-style-type <string> (vs. list-style-type)
Can I Use ::marker

Try this code...
li:before {
content: "→ "; /* caractère UTF-8 */
}

To expand on the top answer, and address the issues brought up regarding the overflowing lines not indenting properly, you could make the list items padding-left 20px (for example) and the position relative. Then in the li:before, set the position to absolute and left -20px;
Example:
ul {
list-style: none;
padding: 0 0 0 20px;
}
ul li {
position: relative;
}
ul li:before {
content: '\2713';
position: absolute;
top: 0;
left: -20px; // or whatever your padding-left is on the ul
font-size: inherit;
line-height: inherit;
}
I would have written this as a comment on the answer, but don't have enough points to post a comment, but hopefully this can help someone having this issue.

This topic may be old, but here's a quick fix
ul {list-style:outside none square;} or
ul {list-style:outside none disc;} , etc...
then add left padding to list element
ul li{line-height: 1.4;padding-bottom: 6px;}

Related

Removing <li> indent [duplicate]

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?
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:
It nicely left-aligns <ul>'s bullet points to surrounding normal paragraph text (= indenting of <ul> removed).
The text blocks within the <li> elements remain correctly indented if they wrap around into multiple lines.
Legacy info:
For IE versions 8 and below you must use margin-left instead:
ul { margin-left: 1.2em; }
Add this to your CSS:
ul { list-style-position: inside; }
This will place the li elements in the same indent as other paragraphs and text.
Ref: http://www.w3schools.com/cssref/pr_list-style-position.asp
display:table-row; will also get rid of the indentation but will remove the bullets.
Remove the padding:
padding-left: 0;
Can you provide a link ?
thanks
I can take a look
Most likely your css selector isnt strong enough or can you try
padding:0!important;
Live demo: https://jsfiddle.net/h8uxmoj4/
ol, ul {
padding-left: 0;
}
li {
list-style: none;
padding-left: 1.25rem;
position: relative;
}
li::before {
left: 0;
position: absolute;
}
ol {
counter-reset: counter;
}
ol li::before {
content: counter(counter) ".";
counter-increment: counter;
}
ul li::before {
content: "●";
}
Since the original question is unclear about its requirements, I attempted to solve this problem within the guidelines set by other answers. In particular:
Align list bullets with outside paragraph text
Align multiple lines within the same list item
I also wanted a solution that didn't rely on browsers agreeing on how much padding to use. I've added an ordered list for completeness.
I have the same problem with a footer I'm trying to divide up. I found that this worked for me by trying few of above suggestions combined:
footer div ul {
list-style-position: inside;
padding-left: 0;
}
This seems to keep it to the left under my h1 and the bullet points inside the div rather than outside to the left.
Doing this inline, I set the margin to 0 (ul style="margin:0px"). The bullets align with paragraph with no overhang.
The following worked for me.
In Chrome, Edge and Firefox (which needs special treatment).
Bullets are kept and are on the same line with surrounding paragraphs.
ul {
padding-left: 0;
margin-left: 17px;
}
/* Different value for Firefox */
#-moz-document url-prefix() {
ul {
margin-left: 14px;
}
}

I am really new to HTML and was wondering how you center multiple links with html and add color the link at the same time?

Fallout
Yes; you should go to the links Howzieky provided. When in doubt, w3schools is right. Codeacademy is great, but teaches some bad practices.
However, that doesn't help you right now. So, I'll try to nudge you along.
First: look up how to link an external style sheet. Keeping your code clean is good when you're just learning.
Now, assuming you have a list of links that will be displayed as a list, you need to remember that code semantics is important for accessibility and seo. So, if it's a list of any kind, it goes inside a list element.
So, start with:
<ol>
<li>link text</li>
<li>link text</li>
</ol>
ol is better accessibility than ul, but both work.
Now, first style your list so you get rid (visually) of the bullits/numbers, and have a block that will play nice:
ol {
display: block;
width: 100%;
height: auto;
overflow: hidden;
/* This sets you up with a block that will scale down nicely if your text is too long. */
margin: 0;
padding: 0;
/* Because it's a headache to find where whitespace is coming from later, I always advise to null the padding and margin and use a container if you need gutters later. This also nixes the space reserved for the bullits/numbers. */
list-style-type: none;
/* Get rid of the bullits/numbers for realsies */
}
Now, to style the list items:
ol li {
display: block;
width: 100%;
height: auto;
padding: 0;
margin: 0;
list-style-type: none; /* For IE 9 and lower. */
text-align: center; /* Here's your centered links */
}
Just one more step:
ol li a,
ol li a:link {
color: red;
}
ol li a:hover,
ol li a:focus,
ol li a:active {
/* do something here to change the links visually when hovered/clicked/tabbed to, be nice to your users. */
}
HTH. Have fun & good luck.

How to remove indentation from an unordered list item?

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?
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:
It nicely left-aligns <ul>'s bullet points to surrounding normal paragraph text (= indenting of <ul> removed).
The text blocks within the <li> elements remain correctly indented if they wrap around into multiple lines.
Legacy info:
For IE versions 8 and below you must use margin-left instead:
ul { margin-left: 1.2em; }
Add this to your CSS:
ul { list-style-position: inside; }
This will place the li elements in the same indent as other paragraphs and text.
Ref: http://www.w3schools.com/cssref/pr_list-style-position.asp
display:table-row; will also get rid of the indentation but will remove the bullets.
Remove the padding:
padding-left: 0;
Can you provide a link ?
thanks
I can take a look
Most likely your css selector isnt strong enough or can you try
padding:0!important;
Live demo: https://jsfiddle.net/h8uxmoj4/
ol, ul {
padding-left: 0;
}
li {
list-style: none;
padding-left: 1.25rem;
position: relative;
}
li::before {
left: 0;
position: absolute;
}
ol {
counter-reset: counter;
}
ol li::before {
content: counter(counter) ".";
counter-increment: counter;
}
ul li::before {
content: "●";
}
Since the original question is unclear about its requirements, I attempted to solve this problem within the guidelines set by other answers. In particular:
Align list bullets with outside paragraph text
Align multiple lines within the same list item
I also wanted a solution that didn't rely on browsers agreeing on how much padding to use. I've added an ordered list for completeness.
I have the same problem with a footer I'm trying to divide up. I found that this worked for me by trying few of above suggestions combined:
footer div ul {
list-style-position: inside;
padding-left: 0;
}
This seems to keep it to the left under my h1 and the bullet points inside the div rather than outside to the left.
Doing this inline, I set the margin to 0 (ul style="margin:0px"). The bullets align with paragraph with no overhang.
The following worked for me.
In Chrome, Edge and Firefox (which needs special treatment).
Bullets are kept and are on the same line with surrounding paragraphs.
ul {
padding-left: 0;
margin-left: 17px;
}
/* Different value for Firefox */
#-moz-document url-prefix() {
ul {
margin-left: 14px;
}
}

A space between inline-block list items [duplicate]

This question already has answers here:
How to remove the space between inline/inline-block elements?
(41 answers)
Closed 8 years ago.
Possible Duplicate:
Unwanted margin in inline-block list items
How to remove “Invisible space” from HTML
Why do the inline-block list items have a space in them? No matter how I make my list items into a menu, I always get spaces.
li {
border: 1px solid black;
display: inline-block;
height: 25px;
list-style-type: none;
text-align: center;
width: 50px;
}
ul {
padding: 0;
}
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
I have seen this and answered on it before:
After further research I have
discovered that inline-block is a
whitespace dependent method and
is dependent on the font setting. In this case 4px is rendered.
To avoid this you could run all your
lis together in one line, or block
the end tags and begin tags together
like this:
<ul>
<li>
<div>first</div>
</li><li>
<div>first</div>
</li><li>
<div>first</div>
</li><li>
<div>first</div>
</li>
</ul>
Example here.
As mentioned by other answers and comments, the best practice for solving this is to add font-size: 0; to the parent element:
ul {
font-size: 0;
}
ul li {
font-size: 14px;
display: inline-block;
}
This is better for HTML readability (avoiding running the tags together etc). The spacing effect is because of the font's spacing setting, so you must reset it for the inlined elements and set it again for the content within.
Solution:
ul {
font-size: 0;
}
ul li {
font-size: 14px;
display: inline-block;
}
You must set parent font size to 0
I would add the CSS property of float left as seen below. That gets rid of the extra space.
ul li {
float:left;
}
Actually, this is not specific to display:inline-block, but also applies to display:inline. Thus, in addition to David Horák's solution, this also works:
ul {
font-size: 0;
}
ul li {
font-size: 14px;
display: inline;
}
Another solution, similar to Gerbus' solution, but this also works with relative font sizing.
ul {
letter-spacing: -1em; /* Effectively collapses white-space */
}
ul li {
display: inline;
letter-spacing: normal; /* Reset letter-spacing to normal value */
}
I had the same problem, when I used a inline-block on my menu I had the space between each "li" I found a simple solution, I don't remember where I found it, anyway here is what I did.
<li>Home</li><!---->
<li>News</li><!---->
<li>About Us</li><!---->
<li>Contact Us</li>
You add a comment sign between each end of, and start of : "li"
Then the horizontal space disappear.
Hope that answer to the question
Thanks
Even if its not inline-block based, this solution might worth consideration (allows nearly same formatting control from upper levels).
ul {
display: table;
}
ul li {
display: table-cell;
}
IE8+ & major browsers compatible
Relative/fixed font-size independent
HTML code formatting independent (no need to glue </li><li>)
just remove the breaks between li's in your html code...
make the li's in one line only..

How can you customize the numbers in an ordered list?

How can I left-align the numbers in an ordered list?
1. an item
// skip some items for brevity
9. another item
10. notice the 1 is under the 9, and the item contents also line up
Change the character after the number in an ordered list?
1) an item
Also is there a CSS solution to change from numbers to alphabetic/roman lists instead of using the type attribute on the ol element.
I am mostly interested in answers that work on Firefox 3.
This is the solution I have working in Firefox 3, Opera and Google Chrome. The list still displays in IE7 (but without the close bracket and left align numbers):
ol {
counter-reset: item;
margin-left: 0;
padding-left: 0;
}
li {
display: block;
margin-bottom: .5em;
margin-left: 2em;
}
li::before {
display: inline-block;
content: counter(item) ") ";
counter-increment: item;
width: 2em;
margin-left: -2em;
}
<ol>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
<li>Six</li>
<li>Seven</li>
<li>Eight</li>
<li>Nine<br>Items</li>
<li>Ten<br>Items</li>
</ol>
EDIT: Included multiple line fix by strager
Also is there a CSS solution to change from numbers to alphabetic/roman lists instead of using the type attribute on the ol element.
Refer to list-style-type CSS property. Or when using counters the second argument accepts a list-style-type value. For example the following will use upper roman:
li::before {
content: counter(item, upper-roman) ") ";
counter-increment: item;
/* ... */
The CSS for styling lists is here, but is basically:
li {
list-style-type: decimal;
list-style-position: inside;
}
However, the specific layout you're after can probably only be achieved by delving into the innards of the layout with something like this (note that I haven't actually tried it):
ol { counter-reset: item }
li { display: block }
li:before { content: counter(item) ") "; counter-increment: item }
HTML5: Use the value attribute (no CSS needed)
Modern browsers will interpret the value attribute and will display it as you expect. See MDN documentation.
<ol>
<li value="3">This is item three.</li>
<li value="50">This is item fifty.</li>
<li value="100">This is item one hundred.</li>
</ol>
Also have a look at the <ol> article on MDN, especially the documentation for the start and attribute.
You can also specify your own numbers in the HTML - e.g. if the numbers are being provided by a database:
ol {
list-style: none;
}
ol>li:before {
content: attr(seq) ". ";
}
<ol>
<li seq="1">Item one</li>
<li seq="20">Item twenty</li>
<li seq="300">Item three hundred</li>
</ol>
The seq attribute is made visible using a method similar to that given in other answers. But instead of using content: counter(foo), we use content: attr(seq).
Demo in CodePen with more styling
Stole a lot of this from other answers, but this is working in FF3 for me. It has upper-roman, uniform indenting, a close bracket.
ol {
counter-reset: item;
margin-left: 0;
padding-left: 0;
}
li {
margin-bottom: .5em;
}
li:before {
display: inline-block;
content: counter(item, upper-roman) ")";
counter-increment: item;
width: 3em;
}
<ol>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
<li>Six</li>
<li>Seven</li>
<li>Eight</li>
<li>Nine</li>
<li>Ten</li>
</ol>
I suggest playing with the :before attribute and seeing what you can achieve with it. It will mean your code really is limited to nice new browsers, and excludes the (annoyingly large) section of the market still using rubbish old browsers,
Something like the following, which forces a fixed with on the items. Yes, I know it's less elegant to have to choose the width yourself, but using CSS for your layout is like undercover police work: however good your motives, it always gets messy.
li:before {
content: counter(item) ") ";
counter-increment: item;
display: marker;
width: 2em;
}
But you're going to have to experiment to find the exact solution.
The numbers line up better if you add leading-zeroes to the numbers, by setting list-style-type to:
ol { list-style-type: decimal-leading-zero; }
Borrowed and improved Marcus Downing's answer. Tested and works in Firefox 3 and Opera 9. Supports multiple lines, too.
ol {
counter-reset: item;
margin-left: 0;
padding-left: 0;
}
li {
display: block;
margin-left: 3.5em; /* Change with margin-left on li:before. Must be -li:before::margin-left + li:before::padding-right. (Causes indention for other lines.) */
}
li:before {
content: counter(item) ")"; /* Change 'item' to 'item, upper-roman' or 'item, lower-roman' for upper- and lower-case roman, respectively. */
counter-increment: item;
display: inline-block;
text-align: right;
width: 3em; /* Must be the maximum width of your list's numbers, including the ')', for compatability (in case you use a fixed-width font, for example). Will have to beef up if using roman. */
padding-right: 0.5em;
margin-left: -3.5em; /* See li comments. */
}
The docs say regarding list-style-position: outside
CSS1 did not specify the precise location of the marker box and for reasons of compatibility, CSS2 remains equally ambiguous. For more precise control of marker boxes, please use markers.
Further up that page is the stuff about markers.
One example is:
LI:before {
display: marker;
content: "(" counter(counter) ")";
counter-increment: counter;
width: 6em;
text-align: center;
}
There is the Type attribute which allows you to change the numbering style, however, you cannot change the full stop after the number/letter.
<ol type="a">
<li>Turn left on Maple Street</li>
<li>Turn right on Clover Court</li>
</ol>
Nope... just use a DL:
dl { overflow:hidden; }
dt {
float:left;
clear: left;
width:4em; /* adjust the width; make sure the total of both is 100% */
text-align: right
}
dd {
float:left;
width:50%; /* adjust the width; make sure the total of both is 100% */
margin: 0 0.5em;
}
Quick and dirt alternative solution. You can use a tabulation character along with preformatted text. Here's a possibility:
<style type="text/css">
ol {
list-style-position: inside;
}
li:first-letter {
white-space: pre;
}
</style>
and your html:
<ol>
<li> an item</li>
<li> another item</li>
...
</ol>
Note that the space between the li tag and the beggining of the text is a tabulation character (what you get when you press the tab key inside notepad).
If you need to support older browsers, you can do this instead:
<style type="text/css">
ol {
list-style-position: inside;
}
</style>
<ol>
<li><pre> </pre>an item</li>
<li><pre> </pre>another item</li>
...
</ol>
I will give here the kind of answer i usually don't like to read, but i think that as there are other answers telling you how to achive what you want, it could be nice to rethink if what you are trying to achive is really a good idea.
First, you should think if it is a good idea to show the items in a non-standard way, with a separator charater diferent than the provided.
I don't know the reasons for that, but let's suppose you have good reasons.
The ways propossed here to achive that consist in add content to your markup, mainly trough the CSS :before pseudoclass. This content is really modifing your DOM structure, adding those items to it.
When you use standard "ol" numeration, you will have a rendered content in which the "li" text is selectable, but the number preceding it is not selectable. That is, the standard numbering system seems to be more "decoration" than real content. If you add content for numbers using for example those ":before" methods, this content will be selectable, and dued to this, performing undesired vopy/paste issues, or accesibility issues with screen readers that will read this "new" content in addition to the standard numeration system.
Perhaps another approach could be to style the numbers using images, although this alternative will bring its own problems (numbers not shown when images are disabled, text size for number not changing, ...).
Anyway, the reason for this answer is not just to propose this "images" alternative, but to make people think in the consequences of trying to change the standard numeration system for ordered lists.
This code makes numbering style same as headers of li content.
<style>
h4 {font-size: 18px}
ol.list-h4 {counter-reset: item; padding-left:27px}
ol.list-h4 > li {display: block}
ol.list-h4 > li::before {display: block; position:absolute; left:16px; top:auto; content: counter(item)"."; counter-increment: item; font-size: 18px}
ol.list-h4 > li > h4 {padding-top:3px}
</style>
<ol class="list-h4">
<li>
<h4>...</h4>
<p>...</p>
</li>
<li>...</li>
</ol>
Vhndaree posted an interesting implementation of this problem on a duplicate question, which goes a step further than any of the existing answers in that it implements a custom character before the incrementing numbers:
.custom {
list-style-type: none;
}
.custom li {
counter-increment: step-counter;
}
.custom li::before {
content: '(' counter(step-counter) ')';
margin-right: 5px;
}
<ol class="custom">
<li>First</li>
<li>Second</li>
<li>Third</li>
<li>Fourth</li>
<li>Fifth</li>
<li>Sixth</li>
<li>Seventh</li>
<li>Eighth</li>
<li>Ninth</li>
<li>Tenth</li>
</ol>
I have it. Try the following:
<html>
<head>
<style type='text/css'>
ol { counter-reset: item; }
li { display: block; }
li:before { content: counter(item) ")"; counter-increment: item;
display: inline-block; width: 50px; }
</style>
</head>
<body>
<ol>
<li>Something</li>
<li>Something</li>
<li>Something</li>
<li>Something</li>
<li>Something</li>
<li>Something</li>
<li>Something</li>
<li>Something</li>
<li>Something</li>
<li>Something</li>
<li>Something</li>
<li>Something</li>
</ol>
</body>
The catch is that this definitely won't work on older or less compliant browsers: display: inline-block is a very new property.
The other answers are better from a conceptual point of view. However, you can just left-pad the numbers with the appropriate number of ' ' to make them line up.
* Note: I did not at first recognize that a numbered list was being used. I thought the list was being explicitly generated.