HTML Structure
HTML documents have a specific structure that defines the organization and layout of content. The structure of an HTML document consists of several key elements:
<!DOCTYPE>
declaration: Specifies the version of HTML that the document uses.<html>
element: The root element of the document.<head>
element: Contains meta information about the document, such as the title and character encoding.<body>
element: Contains the visible content of the document.
Here's an example of a basic HTML document structure:
1<!DOCTYPE html>
2<html>
3 <head>
4 <meta charset="UTF-8">
5 <title>My Web Page</title>
6 </head>
7 <body>
8 <h1>Welcome to My Web Page</h1>
9 <p>This is some example content.</p>
10 </body>
11</html>
In this example, we have a simple HTML document that includes a <DOCTYPE>
declaration, the <html>
, <head>
, and <body>
elements. The <head>
element contains meta information like the page title, while the <body>
element contains the visible content of the page.
Understanding the basic structure of an HTML document is important as it provides a solid foundation for building web pages. By organizing content within the appropriate HTML elements, we can create well-structured and semantically meaningful web pages.
Let's take a look at an example code snippet in JavaScript:
1const name = "John Doe";
2console.log(`Hello, ${name}!`);
This code snippet declares a variable name
and assigns it the value "John Doe". Then, it uses template literals to log a greeting that includes the value of the name
variable. When executed, the code will output Hello, John Doe!
in the console.
xxxxxxxxxx
const name = "John Doe";
console.log(`Hello, ${name}!`);