W3docs

Propiedad float de CSS

The float CSS property defines if a box or an element should float or not. See examples and practice yourself.

La propiedad float define en qué lado del contenedor se deben colocar los elementos, permitiendo así que el texto u otros elementos se envuelvan a su alrededor. La propiedad tiene tres valores: none, left y right.

Esta propiedad está directamente relacionada con la propiedad clear, la cual define si un elemento debe estar junto a los elementos flotantes o debajo de ellos (clear).

info

La propiedad float se ignorará si los elementos están posicionados de forma absoluta (position: absolute).

Valor inicialnone
Se aplica aTodos los elementos.
HeredableNo.
AnimableNo.
VersiónCSS1
Sintaxis DOMobject.style.cssFloat = "right";

Sintaxis

Sintaxis de la propiedad float de CSS

float: none | left | right | initial | inherit;

Ejemplo de la propiedad float:

Ejemplo de la propiedad float de CSS con el valor right

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      img {
        float: right;
        background: #ccc;
      }
    </style>
  </head>
  <body>
    <h2>Float property example</h2>
    <img src="/uploads/media/default/0001/01/003e5c463668d174ab70bea245c192d81901a4a6.png" alt="W3dcos" />
    <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
    </p>
  </body>
</html>

Resultado

Propiedad float de CSS

En el siguiente ejemplo, la imagen flota hacia la izquierda.

Ejemplo de uso de la propiedad float para flotar una imagen:

Ejemplo de la propiedad float de CSS con el valor left

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      img {
        float: left;
        background: #ccc;
      }
    </style>
  </head>
  <body>
    <h2>Float property example</h2>
    <img src="/uploads/media/default/0001/01/003e5c463668d174ab70bea245c192d81901a4a6.png" alt="W3dcos" />
    <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
    </p>
  </body>
</html>

Valores

ValorDescripciónPruébalo
noneIndica que el elemento no flota y se mostrará donde corresponda en el texto. Este es el valor predeterminado de esta propiedad.Pruébalo »
leftIndica que el elemento flota hacia la izquierda.Pruébalo »
rightIndica que el elemento flota hacia la derecha.Pruébalo »
initialHace que la propiedad utilice su valor predeterminado.Pruébalo »
inheritHereda la propiedad de su elemento padre.

Práctica

Práctica

¿Cuál es el propósito de la propiedad 'float' en CSS?