HTML <body> tag

Definition og brug

<body> Tag definerer dokumentets hoved.

Metadata og dokumentinformation for HTML-dokumentet pakkes ind i head-elementet, mens indholdet pakkes ind i body-elementet.

body-elementet følger altid umiddelbart efter head-elementet og er den anden underelement i html-elementet.

<body> Elementet indeholder alt indhold i HTML-dokumentet, f.eks. titler, afsnit, billeder, hyperlinks, tabeller, lister osv.

Bemærk:Der kan kun være ét element i en HTML-dokument <body> Elementer.

Eksempel

En simpel men komplet HTML-dokument:

<!DOCTYPE html>
<html>
  <head>
    <title>Dokumenttitel</title>
  </head>
  <body>
    <h1>Dette er en titel</h1>
    <p>Dette er en afsnit.</p>
  </body>
</html>

Try it yourself

Tip:Flere eksempler findes på siden i bunden.

Globale egenskaber

<body> Tag støtter også Globale egenskaber i HTML

eventegenskaber

<body> Tag støtter også Eventegenskaber i HTML

Standard CSS-indstillinger

De fleste browsere vil bruge følgende standardværdier til visning <body> Element:

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

Try it yourself

Flere eksempler

Eksempel 1

Tilføj en baggrundsbillede til dokumentet (brug CSS):

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

Try it yourself

Eksempel 2

Sæt dokumentets baggrundsfarve (brug CSS):

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

Try it yourself

Eksempel 3

Sæt dokumentets tekstfarve (brug CSS):

<html>
<head>
<style>
body {
  color: green;
}
</style>
</head>
<body>
<h1>Hello world!</h1>
<p>Dette er en tekst.</p>
<p><a href="">Besøg codew3c.com!</a></p>
</body>
</html>

Try it yourself

Eksempel 4

Set the color of unvisited links in the document (using 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/">HTML tutorial</a></p>
</body>
</html>

Try it yourself

Example 5

Set the color of active links in the document (using 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/">HTML tutorial</a></p>
</body>
</html>

Try it yourself

Example 6

Set the color of visited links in the document (using 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/">HTML tutorial</a></p>
</body>
</html>

Try it yourself

Browser support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support