Add class to <ul> in List block.
Is your feature request related to a problem? Please describe.
The subject of adding classes to default blocks was discussed at #6639, and I know you can filter the List block to add a new class, but the wp-block-list class should be present by default.
Without a specific class, any style applied to the generic <ul> will inadvertently affect elements from third-party plugins or custom HTML added elsewhere, and we can't know beforehand if they will be affected.
One practical example happens when you try, for instance, to style the List block in a theme to add new bullets and you are also using the Elementor plugin.
Without a class, the generic .ul style will affect <li> elements used by Elementor in their control handles – unless you explicitly filter the class or resort to a convoluted solution as ul:not(.elementor-editor-element-settings):not(.wp-block-gallery):not(.wp-block-categories):not(.wp-block-latest-posts)... and so on.
This will surely happen with lots of other plugins that use the <ul> tag for tasks like this.
Image 1: Custom style added to <ul> tag.

Image 2: Custom style affecting a third-party plugin.

Describe the solution you'd like
Just add the wp-block-list class to the <ul> tag by default, in the List block.
Describe alternatives you've considered
- Filter the List block to add a new class
- Add multiple
:not()to the generic.ulstyle to target only the List block.
Tested with 5.0-RC1-43946
Note that using non-specific selectors like ul is a bad idea in general. I'm sure you could use something like .content-area ul in your theme.
@swissspidy That was just an example.
The problem would persist if you utilize .content-area ul – or other more specific selector.
The only way to solve the issue is to add a class to the <ul> tag itself.
I think that the reason for avoiding adding classnames for everything by default is that not every theme would need them by default and so filtering in the cases where it makes sense is the preferred method when possible. Adding the Needs Design Feedback label to get a check on that assumption and to pull in feedback from the core design team.
I'm in favor of unordered lists having a class attached, especially with other blocks like the gallery block using the ul tag.
I am in favor of the ul block have some sort of class. Without it I cannot target those blocks easily. I already made an issue once before and showed how the blocks could use a class or even a wrapper to stop from major issues in themes, especially ones where there is a sidebar or where pre and code are used without a wrapper... :/ sadly it seems classes and div wrappers are not being added to the basic blocks.
sadly it seems classes and div wrappers are not being added to the basic blocks.
Adding div wrappers around every block by default would be quite a backward compatibility break.
Adding div wrappers around every block by default would be quite a backward compatibility break.
How so? Backwards to what? Gutenberg hasn't been officially released yet has it? And I doubt it would break anything except floats, which have their own issues.
I am currently dealing with the issue that p tags made by Gutenberg should have a margin bottom, while in other areas it should not. There is no way to target the Gutenberg ones.
I kept having styles from my unordered lists fall onto the gallery block so I resorted to styling my unordered lists by appending :not([class]) to them. Which feels very hacky.
A user emailed in:
1961093-zen
reporting that the gallery block on their site seems to be inheriting the margins for the theme itself.

That sounds very similar to what you're describing here. Would giving the block its own class allow things like "resetting" ul/li margins?
See also:
https://github.com/Automattic/themes/issues/735 https://github.com/Automattic/themes/issues/447 https://github.com/Automattic/themes/issues/596
Please add a class to the ul and li tags. I need them to style the default gutenberg list style. I can't use the parent class because the custom blocks ul and li will be styled.
I very much agree wp-block-list should be included by default for <ul> and <ol> items. But the good news is for any developer you can at least easily add the class using the code found here.
UPDATE!! The original answer in the link above technically works, but there are issues doing it this way, in particular you can then no longer add new classes later. But below in this issue is very much a good workaround.
Without a specific class, any style applied to the generic
<ul>will inadvertently affect elements from third-party plugins or custom HTML added elsewhere, and we can't know beforehand if they will be affected.[...]
Without a class, the generic
.ulstyle will affect<li>elements used by Elementor in their control handles – unless you explicitly filter the class or resort to a convoluted solution asul:not(.elementor-editor-element-settings):not(.wp-block-gallery):not(.wp-block-categories):not(.wp-block-latest-posts)... and so on.
If I understand correctly: This is not inadvertent, the default list block intentionally absorbs generic ul styling (either explicit or browser-default). A list block should expect to be styled the same as any other standard list on the page, and vice-versa. The block implementation shouldn't be optimized on the assumption of a CSS reset (lists stripped of their default styling), but instead that the onus is on a custom variation of a list to unset its own default styling, or choose a more appropriate HTML tag which does not carry the same styling implications.
But the good news is for any developer you can at least easily add the class using the code found here.
Unfortunately, this is not a solution because it brings a bigger problem. If you add a class to the List block like this on the frontend (via enqueue_block_assets), you will also add many JS files from the editor.

(...) that the onus is on a custom variation of a list to unset its own default styling,
This would only work if we could control the whole codebase, which is obviously not the case.
A custom style created by any theme (or plugin), can't know beforehand if a certain property is applied to the default tag. So the onus can't be on it.
(...) or choose a more appropriate HTML tag which does not carry the same styling implications.
If you have a list of things you should use the semantic tag on it. We should not resort to this kind of change just to avoid problems with styles.
Both <ul> and <ol> are particular cases, because they are commonly used for lots of things besides displaying a simple list of text items, so this block should be treated differently.
@MichaelCampanella: Also, using :not([class]) can cause new issues, as when a typographically used list gets additional classes assigned, e.g. for color or font-size, or a block style class that should just extend a small aspect of it on top of the base styles.
Maybe add typographic class to all blocks that are used in a typographical context, semantically, navigation and normal lists are the same, but not in their purpose.
Seems we should add standard block classes to a few of the elements we have left without.
With every project I seem to add more :not exclusions to my css. Almost all blocks can be targeted directly. We have no options to 'slip in' extra classes on core blocks via PHP and this issue is pending like forever. I do understand the purist approach but with the freedom for users to include blocks in more locations, we do need means to target and style them accordingly. Some priority on this issue would be nice.
I'd like to add my vote to this issue.
Ideally, I'd be able to style 'List' block lists without using either reset styles on all other lists, or :not() selectors for all of the other lists.
I'd like a method to style List blocks that doesn't interfere with all of the other lists on a site. For example, menus, meta lists, footer lists, lists introduced by plugins (e.g. WP Job Manager), etc.
There is an argument above that List blocks should inherit the base ul/ol styles and additional styles should be applied with custom block styles.
I agree that solid default list styles are important, but I don't see how that is mutually exclusive with adding a .wp-block-list class. This would give theme developers more control and allow us to write less CSS.
I agree with @keithdevon. Adding a class to all of the core blocks (where they don't already have them) is a simple addition, and will allow developers to use much less (and much less hierarchically complex and less-specific) CSS.
Let's look into rendering classes but only server side, without serializing them.