left

Term side of the Card.
Topic: Positioning
Unit title: left
Categories: Property
Explanation side of the Card

Explanation: The property that sets the distance between the left edge of an element and the left edge of its containing block. With 'absolute' or 'fixed' `position` it places the element in its nearest positioned ancestor or the viewport, while with 'relative' it shifts it from its normal place.

Browser compatibility:
  • The chrome browser supports this feature starting from version 1.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 1.
  • The safari browser supports this feature starting from version 1.
Availability: 

Example

Wrongcss
.tooltip {
  position: absolute;
  left: 50%;
}
Rightcss
.tooltip {
  position: absolute;
  left: 50%;
  translate: -50% 0;
}

left: 50% moves the left edge to the center; translate shifts it back by half its own width.

Common mistakes

  • left: 50% puts the element's left edge, not its center, in the middle.
  • left is ignored because position is still 'static'.

Key points

  • left: 50% centering also shifts the element back with translate: -50% or transform: translateX(-50%).
  • Layouts that support right-to-left text use inset-inline-start instead of left.
  • Elements using left have a position other than 'static'.

Interview questions

Does left: 50% center an element?

No. It moves the element's left edge to the middle; add a translate of '-50%' to center it.

What happens if I set both left and right?

On absolute elements with 'auto' width, the element stretches between both; with a fixed width in left-to-right text, left wins.

What is the logical version of left?

inset-inline-start, which maps to right in right-to-left text.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy