Skip to content

Paragraph block: becomes invalid when setting text alignment to justified #8450

Closed

Description

@ZebulanStanphill

The issue

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

  1. Insert a Paragraph block.
  2. Click the ellipsis (More Options) and choose Edit as HTML.
  3. Add the following to the <p> tag: style="text-align:justify".
  4. Try unfocusing the block.
  5. Notice that the block becomes invalid.

Related issues and PRs

Activity

  1. added
    [Type] BugAn existing feature does not function as intended
    Needs TestingNeeds further testing to be confirmed.
    [Feature] Rich TextRelated to the Rich Text component that allows developers to render a contenteditable
    and removed on Aug 4, 2018
  2. tofumatt commented on Aug 7, 2018

    @tofumatt
    Member

    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.

  3. karmatosed commented on Aug 8, 2018

    @karmatosed
    Member

    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.

  4. azaozz commented on Sep 3, 2018

    @azaozz
    Contributor

    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:

    1. Leave all uncommon settings/attributes for plugins (that should be able to add UI/buttons for them).
    2. Add support for setting and editing tags and attributes when editing the HTML (without invalidating the bloc).
    3. Support them with keyboard shortcuts but leave any UI for plugins.

    To me personally number three seems the best balance.

  5. added and removed
    [Type] BugAn existing feature does not function as intended
    on Oct 27, 2018
  6. added
    Backwards CompatibilityIssues or PRs that impact backwards compatability
    and removed
    Needs TestingNeeds further testing to be confirmed.
    on Oct 31, 2018
  7. added this to the WordPress 5.0 milestone on Oct 31, 2018
  8. danielbachhuber commented on Oct 31, 2018

    @danielbachhuber
    Member
  9. 11 remaining items

  10. BridgwaterNews commented on Dec 8, 2018

    @BridgwaterNews

    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.

  11. mikeicode commented on Dec 9, 2018

    @mikeicode

    I suppose you could just add that to the advanced section on single posts, but not something I've tested.

    You can target a single block with CSS to set the justify, I posted info here: #6833 (comment)

  12. helen-oneill commented on Mar 12, 2019

    @helen-oneill

    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.

    I've just looked for this... I can't see it.

  13. phpbits commented on May 17, 2019

    @phpbits
    Contributor

    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:

    EditorsKit-Formats

    Hoping this will solve everybody's problem :) Thanks!

  14. joxerg commented on Nov 24, 2019

    @joxerg

    So no intention to have Justify by default? seriously??

  15. strarsis commented on Feb 21, 2020

    @strarsis
    Contributor

    My current approach for theme (SASS):

    body {
      p {
        &:not(.has-text-align-center):not(.has-text-align-right) {
          text-align: justify;
        }
      }
    }
  16. sabernhardt commented on May 14, 2021

    @sabernhardt
    Contributor

    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>

  17. danielbachhuber commented on Feb 16, 2023

    @danielbachhuber
    Member

    Opened a PR to add a 'Justify' option to alignment controls: #48146

    Would love a review from anyone who wants to test it 😊

  18. danielbachhuber commented on Feb 17, 2023

    @danielbachhuber
    Member

    I lied. 'Justify' is going in Global Styles first #48202

  19. t-hamano commented on Mar 3, 2024

    @t-hamano
    Contributor

    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"} -->
    <p class="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?

    tinymce-toolbar

    tinymce-shortcuts

  20. t-hamano commented on Mar 3, 2024

    @t-hamano
    Contributor

    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.

  21. youknowriad commented on Nov 13, 2025

    @youknowriad
    Contributor

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions