Skip to content

[css-box-4] Padding/Margin horizontal and vertical shorthands #6507

@finnp

Description

@finnp

Motivation

The padding and margin shorthands for combining top/bottom and left/right are quite practical. They transform

padding-top: 10px;
paddding-left: 10px;
padding-top: 5px;
padding-bottom: 5px;

into

padding: 5px 10px;

However they have 2 issues. The more important one is that it's easy to forget which one of these are the top/bottom and which are the left/right values. In graphics width by height is usually given in that order: width, height. So someone might incorrectly assume that left/right comes first.

The other shortcoming is that it requires you to specify both vertical and horizontal padding/margin even if you might only want to specify one.

Suggestion

Introduce a padding-horizontal, padding-vertical, margin-horizontal and margin-vertical shorthand.

This would allow to write something like

margin-left: 10px;
margin-right: 10px;

as

margin-horizontal: 10px;

I would be happy to get feedback on this, it's my first time I'm suggesting something to the CSS working group. ✨

Links

Metadata

Metadata

Assignees

No one assigned

    Labels

    Closed as Question AnsweredUsed when the issue is more of a question than a problem, and it's been answered.css-box-4

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions