Tag HTML <body>

Definizione e uso

<body> Il tag <body> definisce il corpo del documento.

I metadati del documento HTML e le informazioni del documento sono racchiusi nell'elemento head, mentre il contenuto del documento è racchiuso nell'elemento body.

L'elemento body segue sempre l'elemento head, è il secondo figlio dell'elemento html.

<body> L'elemento contiene tutto il contenuto del documento HTML, ad esempio titoli, paragrafi, immagini, link, tabelle, elenchi, ecc.

Attenzione:In un documento HTML ci può essere solo uno <body> Elemento.

Esempio

Un documento HTML semplice ma completo:

<!DOCTYPE html>
<html>
  <head>
    <title>Titolo del documento</title>
  </head>
  <body>
    <h1>Questo è un titolo</h1>
    <p>Questo è un paragrafo.</p>
  </body>
</html>

Prova tu stesso

Suggerimento:Più esempi sono disponibili nella parte inferiore della pagina.

Proprietà globali

<body> I tag supportano anche Proprietà globali in HTML.

Proprietà degli eventi

<body> I tag supportano anche Proprietà degli eventi in HTML.

Impostazioni CSS predefinite

La maggior parte dei browser utilizzerà i seguenti valori predefiniti per la visualizzazione: <body> Elemento:

body {
  display: block;
  margin: 8px;
}
body:focus {
  outline: none;
}

Prova tu stesso

Altri esempi

Esempio 1

Aggiungi un'immagine di sfondo al documento (utilizzando CSS):

<html>
<head>
<style>
body {
  background-image: url(w3s.png);
}
</style>
</head>
<body>
<h1>Hello world!</h1>
<p><a href="">Visita codew3c.com!</a></p>
</body>

Prova tu stesso

Esempio 2

Imposta il colore di sfondo del documento (utilizzando CSS):

<html>
<head>
<style>
body {
  background-color: #E6E6FA;
}
</style>
</head>
<body>
<h1>Hello world!</h1>
<p><a href="https://www.codew3c.com">Visita codew3c.com!</a></p>
</body>

Prova tu stesso

Esempio 3

Imposta il colore del testo del documento (utilizzando CSS):

<html>
<head>
<style>
body {
  color: green;
}
</style>
</head>
<body>
<h1>Hello world!</h1>
<p>Questo è un testo.</p>
<p><a href="">Visita codew3c.com!</a></p>
</body>
</html>

Prova tu stesso

Esempio 4

Impostare il colore dei link non visitati nel documento (utilizzando CSS):

<html>
<head>
<style>
a:link {
  color:#0000FF;
}
</style>
</head>
<body>
<p><a href="https://www.codew3c.com">codew3c.com</a></p>
<p><a href="https://www.codew3c.com/html/">Corso HTML</a></p>
</body>
</html>

Prova tu stesso

Esempio 5

Impostare il colore dei link attivi nel documento (utilizzando CSS):

<html>
<head>
<style>
a:active {
  color:#00FF00;
}
</style>
</head>
<body>
<p><a href="https://www.codew3c.com">codew3c.com</a></p>
<p><a href="https://www.codew3c.com/html/">Corso HTML</a></p>
</body>
</html>

Prova tu stesso

Esempio 6

Impostare il colore dei link visitati nel documento (utilizzando CSS):

<html>
<head>
<style>
a:visited {
  color:#FF0000;
}
</style>
</head>
<body>
<p><a href="https://www.codew3c.com">codew3c.com</a></p>
<p><a href="https://www.codew3c.com/html/">Corso HTML</a></p>
</body>
</html>

Prova tu stesso

Supporto browser

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Supporto Supporto Supporto Supporto Supporto