Saltar al contenido

Propiedad CSS background-repeat

La propiedad background-repeat se utiliza para definir cómo debe repetirse la imagen de fondo. De forma predeterminada, la imagen de fondo se repite tanto horizontal como verticalmente. Si se establece el valor "repeat-x", la imagen se repetirá solo horizontalmente. Si se establece el valor "repeat-y", la imagen se repetirá solo verticalmente. Existen otros dos valores: "space" y "round". "Space" hace que la imagen se repita sin recortes y "round" hace que la imagen se repita sin espacios.

Debemos usar la propiedad background-repeat junto con las propiedades background-image y background-position.

INFO

De forma predeterminada, la imagen se mostrará en la esquina superior izquierda sin la propiedad background-position.

Valor inicialrepeat
Se aplica aTodos los elementos. También se aplica a ::first-letter y ::first-line.
HeredableNo.
AnimableNo.
VersiónCSS1
Sintaxis DOMelement.style.backgroundRepeat = "repeat-x";

Sintaxis

Sintaxis de la propiedad CSS background-repeat

css
background-repeat: repeat | repeat-x | repeat-y | no-repeat | space | round | initial | inherit;

Ejemplo de la propiedad background-repeat:

Ejemplo de la propiedad CSS background-repeat con el valor repeat

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      body {
        background-image: url("https://es.w3docs.com/uploads/media/default/0001/02/668fdd72934232cdeff7a45a89be805113c916b5.jpeg");
        background-repeat: repeat;
      }
    </style>
  </head>
  <body>
    <h2>This is some heading for an example.</h2>
    <p>Some paragraph for an example.</p>
  </body>
</html>

Resultado

Propiedad CSS background-repeat

En el siguiente ejemplo, la imagen de fondo no se repite.

Ejemplo de la propiedad background-repeat con el valor "no-repeat":

Ejemplo de la propiedad CSS background-repeat con el valor no-repeat

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      body {
        background-image: url("https://es.w3docs.com/uploads/media/default/0001/02/668fdd72934232cdeff7a45a89be805113c916b5.jpeg");
        background-repeat: no-repeat;
      }
    </style>
  </head>
  <body>
    <h2>This is some heading for an example.</h2>
    <p>Some paragraph for an example.</p>
  </body>
</html>

En el siguiente ejemplo, la imagen de fondo se repite solo horizontalmente.

Ejemplo de la propiedad background-repeat con el valor "repeat-x":

Ejemplo de la propiedad CSS background-repeat con el valor repeat-x

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      body {
        background-image: url("https://es.w3docs.com/uploads/media/default/0001/02/668fdd72934232cdeff7a45a89be805113c916b5.jpeg");
        background-repeat: repeat-x;
      }
    </style>
  </head>
  <body>
    <h2>This is some heading for an example.</h2>
    <p>Some paragraph for an example.</p>
  </body>
</html>

Aquí, el valor "repeat-y" hace que la imagen se repita solo verticalmente.

Ejemplo de la propiedad background-repeat con el valor "repeat-y":

Ejemplo de la propiedad CSS background-repeat con el valor repeat-y

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      body {
        background-image: url("https://es.w3docs.com/uploads/media/default/0001/02/668fdd72934232cdeff7a45a89be805113c916b5.jpeg");
        background-repeat: repeat-y;
      }
    </style>
  </head>
  <body>
    <h2>This is some heading for an example.</h2>
    <p>Some paragraph for an example.</p>
  </body>
</html>

Probemos un ejemplo donde la imagen de fondo se repita sin recortes.

Ejemplo de la propiedad background-repeat con el valor "space":

Ejemplo de la propiedad CSS background-repeat con el valor space

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      body {
        background-image: url("https://es.w3docs.com/uploads/media/default/0001/02/668fdd72934232cdeff7a45a89be805113c916b5.jpeg");
        background-repeat: space;
      }
    </style>
  </head>
  <body>
    <h2>This is some heading for an example.</h2>
    <p>Some paragraph for an example.</p>
  </body>
</html>

En el siguiente ejemplo, el valor aplicado hace que la imagen de fondo se repita sin espacios.

Ejemplo de la propiedad background-repeat con el valor "round":

Ejemplo de la propiedad CSS background-repeat con el valor round

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      body {
        background-image: url("https://es.w3docs.com/uploads/media/default/0001/02/668fdd72934232cdeff7a45a89be805113c916b5.jpeg");
        background-repeat: round;
      }
    </style>
  </head>
  <body>
    <h2>This is some heading for an example.</h2>
    <p>Some paragraph for an example.</p>
  </body>
</html>

Valores

ValorDescripciónPruébalo
repeatLa imagen de fondo se repite tanto horizontal como verticalmente. Este es el valor predeterminado.Pruébalo »
repeat-xLa imagen de fondo se repite solo horizontalmente.Pruébalo »
repeat-yLa imagen de fondo se repite solo verticalmente.Pruébalo »
no-repeatLa imagen de fondo no se repite.Pruébalo »
spaceLa imagen de fondo se repite tanto como sea posible sin recortes.Pruébalo »
roundLa imagen de fondo se repite sin espacios.Pruébalo »
initialEstablece la propiedad en su valor predeterminado.Pruébalo »
inheritHereda la propiedad de su elemento padre.

Práctica

¿Cuáles son los diferentes valores que se pueden especificar para la propiedad 'background-repeat' en CSS?

¿Te resulta útil?

Vista previa dual-run — compárala con las rutas Symfony en producción.