Skip to content

Proposal of removing inline styles #2862

@samikeijonen

Description

@samikeijonen

Some blocks like Paragraph and Button use inline styles. For various reasons we should avoid them and invent better system for styling blocks.

  • Hard to maintain: Let's say we have hundreds buttons with my brand color. But then we re-design colors including button colors. It would be nasty job to change all previous button colors.
  • Future-proof markup: Using !import is not an answer. It's also bad practise for modular, future-proof, and semantic separation of markup and presentation.
  • Performance: Inline styles have small performance issue.
  • Child themes: Child themes should be able to easily use different color combinations that parent theme.
  • SEO: It's not good for SEO (don't ask me details, I don't know them:)
  • In short, using inline styles has been considered as a bad practise for a long time.

Joe Dolson summarize it well:

Inline styles inhibit the ability of users to use their own custom stylesheets and create a barrier to tools that customize the view.

Proposal 1

I don't have a silver bullet but what if we start exploring how we could automate custom classes for blocks, something like bg-color-1, color-1, bg-color-2, color-2.

Example of current markup for paragraph:

<p style="background-color:#eee;font-size:28px;text-align:left" class="has-background has-drop-cap">
This is styled paragraph.
</p>

Example of markup for paragraph when we select first Background Color and Text color from Block settings:

<p class="has-background has-drop-cap bg-color-1 color-1">
This is styled paragraph.
</p>

Theme could map those styles to correct color what's declared in add_theme_support( 'gutenberg' ) and child themes could easily overwrite them.

Proposal 2

If nothing else theme should be able to disable inline styles. It could be done for example using 'inline-styles' => false, argument:

add_theme_support( 'gutenberg', array(
'wide-images' => true,
'inline-styles' => false,
'colors' => array(
	'#0073aa',
	'#229fd8',
	'#eee',
	'#444',
),
) );

Metadata

Metadata

Assignees

No one assigned

    Labels

    CustomizationIssues related to Phase 2: Customization efforts[Type] TaskIssues or PRs that have been broken down into an individual action to take

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions