Ordered and unordered lists
The list feature lets you create ordered (numbered) and unordered (bulleted) lists. The unique thing about them is that you can put any content inside each list item (including block elements like paragraphs and tables), retaining the continuity of numbering and indentation.
Since version 41.0.0, the list support plugin has changed for CKEditor 5. You can read more about this change in the Update to CKEditor 41.0.0 guide.
Use the editor below to see the list feature in action. You can use toolbar buttons to insert both ordered
and unordered lists .You can also use Markdown code recognized by the autoformatting feature:
- Start a line with
*
or-
followed by a space for a bulleted list. - Start a line with
1.
or1)
followed by a space for a numbered list.
Top five places to visit this summer
...and stay on the budget.
-
Gran Canaria, Spain
Gran Canaria is a popular tourist destination. The island is often called “a miniature continent”. This is because it offers a great variety of climates and landscapes, from golden sandy beaches through rocky ravines and white dunes to charming villages. In the mid-2010s, over 3.5 million tourists visited Gran Canaria each year.
-
Florence, Italy
Florence, established in 59 BC by Julius Caesar himself got its name from two rivers that surrounded the settlement. Thanks to centuries of history, the capital of Tuscany has plenty to offer to tourists hungry for sightseeing. Some of the most interesting places to visit include:
- Piazza della Signoria
- Mercato Centrale and the San Lorenzo Market
- Museum of Zoology and Natural History “La Specola”
Florence is also regarded as one of the top 15 fashion capitals of the world.
-
Porto, Portugal
Porto, located at the Duero river estuary in northern Portugal, is the country’s second-largest city. It is regarded as one of the oldest European centers, which was recognized in 1996 when deemed the city’s historic center a World Heritage Site.
The old town of Porto is a UNESCO World Heritage site. In 2014 and 2017, Porto was elected The Best European Destination by the Best European Destinations Agency. The city is also home to the Porto School of Architecture, one of the most prestigious architecture schools in the world.
-
Budapest, Hungary
The capital of Hungary, a spa city sitting across the Danube river, is alive with Roman, Turkish, and European history and cultural heritage. Thermal baths, the picturesque river, and the Gellért Hill citadel are only a few things worth considering while planning your trip to Hungary.
They said that, of course, Budapest is beautiful. But it is in fact almost ludicrously beautiful. – Anthony Bourdain
-
The Peloponnese, Greece
The Peloponnese peninsula was already inhabited in prehistoric times. During the bronze age, the first European highly developed culture – the Mycenaean civilization – started there. Roman, Byzantine, Slavic, and Ottoman rules left a significant mark on the place with numerous architectural and cultural relics worth visiting to this day.
The List
plugin provides the ordered (numbered) and unordered (bulleted) features for CKEditor 5. Additional list properties, such as list marker styles, start index, or reversed list order, are provided by the ListProperties
plugin.
After installing the editor, add the feature to your plugin list and toolbar configuration:
import { ClassicEditor, List } from 'ckeditor5';
ClassicEditor
.create( document.querySelector( '#editor' ), {
licenseKey: '<YOUR_LICENSE_KEY>', // Or 'GPL'.
plugins: [ List, /* ... */ ],
toolbar: [ 'bulletedList', 'numberedList', /* ... */ ]
list: {
// Configuration.
}
} )
.then( /* ... */ )
.catch( /* ... */ );
After installing the editor, add ListProperties
to your plugin list and toolbar configuration:
To enable selected sub-features of the list properties, add their configuration to your editor. Set true
for each feature you want to enable:
import { ClassicEditor, List, ListProperties } from 'ckeditor5';
ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [ List, ListProperties, /* ... */ ],
toolbar: [ 'bulletedList', 'numberedList', /* ... */ ],
list: {
properties: {
styles: true,
startIndex: true,
reversed: true
}
}
} )
.then( /* ... */ )
.catch( /* ... */ );
The ListProperties
feature overrides UI button implementations from the ListUI
.
Starting with version 45.1.1, list items (<li>
elements) in the editor data output contain an additional attribute data-list-item-id
. The attribute is necessary to ensure that the lists feature work correctly with other editor features and mechanisms.
<ul>
<li data-list-item-id="e72808ee4144975064acb5d66e5cfba13">Hello</li>
<li data-list-item-id="e5d719ab356409767e9d4358485476358">There!</li>
</ul>
If data loaded in the editor does not contain the data-list-item-id
attributes on list items, they will be automatically added when data is saved.
If you wish to save the editor contents without this attribute, you can set the skipListItemIds
flag to true
when calling editor.getData()
method. However, please note, that data without IDs should be used only for presentation purposes (such as displaying the document as HTML), and should not be used to initialize the editor.
editor.getData( { skipListItemIds: true } );
Such output will not contain data-list-item-id
attribute:
<ul>
<li>Hello</li>
<li>There!</li>
</ul>
These CKEditor 5 features provide similar functionality:
- To-do lists – Create a list of interactive checkboxes with labels.
- Multi-level lists – Multi-level lists allow the user to set different markers (symbols, text or numbers) to display at each level of the list.
- Block indentation – Set indentation for text blocks such as paragraphs or headings and lists.
- Autoformatting – Format the text on the go with Markdown code.
The List
plugin registers:
- The
'numberedList'
command. - The
'bulletedList'
command. - The
'indentList'
command. - The
'outdentList'
command. - The
'numberedList'
UI button. - The
'bulletedList'
UI button.
The ListProperties
plugin registers:
-
The
listStyle
command. It accepts thetype
of the list style to set. If not set, it uses the default marker (usually decimal).editor.execute( 'listStyle', { type: 'lower-roman' } );
The available types are:
- For bulleted lists:
'disc'
,'circle'
, and'square'
. - For numbered lists:
'decimal'
,'decimal-leading-zero'
,'lower-roman'
,'upper-roman'
,'lower-latin'
, and'upper-latin'
.
- For bulleted lists:
-
The
listStart
command. It is a number and defaults to1
(meaning a list starts with1
). If enabled, it accepts a numerical value for thestart
attribute.editor.execute( 'listStart', { startIndex: 3 } );
-
The
listReversed
command. It is a Boolean and defaults tofalse
(meaning the list order is ascending).editor.execute( 'listReversed', { reversed: true } );
-
The
numberedList
UI split button. It overrides the UI button registered by theList
plugin. -
The
bulletedList
UI split button. It overrides the UI button registered by theList
plugin.
The source code of the feature is available on GitHub at https://github.com/ckeditor/ckeditor5/tree/master/packages/ckeditor5-list.