Thursday, June 13, 2024

HTML Headers

 

HTML headers, which are elements inside the <head> section of an HTML document, provide meta-information about the HTML document. Here's a brief overview of the commonly used header elements:

  1. Title

    • <title>: Defines the title of the document, which is displayed in the browser's title bar or tab.


      <title>My Web Page</title>
  2. Base

    • <base>: Specifies the base URL for all relative URLs in the document.


      <base href="https://www.example.com/">
  3. Link

    • <link>: Defines the relationship between the current document and an external resource, often used to link stylesheets.


      <link rel="stylesheet" href="styles.css">
  4. Styles

    • <style>: Contains CSS styles for the document.


      <style> body { background-color: lightblue; } </style>
  5. Script

    • <script>: Embeds or references executable code, typically JavaScript.


      <script src="script.js"></script>
  6. Meta

    • <meta>: Provides metadata about the HTML document, such as character set, author, description, and viewport settings.


      <meta charset="UTF-8"> <meta name="description" content="Free Web tutorials"> <meta name="keywords" content="HTML, CSS, JavaScript"> <meta name="author" content="John Doe"> <meta name="viewport" content="width=device-width, initial-scale=1.0">

Here’s an example of how these elements might be used together in a complete HTML document:

<!DOCTYPE html>
<html lang="en"> <head> <meta charset="UTF-8"> <meta name="description" content="An example web page"> <meta name="keywords" content="HTML, CSS, JavaScript"> <meta name="author" content="Jane Doe"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Example Page</title> <base href="https://www.example.com/"> <link rel="stylesheet" href="styles.css"> <style> body { background-color: lightblue; } </style> <script src="script.js"></script> </head> <body> <h1>Welcome to the Example Page</h1> <p>This is an example of an HTML document with various header elements.</p> </body> </html>

This example includes all the header elements listed, providing a comprehensive setup for the metadata and resources needed by the document.


No comments:

Post a Comment