You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Paragraph block: becomes invalid when setting text alignment to justified #8450
You can not set the text-align CSS property of a Paragraph block to justify. If you add it manually via Edit as HTML, the block will become invalid. Justified text alignment should be allowed, even if it is not exposed through the UI.
How to reproduce
Insert a Paragraph block.
Click the ellipsis (More Options) and choose Edit as HTML.
Add the following to the <p> tag: style="text-align:justify".
Just throwing this out there: if it's not important enough to surface via the UI, is it something we want to keep? A more richly-featured paragraph block with a justify alignment is possible, but maybe if there's no way to affect a change in the UI we shouldn't allow it in a basic block like this? 🤷♂️
cc'ing @karmatosed@mtias–I'm curious what our rule around allowing options that the UI doesn't expose is? Do we generally say "okay" or do we want to explicitly remove stuff that we don't support in our UI?
The latter is my preference as it's simpler but is obviously a bit needlessly hostile toward legacy/custom/expertly-made content.
Whilst I feel we shouldn't surface things we don't have in UI the issue is we do have the ability to add HTML. As a result I think we have to at least not have this break as it is valid HTML.
Seems we will need a (new) way to set/update block props: by parsing the (user edited) HTML. That seems quite doable for simple blocks and HTML attributes but can quickly get "out of hand" for complex blocks (and introduce edge cases).
On the other hand editing the HTML is probably the most "unfriendly" way of doing this. Wondering what's the right balance here:
Leave all uncommon settings/attributes for plugins (that should be able to add UI/buttons for them).
Add support for setting and editing tags and attributes when editing the HTML (without invalidating the bloc).
Support them with keyboard shortcuts but leave any UI for plugins.
To me personally number three seems the best balance.
Added Justify alignment format on EditorsKit plugin ( https://wordpress.org/plugins/block-options/ ) together with highlighted text color and underline controls. Here's how the "Justify" works:
Hoping this will solve everybody's problem :) Thanks!
I tested this issue with the latest version of Gutenberg, and when I change the text alignment in the block toolbar, the attributes and class names are changed instead of the inline styles.
<!-- wp:paragraph {"align":"justify"} --><pclass="has-text-align-justify">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p><!-- /wp:paragraph -->
And if you change this attribute and class name to "justify" in the code editor, the block will NOT break. I think this problem can be solved by providing a UI for justifying and defining a CSS style called has-text-align-justify. In other words, I think the approach tried in #48146 is still valid.
One concern is that if we add the justify option to the AlignmentControl, it will be exposed to all blocks where that component is used or any custom blocks that use that component. Therefore, I'm concerned that developers will be forced to explicitly override the default alignmentControls prop if they do not wish to expose the justfiy option as before.
I know that "justify" formatting option was removed from WordPress intentionally
In the classic editor (and the Classic block), the justify button is not visible, but the shortcut is available. Does anyone know why the UI is intentionally not visible?
I submitted #59531, which aims to add new "textAlign" block support to also allow for the provision of a "justify" option UI for the Paragraph block in the future.
Activity
tofumatt commentedon Aug 7, 2018
Just throwing this out there: if it's not important enough to surface via the UI, is it something we want to keep? A more richly-featured paragraph block with a justify alignment is possible, but maybe if there's no way to affect a change in the UI we shouldn't allow it in a basic block like this? 🤷♂️
cc'ing @karmatosed @mtias–I'm curious what our rule around allowing options that the UI doesn't expose is? Do we generally say "okay" or do we want to explicitly remove stuff that we don't support in our UI?
The latter is my preference as it's simpler but is obviously a bit needlessly hostile toward legacy/custom/expertly-made content.
karmatosed commentedon Aug 8, 2018
Whilst I feel we shouldn't surface things we don't have in UI the issue is we do have the ability to add HTML. As a result I think we have to at least not have this break as it is valid HTML.
azaozz commentedon Sep 3, 2018
Seems we will need a (new) way to set/update block props: by parsing the (user edited) HTML. That seems quite doable for simple blocks and HTML attributes but can quickly get "out of hand" for complex blocks (and introduce edge cases).
On the other hand editing the HTML is probably the most "unfriendly" way of doing this. Wondering what's the right balance here:
To me personally number three seems the best balance.
danielbachhuber commentedon Oct 31, 2018
Related #6878 (comment) #10204
11 remaining items
BridgwaterNews commentedon Dec 8, 2018
Another solution, is to use the 'Classic Block', which I've tested and shows the full justify button which is added with the free WP Edit plugin.
mikeicode commentedon Dec 9, 2018
You can target a single block with CSS to set the justify, I posted info here: #6833 (comment)
helen-oneill commentedon Mar 12, 2019
I've just looked for this... I can't see it.
phpbits commentedon May 17, 2019
Added Justify alignment format on EditorsKit plugin ( https://wordpress.org/plugins/block-options/ ) together with highlighted text color and underline controls. Here's how the "Justify" works:
Hoping this will solve everybody's problem :) Thanks!
joxerg commentedon Nov 24, 2019
So no intention to have Justify by default? seriously??
strarsis commentedon Feb 21, 2020
My current approach for theme (SASS):
sabernhardt commentedon May 14, 2021
The paragraph block fails validation with possibly any style attribute on the
<p>tag (using WordPress 5.7.2 and Gutenberg 10.6.0).Each of these contained "unexpected or invalid" content:
<p style="text-align:justify;">text</p><p style="text-align:left;">text</p><p style="text-decoration:underline;">text</p><p style="text-decoration:none;">text</p><p style="margin: 0 0 3em;">text</p><p style="color:#900;">text</p>(Adding the color to a span tag within the paragraph does work, though.)
<p><span style="color:#900;">text</span></p>danielbachhuber commentedon Feb 16, 2023
Opened a PR to add a 'Justify' option to alignment controls: #48146
Would love a review from anyone who wants to test it 😊
danielbachhuber commentedon Feb 17, 2023
I lied. 'Justify' is going in Global Styles first #48202
t-hamano commentedon Mar 3, 2024
I tested this issue with the latest version of Gutenberg, and when I change the text alignment in the block toolbar, the attributes and class names are changed instead of the inline styles.
And if you change this attribute and class name to "justify" in the code editor, the block will NOT break. I think this problem can be solved by providing a UI for justifying and defining a CSS style called
has-text-align-justify. In other words, I think the approach tried in #48146 is still valid.One concern is that if we add the justify option to the
AlignmentControl, it will be exposed to all blocks where that component is used or any custom blocks that use that component. Therefore, I'm concerned that developers will be forced to explicitly override the defaultalignmentControlsprop if they do not wish to expose the justfiy option as before.In the classic editor (and the Classic block), the justify button is not visible, but the shortcut is available. Does anyone know why the UI is intentionally not visible?
t-hamano commentedon Mar 3, 2024
I submitted #59531, which aims to add new "textAlign" block support to also allow for the provision of a "justify" option UI for the Paragraph block in the future.
youknowriad commentedon Nov 13, 2025
I think the justify class is now usable and the global styles support is added for justify. We can probably close this issue.
If you add a style manually it's still an invalid block but this is a separate concern that applies to all style changes and will be handled in #7604