Saltar al contenido

Etiqueta HTML <header>

La etiqueta &lt;header&gt; define la cabecera de una página o una sección. Por lo general, contiene un logotipo, una barra de búsqueda, enlaces de navegación, etc.

Esta etiqueta no introduce una nueva sección en el esquema. Un elemento &lt;header&gt; comúnmente contiene un encabezado (un &lt;h1&gt;&lt;h6&gt; elemento) para la sección circundante. Sin embargo, esto no es obligatorio.

La etiqueta &lt;header&gt; es uno de los elementos HTML5. En un documento HTML, puedes usar varias etiquetas &lt;header&gt;. Por lo general, se colocan dentro de elementos &lt;body&gt;, &lt;article&gt; o &lt;section&gt;.

peligro

No está permitido colocar la etiqueta &lt;header&gt; dentro de los elementos &lt;footer&gt; y &lt;address&gt;, ni dentro de otra etiqueta &lt;header&gt;.

Sintaxis

La etiqueta &lt;header&gt; se escribe en pares. El contenido se escribe entre las etiquetas de apertura (&lt;header&gt;) y cierre (&lt;&#8203;/header&gt;).

Ejemplo de la etiqueta HTML &lt;header&gt;:

Ejemplo de la etiqueta HTML &lt;header&gt;

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      ul {
        padding: 0;
      }
      ul li {
        display: inline-block;
        margin-right: 10px;
        color: #778899;
      }
    </style>
  </head>
  <body>
    <header>
      <nav>
        <ul>
          <li>Home</li>
          <li>About us</li>
        </ul>
      </nav>
      <h1>Welcome to our page</h1>
      <hr>
    </header>
    <article>
      <header>
        <h2>The section title</h2>
        <p>The text paragraph.</p>
      </header>
    </article>
  </body>
</html>

Resultado

ejemplo de la etiqueta header

Ejemplo de la etiqueta HTML &lt;header&gt; con propiedades CSS:

Ejemplo de la etiqueta HTML &lt;header&gt; con propiedades CSS:

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      body {
        font-family: Arial, sans-serif;
        line-height: 2;
      }
      h2 {
        text-align: center;
      }
      ul {
        padding: 0;
      }
      ul li {
        list-style-type: none;
        display: inline-block;
        margin-right: 10px;
      }
      a {
        display: block;
        color: #778899;
      }
    </style>
  </head>
  <body>
    <header>
      <nav>
        <ul>
          <li>
            <a href="https://www.w3docs.com/learn-html.html">Learn HTML</a>
          </li>
          <li>
            <a href="https://www.w3docs.com/learn-git.html">Learn Git</a>
          </li>
        </ul>
      </nav>
      <h1>Welcome to our page</h1>
      <hr>
    </header>
    <main>
      <h2>Get answers to your coding questions</h2>
      <p>
        Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.
      </p>
      <p>
        Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book. Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.
      </p>
    </main>
  </body>
</html>

Atributos

La etiqueta &lt;header&gt; admite Atributos Globales y Atributos de Eventos.

Cómo dar estilo a una etiqueta HTML &lt;header&gt;

html
<header id="main-header" class="site-header">
  <h1>Page Title</h1>
</header>

Práctica

¿Qué es cierto sobre la etiqueta HTML <header> según el contenido de la URL especificada?

¿Te resulta útil?

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