So far, you’ve learned how to specify the exact position of an element using offset properties. If you’re simply interested in moving an element as far left or as far right as possible in the container, you can use the float property.

The float property is commonly used for wrapping text around an image. Note, however, that moving elements left or right for layout purposes is better suited for tools like CSS grid and flexbox, which you’ll learn about later on.

The float property is often set using one of the values below:

  • left - moves, or floats, elements as far left as possible.
  • right - moves elements as far right as possible.
.green-section { width: 50%; height: 150px; } .orange-section { background-color: orange; width: 50%; float: right; }

In the example above, we float the .orange-section element to the right. This works for static and relative positioned elements. See the result of the code below:

Diagrm of an element floating on the right

Floated elements must have a width specified, as in the example above. Otherwise, the element will assume the full width of its containing element, and changing the float value will not yield any visible results.



Add a declaration to the .answer ruleset that sets the float property to left.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?